Merge "Fix wrong @return type hints in Language::tsTo… methods"
[lhc/web/wiklou.git] / tests / phpunit / includes / specials / SpecialSearchTest.php
index 13c2838..a4e4df1 100644 (file)
@@ -44,24 +44,24 @@ class SpecialSearchTest extends MediaWikiTestCase {
                 * after an assertion fail.
                 */
                $this->assertEquals(
-                       array( /** Expected: */
+                       [ /** Expected: */
                                'ProfileName' => $expectedProfile,
                                'Namespaces' => $expectedNS,
-                       ),
-                       array( /** Actual: */
+                       ],
+                       [ /** Actual: */
                                'ProfileName' => $search->getProfile(),
                                'Namespaces' => $search->getNamespaces(),
-                       ),
+                       ],
                        $message
                );
        }
 
        public static function provideSearchOptionsTests() {
                $defaultNS = SearchEngine::defaultNamespaces();
-               $EMPTY_REQUEST = array();
+               $EMPTY_REQUEST = [];
                $NO_USER_PREF = null;
 
-               return array(
+               return [
                        /**
                         * Parameters:
                         *     <Web Request>, <User options>
@@ -69,28 +69,28 @@ class SpecialSearchTest extends MediaWikiTestCase {
                         *     <ProfileName>, <NSList>
                         * Then an optional message.
                         */
-                       array(
+                       [
                                $EMPTY_REQUEST, $NO_USER_PREF,
                                'default', $defaultNS,
                                'Bug 33270: No request nor user preferences should give default profile'
-                       ),
-                       array(
-                               array( 'ns5' => 1 ), $NO_USER_PREF,
-                               'advanced', array( 5 ),
+                       ],
+                       [
+                               [ 'ns5' => 1 ], $NO_USER_PREF,
+                               'advanced', [ 5 ],
                                'Web request with specific NS should override user preference'
-                       ),
-                       array(
-                               $EMPTY_REQUEST, array(
+                       ],
+                       [
+                               $EMPTY_REQUEST, [
                                'searchNs2' => 1,
                                'searchNs14' => 1,
-                       ) + array_fill_keys( array_map( function ( $ns ) {
+                       ] + array_fill_keys( array_map( function ( $ns ) {
                                return "searchNs$ns";
                        }, $defaultNS ), 0 ),
-                               'advanced', array( 2, 14 ),
+                               'advanced', [ 2, 14 ],
                                'Bug 33583: search with no option should honor User search preferences'
                                        . ' and have all other namespace disabled'
-                       ),
-               );
+                       ],
+               ];
        }
 
        /**
@@ -115,9 +115,9 @@ class SpecialSearchTest extends MediaWikiTestCase {
         * https://gerrit.wikimedia.org/r/4841
         */
        public function testSearchTermIsNotExpanded() {
-               $this->setMwGlobals( array(
+               $this->setMwGlobals( [
                        'wgSearchType' => null,
-               ) );
+               ] );
 
                # Initialize [[Special::Search]]
                $search = new SpecialSearch();
@@ -143,29 +143,29 @@ class SpecialSearchTest extends MediaWikiTestCase {
        }
 
        public function provideRewriteQueryWithSuggestion() {
-               return array(
-                       array(
+               return [
+                       [
                                'With suggestion and no rewritten query shows did you mean',
                                '/Did you mean: <a[^>]+>first suggestion/',
-                               new SpecialSearchTestMockResultSet( 'first suggestion', null, array(
+                               new SpecialSearchTestMockResultSet( 'first suggestion', null, [
                                        SearchResult::newFromTitle( Title::newMainPage() ),
-                               ) ),
-                       ),
+                               ] ),
+                       ],
 
-                       array(
+                       [
                                'With rewritten query informs user of change',
                                '/Showing results for <a[^>]+>first suggestion/',
-                               new SpecialSearchTestMockResultSet( 'asdf', 'first suggestion', array(
+                               new SpecialSearchTestMockResultSet( 'asdf', 'first suggestion', [
                                        SearchResult::newFromTitle( Title::newMainPage() ),
-                               ) ),
-                       ),
+                               ] ),
+                       ],
 
-                       array(
+                       [
                                'When both queries have no results user gets no results',
                                '/There were no results matching the query/',
-                               new SpecialSearchTestMockResultSet( 'first suggestion', 'first suggestion', array() ),
-                       ),
-               );
+                               new SpecialSearchTestMockResultSet( 'first suggestion', 'first suggestion', [] ),
+                       ],
+               ];
        }
 
        /**
@@ -174,13 +174,14 @@ class SpecialSearchTest extends MediaWikiTestCase {
        public function testRewriteQueryWithSuggestion( $message, $expectRegex, $results ) {
                $mockSearchEngine = $this->mockSearchEngine( $results );
                $search = $this->getMockBuilder( 'SpecialSearch' )
-                       ->setMethods( array( 'getSearchEngine' ) )
+                       ->setMethods( [ 'getSearchEngine' ] )
                        ->getMock();
                $search->expects( $this->any() )
                        ->method( 'getSearchEngine' )
                        ->will( $this->returnValue( $mockSearchEngine ) );
 
                $search->getContext()->setTitle( Title::makeTitle( NS_SPECIAL, 'Search' ) );
+               $search->getContext()->setLanguage( Language::factory( 'en' ) );
                $search->load();
                $search->showResults( 'this is a fake search' );
 
@@ -192,7 +193,7 @@ class SpecialSearchTest extends MediaWikiTestCase {
 
        protected function mockSearchEngine( $results ) {
                $mock = $this->getMockBuilder( 'SearchEngine' )
-                       ->setMethods( array( 'searchText', 'searchTitle' ) )
+                       ->setMethods( [ 'searchText', 'searchTitle' ] )
                        ->getMock();
 
                $mock->expects( $this->any() )
@@ -207,7 +208,12 @@ class SpecialSearchTestMockResultSet extends SearchResultSet {
        protected $results;
        protected $suggestion;
 
-       public function __construct( $suggestion = null, $rewrittenQuery = null, array $results = array(), $containedSyntax = false) {
+       public function __construct(
+               $suggestion = null,
+               $rewrittenQuery = null,
+               array $results = [],
+               $containedSyntax = false
+       ) {
                $this->suggestion = $suggestion;
                $this->rewrittenQuery = $rewrittenQuery;
                $this->results = $results;