MediaWiki  REL1_19
SpecialSearchTest.php
Go to the documentation of this file.
00001 <?php
00010 class SpecialSearchTest extends MediaWikiTestCase {
00011         private $search;
00012 
00013         function setUp() { }
00014         function tearDown() { }
00015 
00024         function testProfileAndNamespaceLoading(
00025                 $requested, $userOptions, $expectedProfile, $expectedNS,
00026                 $message = 'Profile name and namespaces mismatches!'
00027         ) {
00028                 $context = new RequestContext;
00029                 $context->setUser(
00030                         $this->newUserWithSearchNS( $userOptions )
00031                 );
00032                 /*
00033                 $context->setRequest( new FauxRequest( array(
00034                         'ns5'=>true,
00035                         'ns6'=>true,
00036                 ) ));
00037                  */
00038                 $context->setRequest( new FauxRequest( $requested ));
00039                 $search = new SpecialSearch();
00040                 $search->setContext( $context );
00041                 $search->load();
00042 
00048                 $this->assertEquals(
00049                         array( 
00050                                 'ProfileName' => $expectedProfile,
00051                                 'Namespaces'  => $expectedNS,
00052                         )
00053                         , array( 
00054                                 'ProfileName' => $search->getProfile(),
00055                                 'Namespaces'  => $search->getNamespaces(),
00056                         )
00057                         , $message
00058                 );
00059 
00060         }
00061 
00062         function provideSearchOptionsTests() {
00063                 $defaultNS = SearchEngine::defaultNamespaces();
00064                 $EMPTY_REQUEST = array();
00065                 $NO_USER_PREF  = null;
00066 
00067                 return array(
00075                         array(
00076                                 $EMPTY_REQUEST, $NO_USER_PREF,
00077                                 'default', $defaultNS,
00078                                 'Bug 33270: No request nor user preferences should give default profile'
00079                         ),
00080                         array(
00081                                 array( 'ns5' => 1 ), $NO_USER_PREF,
00082                                 'advanced', array(  5),
00083                                 'Web request with specific NS should override user preference'
00084                         ),
00085                         array(
00086                                 $EMPTY_REQUEST, array( 'searchNs2' => 1, 'searchNs14' => 1 ),
00087                                 'advanced', array( 2, 14 ),
00088                                 'Bug 33583: search with no option should honor User search preferences'
00089                         ),
00090                 );
00091         }
00092 
00097         function newUserWithSearchNS( $opt = null ) {
00098                 $u = User::newFromId(0);
00099                 if( $opt === null ) {
00100                         return $u;
00101                 }
00102                 foreach($opt as $name => $value) {
00103                         $u->setOption( $name, $value );
00104                 }
00105                 return $u;
00106         }
00107 }
00108