* @license BSD */ namespace Domframework\Tests; use Domframework\Fts; /** Test the FTS */ class FtsTest extends \PHPUnit_Framework_TestCase { public function testTokenizerSearch0() { // Empty $fts = new Fts(); $fts->search(""); $res = $fts->getTokensMin(); $this->assertSame($res, array ("tokens" => array (), "minuses" => array ())); } public function testTokenizerSearch1() { // Too small $fts = new Fts(); $fts->search("X"); $res = $fts->getTokensMin(); $this->assertSame($res, array ("tokens" => array (), "minuses" => array ())); } public function testTokenizerSearch2() { // One word $fts = new Fts(); $fts->search("XYZ"); $res = $fts->getTokensMin(); $this->assertSame($res, array ("tokens" => array ("XYZ"), "minuses" => array (""))); } public function testTokenizerSearch3() { // Two word $fts = new Fts(); $fts->search("XYZ 123"); $res = $fts->getTokensMin(); $this->assertSame($res, array ("tokens" => array ("XYZ", "123"), "minuses" => array ("", ""))); } public function testTokenizerSearch4() { // 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 testTokenizerSearch5() { // 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 testTokenizerSearch6() { // 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 testTokenizerSentence0() { // Empty sentence $fts = new Fts(); $fts->search("\"\""); $res = $fts->getTokensMin(); $this->assertSame($res, array ("tokens" => array (), "minuses" => array ())); } public function testTokenizerSentence1() { // 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 testTokenizerSentence2() { // 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 testTokenizerSentence3() { // 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 testTokenizerMixed1() { // 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 testTokenizerMixed2() { // 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 testTokenizerMixed3() { // 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 testTokenizerMixed4() { // 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 testTokenizerMixed5() { // 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 ("", "", "", ""))); } }