3 require_once 'lib/TextSearchQuery.php';
4 require_once 'PHPUnit.php';
6 class TextSearchTest extends phpwiki_TestCase {
8 function testTitleSearch() {
11 $pagename = "PgsrcTranslation";
12 $query = new TextSearchQuery($pagename . SUBPAGE_SEPARATOR . '*', true, 'glob');
13 $sortby = false; $limit = 20; $exclude = "";
14 $dbi = $request->getDbh();
15 $subpages = $dbi->titleSearch($query, $sortby, $limit, $exclude);
18 while ($page = $subpages->next())
19 $result[] = $page->getName();
20 $this->assertTrue(count($result) > 0, "glob count > 0");
23 $sortby = false; $limit = 5; $exclude = "";
24 $subpages = $dbi->titleSearch($query, $sortby, $limit, $exclude);
26 // don't trust count() with limit
27 $this->assertTrue($subpages->count() > 0 and $subpages->count() <= 7,
30 // but the iterator should limit
31 while ($page = $subpages->next())
32 $result[] = $page->getName();
33 $this->assertEquals(5, count($result), "limit 5");
37 function testFulltextSearch() {
39 $dbi = $request->getDbh();
41 $query = new TextSearchQuery('Indent the paragraph*', true); // auto
42 $pages = $dbi->fullSearch($query);
44 while ($page = $pages->next())
45 $result[] = $page->getName();
47 $this->assertTrue(in_array("TextFormattingRules", $result), "found all");
49 $query = new TextSearchQuery('"Indent the paragraph"', false); // case-insensitive, auto
50 $pages = $dbi->fullSearch($query);
52 while ($page = $pages->next())
53 $result[] = $page->getName();
54 $this->assertTrue(in_array("TextFormattingRules", $result), "found phrase");