]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - tests/unit/lib/TextSearchTest.php
extra_empty_lines
[SourceForge/phpwiki.git] / tests / unit / lib / TextSearchTest.php
1 <?php // $Id$
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     $sortby = false; $limit = 2; $exclude = "";
41
42         $query = new TextSearchQuery('WikiPlugin to let users attach comments', true); // auto
43         $pages = $dbi->fullSearch($query, $sortby, $limit, $exclude);
44         $result = array();
45     while ($page = $pages->next())
46         $result[] = $page->getName();
47         $this->assertTrue(in_array("AddCommentPlugin", $result), "found all, no regex");
48
49         $query = new TextSearchQuery('WikiPlugin* to let users attach comments*', false); // auto
50     /* => (LOWER(pagename) LIKE 'wikiplugin%' OR content LIKE 'wikiplugin%') AND (LOWER(pagename) LIKE '%to%') AND (LOWER(pagename) LIKE '%let%' OR content LIKE '%let%') AND (LOWER(pagename) LIKE '%users%' OR content LIKE '%users%') AND (LOWER(pagename) LIKE '%attach%' OR content LIKE '%attach%') AND (LOWER(pagename) LIKE 'comments%' OR content LIKE 'comments%')
51      SELECT page.id AS id, page.pagename AS pagename, page.hits AS hits,page.pagedata as pagedata,version.version AS version, version.mtime AS mtime, version.minor_edit AS minor_edit, version.content AS content, version.versiondata AS versiondata FROM nonempty, page, recent, version WHERE nonempty.id=page.id AND page.id=recent.id AND page.id=version.id AND latestversion=version AND ((LOWER(pagename) LIKE 'wikiplugin%' OR content LIKE 'wikiplugin%') AND (LOWER(pagename) LIKE '%to%') AND (LOWER(pagename) LIKE '%let%' OR content LIKE '%let%') AND (LOWER(pagename) LIKE '%users%' OR content LIKE '%users%') AND (LOWER(pagename) LIKE '%attach%' OR content LIKE '%attach%') AND (LOWER(pagename) LIKE 'comments%' OR content LIKE 'comments%'))
52      SELECT page.id AS id, page.pagename AS pagename, page.hits AS hits,page.pagedata as pagedata,version.version AS version, version.mtime AS mtime, version.minor_edit AS minor_edit, version.content AS content, version.versiondata AS versiondata FROM nonempty, page, recent, version WHERE nonempty.id=page.id AND page.id=recent.id AND page.id=version.id AND latestversion=version AND ((LOWER(pagename) LIKE 'wikiplugin%' OR content LIKE 'wikiplugin%') AND (1=1) AND (LOWER(pagename) LIKE '%let%' OR content LIKE '%let%') AND (LOWER(pagename) LIKE '%users%' OR content LIKE '%users%') AND (LOWER(pagename) LIKE '%attach%' OR content LIKE '%attach%') AND (LOWER(pagename) LIKE 'comments%' OR content LIKE 'comments%'))
53      */
54         $pages = $dbi->fullSearch($query, $sortby, $limit, $exclude);
55         $result = array();
56     while ($page = $pages->next())
57         $result[] = $page->getName();
58         $this->assertTrue(in_array("AddCommentPlugin", $result), "found regex all");
59
60     $sortby = false; $limit = 2; $exclude = "";
61         $query = new TextSearchQuery('"Indent the paragraph"', false); // case-insensitive, auto
62         $pages = $dbi->fullSearch($query, $sortby, $limit, $exclude);
63         $result = array();
64     while ($page = $pages->next())
65         $result[] = $page->getName();
66         $this->assertTrue(in_array("TextFormattingRules", $result), "found phrase");
67
68         $query = new TextSearchQuery('"Indent the paragraph"', false); // case-insensitive, auto
69         $pages = $dbi->fullSearch($query, $sortby, $limit, $exclude);
70         $result = array();
71     while ($page = $pages->next())
72         $result[] = $page->getName();
73         $this->assertTrue(in_array("TextFormattingRules", $result), "found case phrase");
74
75     }
76 }
77
78 ?>