20e42a68bdcd77b1563dabed9640b0507d7a9d53
3 * Test class for SpecialSearch class
4 * Copyright © 2012, Antoine Musso
6 * @author Antoine Musso
10 class SpecialSearchTest
extends MediaWikiTestCase
{
14 function tearDown() { }
17 * @covers SpecialSearch::load
18 * @dataProvider provideSearchOptionsTests
19 * @param $requested Array Request parameters. For example array( 'ns5' => true, 'ns6' => true). NULL to use default options.
20 * @param $userOptions Array User options to test with. For example array('searchNs5' => 1 );. NULL to use default options.
21 * @param $expectedProfile An expected search profile name
22 * @param $expectedNs Array Expected namespaces
24 function testProfileAndNamespaceLoading(
25 $requested, $userOptions, $expectedProfile, $expectedNS,
26 $message = 'Profile name and namespaces mismatches!'
28 $context = new RequestContext
;
30 $this->newUserWithSearchNS( $userOptions )
33 $context->setRequest( new FauxRequest( array(
38 $context->setRequest( new FauxRequest( $requested ));
39 $search = new SpecialSearch();
40 $search->setContext( $context );
44 * Verify profile name and namespace in the same assertion to make
45 * sure we will be able to fully compare the above code. PHPUnit stop
46 * after an assertion fail.
49 array( /** Expected: */
50 'ProfileName' => $expectedProfile,
51 'Namespaces' => $expectedNS,
53 , array( /** Actual: */
54 'ProfileName' => $search->getProfile(),
55 'Namespaces' => $search->getNamespaces(),
62 function provideSearchOptionsTests() {
63 $defaultNS = SearchEngine
::defaultNamespaces();
64 $EMPTY_REQUEST = array();
70 * <Web Request>, <User options>
71 * Followed by expected values:
72 * <ProfileName>, <NSList>
73 * Then an optional message.
76 $EMPTY_REQUEST, $NO_USER_PREF,
77 'default', $defaultNS,
78 'Bug 33270: No request nor user preferences should give default profile'
81 array( 'ns5' => 1 ), $NO_USER_PREF,
82 'advanced', array( 5),
83 'Web request with specific NS should override user preference'
86 $EMPTY_REQUEST, array( 'searchNs2' => 1, 'searchNs14' => 1 ),
87 'advanced', array( 2, 14 ),
88 'Bug 33583: search with no option should honor User search preferences'
91 $EMPTY_REQUEST, array_fill_keys( array_map( function( $ns ) {
93 }, $defaultNS ), 0 ) +
array( 'searchNs2' => 1, 'searchNs14' => 1 ),
94 'advanced', array( 2, 14 ),
95 'Bug 33583: search with no option should honor User search preferences'
96 . 'and have all other namespace disabled'
102 * Helper to create a new User object with given options
103 * User remains anonymous though
105 function newUserWithSearchNS( $opt = null ) {
106 $u = User
::newFromId(0);
107 if( $opt === null ) {
110 foreach($opt as $name => $value) {
111 $u->setOption( $name, $value );