182 lines
5.5 KiB
PHP
182 lines
5.5 KiB
PHP
<?php
|
|
/** DomFramework - Tests
|
|
* @package domframework
|
|
* @author Dominique Fournier <dominique@fournier38.fr>
|
|
* @license BSD
|
|
*/
|
|
|
|
namespace Domframework\Tests;
|
|
|
|
use Domframework\Fts;
|
|
|
|
/** Test the FTS */
|
|
class FtsTest extends \PHPUnit_Framework_TestCase
|
|
{
|
|
public function test_tokenizerSearch0 ()
|
|
{
|
|
// Empty
|
|
$fts = new Fts ();
|
|
$fts->search ("");
|
|
$res = $fts->getTokensMin ();
|
|
$this->assertSame ($res, array ("tokens"=>array (),
|
|
"minuses"=>array ()));
|
|
}
|
|
|
|
public function test_tokenizerSearch1 ()
|
|
{
|
|
// Too small
|
|
$fts = new Fts ();
|
|
$fts->search ("X");
|
|
$res = $fts->getTokensMin ();
|
|
$this->assertSame ($res, array ("tokens"=>array (),
|
|
"minuses"=>array ()));
|
|
}
|
|
|
|
public function test_tokenizerSearch2 ()
|
|
{
|
|
// One word
|
|
$fts = new Fts ();
|
|
$fts->search ("XYZ");
|
|
$res = $fts->getTokensMin ();
|
|
$this->assertSame ($res, array ("tokens"=>array ("XYZ"),
|
|
"minuses"=>array ("")));
|
|
}
|
|
|
|
public function test_tokenizerSearch3 ()
|
|
{
|
|
// Two word
|
|
$fts = new Fts ();
|
|
$fts->search ("XYZ 123");
|
|
$res = $fts->getTokensMin ();
|
|
$this->assertSame ($res, array ("tokens"=>array ("XYZ", "123"),
|
|
"minuses"=>array ("", "")));
|
|
}
|
|
|
|
public function test_tokenizerSearch4 ()
|
|
{
|
|
// Three word
|
|
$fts = new Fts ();
|
|
$fts->search ("XYZ 123 ABC");
|
|
$res = $fts->getTokensMin ();
|
|
$this->assertSame ($res, array ("tokens"=>array ("XYZ", "123", "ABC"),
|
|
"minuses"=>array ("", "", "")));
|
|
}
|
|
|
|
public function test_tokenizerSearch5 ()
|
|
{
|
|
// Three word
|
|
$fts = new Fts ();
|
|
$fts->search ("XYZ 123 ABC KLM");
|
|
$res = $fts->getTokensMin ();
|
|
$this->assertSame ($res, array ("tokens"=>array ("XYZ", "123",
|
|
"ABC", "KLM"),
|
|
"minuses"=>array ("", "", "", "")));
|
|
}
|
|
|
|
public function test_tokenizerSearch6 ()
|
|
{
|
|
// Three word
|
|
$fts = new Fts ();
|
|
$fts->search ("Louis-XYZ 123 -AéBCé KLM");
|
|
$res = $fts->getTokensMin ();
|
|
$this->assertSame ($res, array ("tokens"=>array ("Louis-XYZ", "123",
|
|
"AéBCé", "KLM"),
|
|
"minuses"=>array ("", "", "-", "")));
|
|
}
|
|
|
|
|
|
public function test_tokenizerSentence0 ()
|
|
{
|
|
// Empty sentence
|
|
$fts = new Fts ();
|
|
$fts->search ("\"\"");
|
|
$res = $fts->getTokensMin ();
|
|
$this->assertSame ($res, array ("tokens"=>array (),
|
|
"minuses"=>array ()));
|
|
}
|
|
|
|
public function test_tokenizerSentence1 ()
|
|
{
|
|
// One sentence only
|
|
$fts = new Fts ();
|
|
$fts->search ("\"XYZ 123\"");
|
|
$res = $fts->getTokensMin ();
|
|
$this->assertSame ($res, array ("tokens"=>array ("XYZ 123"),
|
|
"minuses"=>array ("")));
|
|
}
|
|
|
|
public function test_tokenizerSentence2 ()
|
|
{
|
|
// Two sentence
|
|
$fts = new Fts ();
|
|
$fts->search ("\"XYZ 123\" \"ABC KLM\"");
|
|
$res = $fts->getTokensMin ();
|
|
$this->assertSame ($res, array ("tokens"=>array ("XYZ 123", "ABC KLM"),
|
|
"minuses"=>array ("", "")));
|
|
}
|
|
|
|
public function test_tokenizerSentence3 ()
|
|
{
|
|
// Three sentence
|
|
$fts = new Fts ();
|
|
$fts->search ("\"XYZ 123\" -\"ABC KLM\" \"RPO YUI\"");
|
|
$res = $fts->getTokensMin ();
|
|
$this->assertSame ($res, array ("tokens"=>array ("XYZ 123", "ABC KLM",
|
|
"RPO YUI"),
|
|
"minuses"=>array ("", "-", "")));
|
|
}
|
|
|
|
public function test_tokenizerMixed1 ()
|
|
{
|
|
// One word and one sentence, starting by word
|
|
$fts = new Fts ();
|
|
$fts->search ("XYZ \"ABC KLM\"");
|
|
$res = $fts->getTokensMin ();
|
|
$this->assertSame ($res, array ("tokens"=>array ("XYZ", "ABC KLM"),
|
|
"minuses"=>array ("", "")));
|
|
}
|
|
|
|
public function test_tokenizerMixed2 ()
|
|
{
|
|
// One word and one sentence, starting by sentence
|
|
$fts = new Fts ();
|
|
$fts->search ("\"ABC KLM\" XYZ");
|
|
$res = $fts->getTokensMin ();
|
|
$this->assertSame ($res, array ("tokens"=>array ("ABC KLM", "XYZ"),
|
|
"minuses"=>array ("", "")));
|
|
}
|
|
|
|
public function test_tokenizerMixed3 ()
|
|
{
|
|
// One word and two sentences, starting by sentence
|
|
$fts = new Fts ();
|
|
$fts->search ("\"ABC KLM\" XYZ \"RPO YUI\"");
|
|
$res = $fts->getTokensMin ();
|
|
$this->assertSame ($res, array ("tokens"=>array ("ABC KLM", "XYZ",
|
|
"RPO YUI"),
|
|
"minuses"=>array ("", "", "")));
|
|
}
|
|
|
|
public function test_tokenizerMixed4 ()
|
|
{
|
|
// Two words and two sentences, starting by sentence
|
|
$fts = new Fts ();
|
|
$fts->search ("\"ABC KLM\" XYZ \"RPO YUI\" 123");
|
|
$res = $fts->getTokensMin ();
|
|
$this->assertSame ($res, array ("tokens"=>array ("ABC KLM", "XYZ",
|
|
"RPO YUI", "123"),
|
|
"minuses"=>array ("", "", "", "")));
|
|
}
|
|
|
|
public function test_tokenizerMixed5 ()
|
|
{
|
|
// Two words and two sentences, starting by a word
|
|
$fts = new Fts ();
|
|
$fts->search ("123 \"ABC KLM\" XYZ \"RPO YUI\"");
|
|
$res = $fts->getTokensMin ();
|
|
$this->assertSame ($res, array ("tokens"=>array ("123", "ABC KLM",
|
|
"XYZ", "RPO YUI"),
|
|
"minuses"=>array ("", "", "", "")));
|
|
}
|
|
}
|