aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--includes/specials/SpecialSearch.php21
-rw-r--r--tests/phpunit/includes/specials/SpecialSearchTest.php16
2 files changed, 20 insertions, 17 deletions
diff --git a/includes/specials/SpecialSearch.php b/includes/specials/SpecialSearch.php
index 927464fbb132..3fa86875d691 100644
--- a/includes/specials/SpecialSearch.php
+++ b/includes/specials/SpecialSearch.php
@@ -110,6 +110,8 @@ class SpecialSearch extends SpecialPage {
/**
* Set up basic search parameters from the request and user settings.
+ *
+ * @see tests/phpunit/includes/specials/SpecialSearchTest.php
*/
public function load() {
$request = $this->getRequest();
@@ -117,27 +119,30 @@ class SpecialSearch extends SpecialPage {
$this->mPrefix = $request->getVal( 'prefix', '' );
$user = $this->getUser();
+
# Extract manually requested namespaces
$nslist = $this->powerSearch( $request );
+ if ( !count( $nslist ) ) {
+ # Fallback to user preference
+ $nslist = SearchEngine::userNamespaces( $user );
+ }
+
$profile = null;
if ( !count( $nslist ) ) {
$profile = 'default';
}
+
$profile = $request->getVal( 'profile', $profile );
$profiles = $this->getSearchProfiles();
if ( $profile === null ) {
// BC with old request format
$profile = 'advanced';
- if ( count( $nslist ) ) {
- foreach( $profiles as $key => $data ) {
- if ( $nslist === $data['namespaces'] && $key !== 'advanced') {
- $profile = $key;
- }
+ foreach( $profiles as $key => $data ) {
+ if ( $nslist === $data['namespaces'] && $key !== 'advanced') {
+ $profile = $key;
}
- $this->namespaces = $nslist;
- } else {
- $this->namespaces = SearchEngine::userNamespaces( $user );
}
+ $this->namespaces = $nslist;
} elseif ( $profile === 'advanced' ) {
$this->namespaces = $nslist;
} else {
diff --git a/tests/phpunit/includes/specials/SpecialSearchTest.php b/tests/phpunit/includes/specials/SpecialSearchTest.php
index b1c06cdf6df7..eb60cf2048e2 100644
--- a/tests/phpunit/includes/specials/SpecialSearchTest.php
+++ b/tests/phpunit/includes/specials/SpecialSearchTest.php
@@ -14,11 +14,12 @@ class SpecialSearchTest extends MediaWikiTestCase {
function tearDown() { }
/**
+ * @covers SpecialSearch::load
* @dataProvider provideSearchOptionsTests
* @param $requested Array Request parameters. For example array( 'ns5' => true, 'ns6' => true). NULL to use default options.
* @param $userOptions Array User options to test with. For example array('searchNs5' => 1 );. NULL to use default options.
*/
- function testFoobar(
+ function testProfileAndNamespaceLoading(
$requested, $userOptions, $expectedProfile, $expectedNS,
$message = 'Profile name andnamespaces mismatches!'
) {
@@ -79,14 +80,11 @@ class SpecialSearchTest extends MediaWikiTestCase {
'advanced', array( 5),
'Web request with specific NS should override user preference'
),
- /* FIXME this test is for bug 33583
- array(
- $EMPTY_REQUEST, array( 'searchNs2' ),
- 'advanced', array( 2 ),
- 'Bug 33583: search with no option should honor User search preferences'
- ),
- */
-
+ array(
+ $EMPTY_REQUEST, array( 'searchNs2' => 1, 'searchNs14' => 1 ),
+ 'advanced', array( 2, 14 ),
+ 'Bug 33583: search with no option should honor User search preferences'
+ ),
);
}