* Fix search-replace problems in MediaWiki_Setup.php
authorMark A. Hershberger <mah@users.mediawiki.org>
Sun, 7 Mar 2010 00:30:02 +0000 (00:30 +0000)
committerMark A. Hershberger <mah@users.mediawiki.org>
Sun, 7 Mar 2010 00:30:02 +0000 (00:30 +0000)
* Use the proper Search* class depending on database setup.
* Rename SearchMySQLTest to SearchDbTest since it isn't
  mysql-specific.
* Clean up code in SearchEngineTest.php to make it easier to add
  searchable pages.

maintenance/tests/MediaWiki_Setup.php
maintenance/tests/SearchDbTest.php [new file with mode: 0644]
maintenance/tests/SearchEngineTest.php
maintenance/tests/SearchMySQLTest.php [deleted file]

index 5483907..3957d38 100644 (file)
@@ -10,9 +10,9 @@ abstract class MediaWiki_Setup extends PHPUnit_Framework_TestCase {
                foreach( $tables as $table )
                        $oldTableNames[$table] = $db->tableName( $table );
                if($db->getType() == 'oracle') {
-                       $wgDBprefix === 'pt_';
+                       $wgDBprefix = 'pt_';
                } else {
-                       $wgDBprefix === 'parsertest_';
+                       $wgDBprefix = 'parsertest_';
                }
 
                $db->tablePrefix( $wgDBprefix );
diff --git a/maintenance/tests/SearchDbTest.php b/maintenance/tests/SearchDbTest.php
new file mode 100644 (file)
index 0000000..1f22340
--- /dev/null
@@ -0,0 +1,34 @@
+<?php
+require_once( 'SearchEngineTest.php' );
+
+class SearchDbTest extends SearchEngineTest {
+       var $db;
+
+       function setUp() {
+               global $wgDBprefix, $wgDBtype;
+
+               if($wgDBprefix === "parsertest_" ||
+                  ($wgDBtype === 'oracle' && $wgDBprefix === 'pt_')) {
+                       $this->markTestSkipped("This test can't (yet?) be run with the parser tests");
+               }
+
+               $GLOBALS['wgContLang'] = new Language;
+               $this->db = $this->buildTestDatabase(
+                       array( 'page', 'revision', 'text', 'searchindex', 'user' ) );
+               if( $this->db ) {
+                       $this->insertSearchData();
+               }
+               $searchType = preg_replace("/Database/", "Search", get_class($this->db));
+               $this->search = new $searchType( $this->db );
+       }
+
+       function tearDown() {
+               if( !is_null( $this->db ) ) {
+                       wfGetLB()->closeConnecton( $this->db );
+               }
+               unset( $this->db );
+               unset( $this->search );
+       }
+}
+
+
index 0cae2d4..8f6b86b 100644 (file)
@@ -7,64 +7,39 @@ require_once( 'MediaWiki_Setup.php' );
  */
 class SearchEngineTest extends MediaWiki_Setup {
        var $db, $search;
+       private $count = 0;
 
-       function insertSearchData() {
-               $this->db->safeQuery( <<<SQL
-               INSERT INTO ! (page_id,page_namespace,page_title,page_latest)
-               VALUES (1, 0, 'Main_Page', 1),
-                          (2, 1, 'Main_Page', 2),
-                          (3, 0, 'Smithee', 3),
-                          (4, 1, 'Smithee', 4),
-                          (5, 0, 'Unrelated_page', 5),
-                          (6, 0, 'Another_page', 6),
-                          (7, 4, 'Help', 7),
-                          (8, 0, 'Thppt', 8),
-                          (9, 0, 'Alan_Smithee', 9),
-                          (10, 0, 'Pages', 10)
-SQL
-                       , $this->db->tableName( 'page' ) );
-               $this->db->safeQuery( <<<SQL
-               INSERT INTO ! (rev_id,rev_page)
-               VALUES (1, 1),
-                      (2, 2),
-                      (3, 3),
-                      (4, 4),
-                      (5, 5),
-                      (6, 6),
-                      (7, 7),
-                      (8, 8),
-                      (9, 9),
-                      (10, 10)
-SQL
-                       , $this->db->tableName( 'revision' ) );
-               $this->db->safeQuery( <<<SQL
-               INSERT INTO ! (old_id,old_text)
-               VALUES (1, 'This is a main page'),
-                          (2, 'This is a talk page to the main page, see [[smithee]]'),
-                          (3, 'A smithee is one who smiths. See also [[Alan Smithee]]'),
-                          (4, 'This article sucks.'),
-                          (5, 'Nothing in this page is about the S word.'),
-                          (6, 'This page also is unrelated.'),
-                          (7, 'Help me!'),
-                          (8, 'Blah blah'),
-                          (9, 'yum'),
-                          (10,'are food')
-SQL
-                       , $this->db->tableName( 'text' ) );
-               $this->db->safeQuery( <<<SQL
-               INSERT INTO ! (si_page,si_title,si_text)
-               VALUES (1, 'main page', 'this is a main page'),
-                          (2, 'main page', 'this is a talk page to the main page, see smithee'),
-                          (3, 'smithee', 'a smithee is one who smiths see also alan smithee'),
-                          (4, 'smithee', 'this article sucks'),
-                          (5, 'unrelated page', 'nothing in this page is about the s word'),
-                          (6, 'another page', 'this page also is unrelated'),
-                          (7, 'help', 'help me'),
-                          (8, 'thppt', 'blah blah'),
-                          (9, 'alan smithee', 'yum'),
-                          (10, 'pages', 'are food')
-SQL
-                       , $this->db->tableName( 'searchindex' ) );
+       function insertSearchData() {
+               $this->insertPage("Main_Page",      "This is a main page", 0);
+               $this->insertPage('Main_Page',      'This is a talk page to the main page, see [[smithee]]', 1);
+               $this->insertPage('Smithee',            'A smithee is one who smiths. See also [[Alan Smithee]]', 0);
+               $this->insertPage('Smithee',            'This article sucks.', 1);
+               $this->insertPage('Unrelated_page',     'Nothing in this page is about the S word.', 0);
+               $this->insertPage('Another_page',       'This page also is unrelated.', 0);
+               $this->insertPage('Help',                       'Help me!', 4);
+               $this->insertPage('Thppt',                      'Blah blah', 0);
+               $this->insertPage('Alan_Smithee',       'yum', 0);
+               $this->insertPage('Pages',                      'are food', 0);
+               $this->insertPage('DblPageOne',         'ABCDEF', 0);
+               $this->insertPage('DblPageTwo',         'ABCDE', 0);
+               $this->insertPage('DblPageTwoLow',  'abcde', 0);
+       }
+
+       function normalize( $text ) {
+               return strtolower(preg_replace("/[^[:alnum:] ]/", " ", $text));
+       }
+
+       function insertPage( $pageName, $text, $ns ) {
+               $this->count++;
+               $this->db->safeQuery( 'INSERT INTO ! (page_id,page_namespace,page_title,page_latest) VALUES (?,?,?,?)',
+                       $this->db->tableName( 'page' ), $this->count, $ns, $pageName, $this->count );
+               $this->db->safeQuery( 'INSERT INTO ! (rev_id,rev_page) VALUES (?, ?)',
+                       $this->db->tableName( 'revision' ), $this->count, $this->count );
+               $this->db->safeQuery( 'INSERT INTO ! (old_id,old_text) VALUES (?, ?)',
+                       $this->db->tableName( 'text' ), $this->count, $text );
+               $this->db->safeQuery( 'INSERT INTO ! (si_page,si_title,si_text) VALUES (?, ?, ?)',
+                       $this->db->tableName( 'searchindex' ), $this->count,
+                       $this->normalize( $pageName ), $this->normalize( $text ) );
        }
 
        function fetchIds( $results ) {
diff --git a/maintenance/tests/SearchMySQLTest.php b/maintenance/tests/SearchMySQLTest.php
deleted file mode 100644 (file)
index 0c2ad22..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-<?php
-require_once( 'SearchEngineTest.php' );
-
-class SearchMySQLTest extends SearchEngineTest {
-       var $db;
-
-       function setUp() {
-               global $wgDBprefix;
-               if($wgDBprefix === "parsertest_" || ($wgDBtype == 'oracle' && $wgDBprefix === 'pt_')) $this->markTestSkipped("This test can't (yet?) be run with the parser tests");
-
-               $GLOBALS['wgContLang'] = new Language;
-               $this->db = $this->buildTestDatabase(
-                       array( 'page', 'revision', 'text', 'searchindex', 'user' ) );
-               if( $this->db ) {
-                       $this->insertSearchData();
-               }
-               $this->search = new SearchMySQL( $this->db );
-       }
-
-       function tearDown() {
-               if( !is_null( $this->db ) ) {
-                       wfGetLB()->closeConnecton( $this->db );
-               }
-               unset( $this->db );
-               unset( $this->search );
-       }
-}
-
-