Index: trunk/phase3/maintenance/tests/SearchMySQLTest.php |
— | — | @@ -1,29 +0,0 @@ |
2 | | -<?php |
3 | | -require_once( 'SearchEngineTest.php' ); |
4 | | - |
5 | | -class SearchMySQLTest extends SearchEngineTest { |
6 | | - var $db; |
7 | | - |
8 | | - function setUp() { |
9 | | - global $wgDBprefix; |
10 | | - if($wgDBprefix === "parsertest_" || ($wgDBtype == 'oracle' && $wgDBprefix === 'pt_')) $this->markTestSkipped("This test can't (yet?) be run with the parser tests"); |
11 | | - |
12 | | - $GLOBALS['wgContLang'] = new Language; |
13 | | - $this->db = $this->buildTestDatabase( |
14 | | - array( 'page', 'revision', 'text', 'searchindex', 'user' ) ); |
15 | | - if( $this->db ) { |
16 | | - $this->insertSearchData(); |
17 | | - } |
18 | | - $this->search = new SearchMySQL( $this->db ); |
19 | | - } |
20 | | - |
21 | | - function tearDown() { |
22 | | - if( !is_null( $this->db ) ) { |
23 | | - wfGetLB()->closeConnecton( $this->db ); |
24 | | - } |
25 | | - unset( $this->db ); |
26 | | - unset( $this->search ); |
27 | | - } |
28 | | -} |
29 | | - |
30 | | - |
Index: trunk/phase3/maintenance/tests/SearchEngineTest.php |
— | — | @@ -7,66 +7,41 @@ |
8 | 8 | */ |
9 | 9 | class SearchEngineTest extends MediaWiki_Setup { |
10 | 10 | var $db, $search; |
| 11 | + private $count = 0; |
11 | 12 | |
12 | | - function insertSearchData() { |
13 | | - $this->db->safeQuery( <<<SQL |
14 | | - INSERT INTO ! (page_id,page_namespace,page_title,page_latest) |
15 | | - VALUES (1, 0, 'Main_Page', 1), |
16 | | - (2, 1, 'Main_Page', 2), |
17 | | - (3, 0, 'Smithee', 3), |
18 | | - (4, 1, 'Smithee', 4), |
19 | | - (5, 0, 'Unrelated_page', 5), |
20 | | - (6, 0, 'Another_page', 6), |
21 | | - (7, 4, 'Help', 7), |
22 | | - (8, 0, 'Thppt', 8), |
23 | | - (9, 0, 'Alan_Smithee', 9), |
24 | | - (10, 0, 'Pages', 10) |
25 | | -SQL |
26 | | - , $this->db->tableName( 'page' ) ); |
27 | | - $this->db->safeQuery( <<<SQL |
28 | | - INSERT INTO ! (rev_id,rev_page) |
29 | | - VALUES (1, 1), |
30 | | - (2, 2), |
31 | | - (3, 3), |
32 | | - (4, 4), |
33 | | - (5, 5), |
34 | | - (6, 6), |
35 | | - (7, 7), |
36 | | - (8, 8), |
37 | | - (9, 9), |
38 | | - (10, 10) |
39 | | -SQL |
40 | | - , $this->db->tableName( 'revision' ) ); |
41 | | - $this->db->safeQuery( <<<SQL |
42 | | - INSERT INTO ! (old_id,old_text) |
43 | | - VALUES (1, 'This is a main page'), |
44 | | - (2, 'This is a talk page to the main page, see [[smithee]]'), |
45 | | - (3, 'A smithee is one who smiths. See also [[Alan Smithee]]'), |
46 | | - (4, 'This article sucks.'), |
47 | | - (5, 'Nothing in this page is about the S word.'), |
48 | | - (6, 'This page also is unrelated.'), |
49 | | - (7, 'Help me!'), |
50 | | - (8, 'Blah blah'), |
51 | | - (9, 'yum'), |
52 | | - (10,'are food') |
53 | | -SQL |
54 | | - , $this->db->tableName( 'text' ) ); |
55 | | - $this->db->safeQuery( <<<SQL |
56 | | - INSERT INTO ! (si_page,si_title,si_text) |
57 | | - VALUES (1, 'main page', 'this is a main page'), |
58 | | - (2, 'main page', 'this is a talk page to the main page, see smithee'), |
59 | | - (3, 'smithee', 'a smithee is one who smiths see also alan smithee'), |
60 | | - (4, 'smithee', 'this article sucks'), |
61 | | - (5, 'unrelated page', 'nothing in this page is about the s word'), |
62 | | - (6, 'another page', 'this page also is unrelated'), |
63 | | - (7, 'help', 'help me'), |
64 | | - (8, 'thppt', 'blah blah'), |
65 | | - (9, 'alan smithee', 'yum'), |
66 | | - (10, 'pages', 'are food') |
67 | | -SQL |
68 | | - , $this->db->tableName( 'searchindex' ) ); |
| 13 | + function insertSearchData() { |
| 14 | + $this->insertPage("Main_Page", "This is a main page", 0); |
| 15 | + $this->insertPage('Main_Page', 'This is a talk page to the main page, see [[smithee]]', 1); |
| 16 | + $this->insertPage('Smithee', 'A smithee is one who smiths. See also [[Alan Smithee]]', 0); |
| 17 | + $this->insertPage('Smithee', 'This article sucks.', 1); |
| 18 | + $this->insertPage('Unrelated_page', 'Nothing in this page is about the S word.', 0); |
| 19 | + $this->insertPage('Another_page', 'This page also is unrelated.', 0); |
| 20 | + $this->insertPage('Help', 'Help me!', 4); |
| 21 | + $this->insertPage('Thppt', 'Blah blah', 0); |
| 22 | + $this->insertPage('Alan_Smithee', 'yum', 0); |
| 23 | + $this->insertPage('Pages', 'are food', 0); |
| 24 | + $this->insertPage('DblPageOne', 'ABCDEF', 0); |
| 25 | + $this->insertPage('DblPageTwo', 'ABCDE', 0); |
| 26 | + $this->insertPage('DblPageTwoLow', 'abcde', 0); |
69 | 27 | } |
70 | 28 | |
| 29 | + function normalize( $text ) { |
| 30 | + return strtolower(preg_replace("/[^[:alnum:] ]/", " ", $text)); |
| 31 | + } |
| 32 | + |
| 33 | + function insertPage( $pageName, $text, $ns ) { |
| 34 | + $this->count++; |
| 35 | + $this->db->safeQuery( 'INSERT INTO ! (page_id,page_namespace,page_title,page_latest) VALUES (?,?,?,?)', |
| 36 | + $this->db->tableName( 'page' ), $this->count, $ns, $pageName, $this->count ); |
| 37 | + $this->db->safeQuery( 'INSERT INTO ! (rev_id,rev_page) VALUES (?, ?)', |
| 38 | + $this->db->tableName( 'revision' ), $this->count, $this->count ); |
| 39 | + $this->db->safeQuery( 'INSERT INTO ! (old_id,old_text) VALUES (?, ?)', |
| 40 | + $this->db->tableName( 'text' ), $this->count, $text ); |
| 41 | + $this->db->safeQuery( 'INSERT INTO ! (si_page,si_title,si_text) VALUES (?, ?, ?)', |
| 42 | + $this->db->tableName( 'searchindex' ), $this->count, |
| 43 | + $this->normalize( $pageName ), $this->normalize( $text ) ); |
| 44 | + } |
| 45 | + |
71 | 46 | function fetchIds( $results ) { |
72 | 47 | $matches = array(); |
73 | 48 | while( $row = $results->next() ) { |
Index: trunk/phase3/maintenance/tests/SearchDbTest.php |
— | — | @@ -0,0 +1,34 @@ |
| 2 | +<?php |
| 3 | +require_once( 'SearchEngineTest.php' ); |
| 4 | + |
| 5 | +class SearchDbTest extends SearchEngineTest { |
| 6 | + var $db; |
| 7 | + |
| 8 | + function setUp() { |
| 9 | + global $wgDBprefix, $wgDBtype; |
| 10 | + |
| 11 | + if($wgDBprefix === "parsertest_" || |
| 12 | + ($wgDBtype === 'oracle' && $wgDBprefix === 'pt_')) { |
| 13 | + $this->markTestSkipped("This test can't (yet?) be run with the parser tests"); |
| 14 | + } |
| 15 | + |
| 16 | + $GLOBALS['wgContLang'] = new Language; |
| 17 | + $this->db = $this->buildTestDatabase( |
| 18 | + array( 'page', 'revision', 'text', 'searchindex', 'user' ) ); |
| 19 | + if( $this->db ) { |
| 20 | + $this->insertSearchData(); |
| 21 | + } |
| 22 | + $searchType = preg_replace("/Database/", "Search", get_class($this->db)); |
| 23 | + $this->search = new $searchType( $this->db ); |
| 24 | + } |
| 25 | + |
| 26 | + function tearDown() { |
| 27 | + if( !is_null( $this->db ) ) { |
| 28 | + wfGetLB()->closeConnecton( $this->db ); |
| 29 | + } |
| 30 | + unset( $this->db ); |
| 31 | + unset( $this->search ); |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | + |
Property changes on: trunk/phase3/maintenance/tests/SearchDbTest.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 36 | + native |
Name: svn:keywords |
2 | 37 | + Author Date Id Revision |
Index: trunk/phase3/maintenance/tests/MediaWiki_Setup.php |
— | — | @@ -10,9 +10,9 @@ |
11 | 11 | foreach( $tables as $table ) |
12 | 12 | $oldTableNames[$table] = $db->tableName( $table ); |
13 | 13 | if($db->getType() == 'oracle') { |
14 | | - $wgDBprefix === 'pt_'; |
| 14 | + $wgDBprefix = 'pt_'; |
15 | 15 | } else { |
16 | | - $wgDBprefix === 'parsertest_'; |
| 16 | + $wgDBprefix = 'parsertest_'; |
17 | 17 | } |
18 | 18 | |
19 | 19 | $db->tablePrefix( $wgDBprefix ); |