MediaWiki  1.23.0
SpecialSearchTest.php
Go to the documentation of this file.
1 <?php
11  private $search;
12 
22  $requested, $userOptions, $expectedProfile, $expectedNS,
23  $message = 'Profile name and namespaces mismatches!'
24  ) {
25  $context = new RequestContext;
26  $context->setUser(
27  $this->newUserWithSearchNS( $userOptions )
28  );
29  /*
30  $context->setRequest( new FauxRequest( array(
31  'ns5'=>true,
32  'ns6'=>true,
33  ) ));
34  */
35  $context->setRequest( new FauxRequest( $requested ) );
36  $search = new SpecialSearch();
37  $search->setContext( $context );
38  $search->load();
39 
45  $this->assertEquals(
46  array(
47  'ProfileName' => $expectedProfile,
48  'Namespaces' => $expectedNS,
49  ),
50  array(
51  'ProfileName' => $search->getProfile(),
52  'Namespaces' => $search->getNamespaces(),
53  ),
54  $message
55  );
56  }
57 
58  public static function provideSearchOptionsTests() {
59  $defaultNS = SearchEngine::defaultNamespaces();
60  $EMPTY_REQUEST = array();
61  $NO_USER_PREF = null;
62 
63  return array(
71  array(
72  $EMPTY_REQUEST, $NO_USER_PREF,
73  'default', $defaultNS,
74  'Bug 33270: No request nor user preferences should give default profile'
75  ),
76  array(
77  array( 'ns5' => 1 ), $NO_USER_PREF,
78  'advanced', array( 5 ),
79  'Web request with specific NS should override user preference'
80  ),
81  array(
82  $EMPTY_REQUEST, array(
83  'searchNs2' => 1,
84  'searchNs14' => 1,
85  ) + array_fill_keys( array_map( function ( $ns ) {
86  return "searchNs$ns";
87  }, $defaultNS ), 0 ),
88  'advanced', array( 2, 14 ),
89  'Bug 33583: search with no option should honor User search preferences'
90  . ' and have all other namespace disabled'
91  ),
92  );
93  }
94 
99  function newUserWithSearchNS( $opt = null ) {
100  $u = User::newFromId( 0 );
101  if ( $opt === null ) {
102  return $u;
103  }
104  foreach ( $opt as $name => $value ) {
105  $u->setOption( $name, $value );
106  }
107 
108  return $u;
109  }
110 
115  public function testSearchTermIsNotExpanded() {
116 
117  # Initialize [[Special::Search]]
118  $search = new SpecialSearch();
119  $search->getContext()->setTitle( Title::newFromText( 'Special:Search' ) );
120  $search->load();
121 
122  # Simulate a user searching for a given term
123  $term = '{{SITENAME}}';
124  $search->showResults( $term );
125 
126  # Lookup the HTML page title set for that page
127  $pageTitle = $search
128  ->getContext()
129  ->getOutput()
130  ->getHTMLTitle();
131 
132  # Compare :-]
133  $this->assertRegExp(
134  '/' . preg_quote( $term ) . '/',
135  $pageTitle,
136  "Search term '{$term}' should not be expanded in Special:Search <title>"
137  );
138  }
139 }
FauxRequest
WebRequest clone which takes values from a provided array.
Definition: WebRequest.php:1275
User\newFromId
static newFromId( $id)
Static factory method for creation from a given user ID.
Definition: User.php:411
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:189
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
RequestContext\setUser
setUser(User $u)
Set the User object.
Definition: RequestContext.php:225
SearchEngine\defaultNamespaces
static defaultNamespaces()
An array of namespaces indexes to be searched by default.
Definition: SearchEngine.php:393
SpecialSearchTest\newUserWithSearchNS
newUserWithSearchNS( $opt=null)
Helper to create a new User object with given options User remains anonymous though.
Definition: SpecialSearchTest.php:99
MediaWikiTestCase
Definition: MediaWikiTestCase.php:6
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
RequestContext
Group all the pieces relevant to the context of a request into one instance.
Definition: RequestContext.php:30
SpecialSearchTest\provideSearchOptionsTests
static provideSearchOptionsTests()
Definition: SpecialSearchTest.php:58
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:336
$value
$value
Definition: styleTest.css.php:45
SpecialSearchTest\testProfileAndNamespaceLoading
testProfileAndNamespaceLoading( $requested, $userOptions, $expectedProfile, $expectedNS, $message='Profile name and namespaces mismatches!')
@covers SpecialSearch::load @dataProvider provideSearchOptionsTests
Definition: SpecialSearchTest.php:21
SpecialSearch
implements Special:Search - Run text & title search and display the output
Definition: SpecialSearch.php:30
SpecialSearchTest\testSearchTermIsNotExpanded
testSearchTermIsNotExpanded()
Verify we do not expand search term in <title> on search result page https://gerrit....
Definition: SpecialSearchTest.php:115
SpecialSearchTest
Test class for SpecialSearch class Copyright © 2012, Antoine Musso.
Definition: SpecialSearchTest.php:10
$term
the value to return A Title object or null whereas SearchGetNearMatch runs after $term
Definition: hooks.txt:2125
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
SpecialSearchTest\$search
$search
Definition: SpecialSearchTest.php:11