X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fsearch%2FSearchEngineTest.php;h=055e9823779d97ba9b86d404070e791cfc08ad0f;hb=a8995619c1bc0c0880962a266a0398bc87d1b7ae;hp=3da1361530f584c1636917d8469d6a3575c9790e;hpb=9221f5ffd09b4f7347dbd5e251c96733c1becba1;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/search/SearchEngineTest.php b/tests/phpunit/includes/search/SearchEngineTest.php index 3da1361530..055e982377 100644 --- a/tests/phpunit/includes/search/SearchEngineTest.php +++ b/tests/phpunit/includes/search/SearchEngineTest.php @@ -14,8 +14,6 @@ class SearchEngineTest extends MediaWikiLangTestCase { */ protected $search; - protected $pageList; - /** * Checks for database type & version. * Will skip current test if DB does not support search. @@ -33,13 +31,9 @@ class SearchEngineTest extends MediaWikiLangTestCase { } $searchType = $this->db->getSearchEngine(); - $this->setMwGlobals( array( + $this->setMwGlobals( [ 'wgSearchType' => $searchType - ) ); - - if ( !isset( self::$pageList ) ) { - $this->addPages(); - } + ] ); $this->search = new $searchType( $this->db ); } @@ -50,33 +44,32 @@ class SearchEngineTest extends MediaWikiLangTestCase { parent::tearDown(); } - protected function addPages() { + public function addDBDataOnce() { 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 ) { @@ -86,7 +79,7 @@ class SearchEngineTest extends MediaWikiLangTestCase { } $this->assertTrue( is_object( $results ) ); - $matches = array(); + $matches = []; $row = $results->next(); while ( $row ) { $matches[] = $row->getTitle()->getPrefixedText(); @@ -101,85 +94,61 @@ class SearchEngineTest extends MediaWikiLangTestCase { 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() { $this->assertEquals( - array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ), + [ 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ], $this->fetchIds( $this->search->searchText( 'AZ' ) ), "Search for normalized from Half-width Upper" ); $this->assertEquals( - array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ), + [ 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ], $this->fetchIds( $this->search->searchText( 'az' ) ), "Search for normalized from Half-width Lower" ); $this->assertEquals( - array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ), + [ 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ], $this->fetchIds( $this->search->searchText( 'AZ' ) ), "Search for normalized from Full-width Upper" ); $this->assertEquals( - array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ), + [ 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ], $this->fetchIds( $this->search->searchText( 'az' ) ), "Search for normalized from Full-width Lower" ); } public function testTextSearch() { $this->assertEquals( - array( 'Smithee' ), + [ 'Smithee' ], $this->fetchIds( $this->search->searchText( 'smithee' ) ), "Plain search failed" ); } public function testTextPowerSearch() { - $this->search->setNamespaces( array( 0, 1, 4 ) ); + $this->search->setNamespaces( [ 0, 1, 4 ] ); $this->assertEquals( - array( + [ 'Smithee', 'Talk:Not Main Page', - ), + ], $this->fetchIds( $this->search->searchText( 'smithee' ) ), "Power search failed" ); } public function testTitleSearch() { $this->assertEquals( - array( + [ 'Alan Smithee', 'Smithee', - ), + ], $this->fetchIds( $this->search->searchTitle( 'smithee' ) ), "Title search failed" ); } public function testTextTitlePowerSearch() { - $this->search->setNamespaces( array( 0, 1, 4 ) ); + $this->search->setNamespaces( [ 0, 1, 4 ] ); $this->assertEquals( - array( + [ 'Alan Smithee', 'Smithee', 'Talk:Smithee', - ), + ], $this->fetchIds( $this->search->searchTitle( 'smithee' ) ), "Title power search failed" ); }