Krinkle has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/161139

Change subject: MediaWikiTestCase: Centralise insertPage() logic from 
SearchEngineTest
......................................................................

MediaWikiTestCase: Centralise insertPage() logic from SearchEngineTest

Make it re-usable for other tests and update SearchEngineTest to
use the addDBData (which is called automatically) instead of
manually keeping track of the state.

Change-Id: I75a6951545d9824e71e00f0f96936c53b400dce6
---
M tests/phpunit/MediaWikiTestCase.php
M tests/phpunit/includes/search/SearchEngineTest.php
2 files changed, 45 insertions(+), 49 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/39/161139/1

diff --git a/tests/phpunit/MediaWikiTestCase.php 
b/tests/phpunit/MediaWikiTestCase.php
index 995853e..9000def 100644
--- a/tests/phpunit/MediaWikiTestCase.php
+++ b/tests/phpunit/MediaWikiTestCase.php
@@ -429,6 +429,33 @@
        }
 
        /**
+        * Insert a new page.
+        *
+        * Should be called from addDBData().
+        *
+        * @param string $pageName Page name
+        * @param string $text Page's content
+        * @return array Title object and page id
+        */
+       protected function insertPage( $pageName, $text = 'Sample page for unit 
test.' ) {
+               $title = Title::newFromText( $pageName, 0 );
+
+               $user = User::newFromName( 'WikiSysop' );
+               $comment = __METHOD__ . ': Sample page for unit test.';
+
+               // Avoid memory leak...?
+               LinkCache::singleton()->clear();
+
+               $page = WikiPage::factory( $title );
+               $page->doEditContent( ContentHandler::makeContent( $text, 
$title ), $comment, 0, false, $user );
+
+               return array(
+                       'title' => $title,
+                       'id' => $page->getId(),
+               );
+       }
+
+       /**
         * Stub. If a test needs to add additional data to the database, it 
should
         * implement this method and do so
         *
diff --git a/tests/phpunit/includes/search/SearchEngineTest.php 
b/tests/phpunit/includes/search/SearchEngineTest.php
index 3da1361..d0cbfa0 100644
--- a/tests/phpunit/includes/search/SearchEngineTest.php
+++ b/tests/phpunit/includes/search/SearchEngineTest.php
@@ -14,8 +14,6 @@
         */
        protected $search;
 
-       protected $pageList;
-
        /**
         * Checks for database type & version.
         * Will skip current test if DB does not support search.
@@ -37,10 +35,6 @@
                        'wgSearchType' => $searchType
                ) );
 
-               if ( !isset( self::$pageList ) ) {
-                       $this->addPages();
-               }
-
                $this->search = new $searchType( $this->db );
        }
 
@@ -50,33 +44,32 @@
                parent::tearDown();
        }
 
-       protected function addPages() {
+       public function addDBData() {
                if ( !$this->isWikitextNS( NS_MAIN ) ) {
                        // @todo cover the case of non-wikitext content in the 
main namespace
                        return;
                }
 
-               $this->insertPage( "Not_Main_Page", "This is not a main page", 
0 );
+               $this->insertPage( 'Not_Main_Page', 'This is not a main page' );
                $this->insertPage(
                        'Talk:Not_Main_Page',
-                       'This is not a talk page to the main page, see 
[[smithee]]',
-                       1
+                       'This is not a talk page to the main page, see 
[[smithee]]'
                );
-               $this->insertPage( 'Smithee', 'A smithee is one who smiths. See 
also [[Alan Smithee]]', 0 );
-               $this->insertPage( 'Talk: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', 'Help me!', 4 );
-               $this->insertPage( 'Thppt', 'Blah blah', 0 );
-               $this->insertPage( 'Alan_Smithee', 'yum', 0 );
-               $this->insertPage( 'Pages', 'are\'food', 0 );
-               $this->insertPage( 'HalfOneUp', 'AZ', 0 );
-               $this->insertPage( 'FullOneUp', 'AZ', 0 );
-               $this->insertPage( 'HalfTwoLow', 'az', 0 );
-               $this->insertPage( 'FullTwoLow', 'az', 0 );
-               $this->insertPage( 'HalfNumbers', '1234567890', 0 );
-               $this->insertPage( 'FullNumbers', '1234567890', 0 );
-               $this->insertPage( 'DomainName', 'example.com', 0 );
+               $this->insertPage( 'Smithee', 'A smithee is one who smiths. See 
also [[Alan Smithee]]' );
+               $this->insertPage( 'Talk:Smithee', 'This article sucks.' );
+               $this->insertPage( 'Unrelated_page', 'Nothing in this page is 
about the S word.' );
+               $this->insertPage( 'Another_page', 'This page also is 
unrelated.' );
+               $this->insertPage( 'Help:Help', 'Help me!' );
+               $this->insertPage( 'Thppt', 'Blah blah' );
+               $this->insertPage( 'Alan_Smithee', 'yum' );
+               $this->insertPage( 'Pages', 'are\'food' );
+               $this->insertPage( 'HalfOneUp', 'AZ' );
+               $this->insertPage( 'FullOneUp', 'AZ' );
+               $this->insertPage( 'HalfTwoLow', 'az' );
+               $this->insertPage( 'FullTwoLow', 'az' );
+               $this->insertPage( 'HalfNumbers', '1234567890' );
+               $this->insertPage( 'FullNumbers', '1234567890' );
+               $this->insertPage( 'DomainName', 'example.com' );
        }
 
        protected function fetchIds( $results ) {
@@ -99,30 +92,6 @@
                sort( $matches );
 
                return $matches;
-       }
-
-       /**
-        * Insert a new page
-        *
-        * @param string $pageName Page name
-        * @param string $text Page's content
-        * @param int $ns Unused
-        */
-       protected function insertPage( $pageName, $text, $ns ) {
-               $title = Title::newFromText( $pageName, $ns );
-
-               $user = User::newFromName( 'WikiSysop' );
-               $comment = 'Search Test';
-
-               // avoid memory leak...?
-               LinkCache::singleton()->clear();
-
-               $page = WikiPage::factory( $title );
-               $page->doEditContent( ContentHandler::makeContent( $text, 
$title ), $comment, 0, false, $user );
-
-               $this->pageList[] = array( $title, $page->getId() );
-
-               return true;
        }
 
        public function testFullWidth() {

-- 
To view, visit https://gerrit.wikimedia.org/r/161139
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I75a6951545d9824e71e00f0f96936c53b400dce6
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Krinkle <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to