]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - tests/unit/lib/TextSearchTest.php
fulltext enhancements
[SourceForge/phpwiki.git] / tests / unit / lib / TextSearchTest.php
1 <?php
2
3 require_once 'lib/TextSearchQuery.php';
4 require_once 'PHPUnit.php';
5
6 class TextSearchTest extends phpwiki_TestCase {
7
8     function testTitleSearch() {
9         global $request;
10         // find subpages
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);
16
17         $result = array();
18         while ($page = $subpages->next())
19             $result[] = $page->getName();
20         $this->assertTrue(count($result) > 0, "glob count > 0");
21
22         // apply limit
23         $sortby = false; $limit = 5; $exclude = "";
24         $subpages = $dbi->titleSearch($query, $sortby, $limit, $exclude);
25
26         // don't trust count() with limit
27         $this->assertTrue($subpages->count() > 0 and $subpages->count() <= 7, 
28                           "0 < count() <= 7");
29         $result = array();
30         // but the iterator should limit
31         while ($page = $subpages->next())
32             $result[] = $page->getName();
33         $this->assertEquals(5, count($result), "limit 5");
34         
35     }
36
37     function testFulltextSearch() {
38         global $request;
39         $dbi = $request->getDbh();
40
41         $query = new TextSearchQuery('Indent the paragraph*', true); // auto
42         $pages = $dbi->fullSearch($query);
43         $result = array();
44         while ($page = $pages->next())
45             $result[] = $page->getName();
46
47         $this->assertTrue(in_array("TextFormattingRules", $result), "found all");
48
49         $query = new TextSearchQuery('"Indent the paragraph"', false); // case-insensitive, auto
50         $pages = $dbi->fullSearch($query);
51         $result = array();
52         while ($page = $pages->next())
53             $result[] = $page->getName();
54         $this->assertTrue(in_array("TextFormattingRules", $result), "found phrase");
55
56     }
57 }
58
59
60 ?>