r108400 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108399‎ | r108400 | r108401 >
Date:11:41, 9 January 2012
Author:hashar
Status:ok (Comments)
Tags:
Comment:
test skeleton for Special:Search

Only two tests for now. A third one was written for r106780 / bug 33583
but is disabled to avoid breaking Jenkins.
Modified paths:
  • /trunk/phase3/includes/specials/SpecialSearch.php (modified) (history)
  • /trunk/phase3/tests/phpunit/includes/specials/SpecialSearchTest.php (added) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/includes/specials/SpecialSearchTest.php
@@ -0,0 +1,108 @@
 2+<?php
 3+/**
 4+ * Test class for SpecialSearch class
 5+ * Copyright © 2012, Antoine Musso
 6+ *
 7+ * @author Antoine Musso
 8+ * @group Database
 9+ */
 10+
 11+class SpecialSearchTest extends MediaWikiTestCase {
 12+ private $search;
 13+
 14+ function setUp() { }
 15+ function tearDown() { }
 16+
 17+ /**
 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+ */
 22+ function testFoobar(
 23+ $requested, $userOptions, $expectedProfile, $expectedNS,
 24+ $message = 'Profile name andnamespaces mismatches!'
 25+ ) {
 26+ $context = new RequestContext;
 27+ $context->setUser(
 28+ $this->newUserWithSearchNS( $userOptions )
 29+ );
 30+ /*
 31+ $context->setRequest( new FauxRequest( array(
 32+ 'ns5'=>true,
 33+ 'ns6'=>true,
 34+ ) ));
 35+ */
 36+ $context->setRequest( new FauxRequest( $requested ));
 37+ $search = new SpecialSearch();
 38+ $search->setContext( $context );
 39+ $search->load();
 40+
 41+ /**
 42+ * Verify profile name and namespace in the same assertion to make
 43+ * sure we will be able to fully compare the above code. PHPUnit stop
 44+ * after an assertion fail.
 45+ */
 46+ $this->assertEquals(
 47+ array( /** Expected: */
 48+ 'ProfileName' => $expectedProfile,
 49+ 'Namespaces' => $expectedNS,
 50+ )
 51+ , array( /** Actual: */
 52+ 'ProfileName' => $search->getProfile(),
 53+ 'Namespaces' => $search->getNamespaces(),
 54+ )
 55+ , $message
 56+ );
 57+
 58+ }
 59+
 60+ function provideSearchOptionsTests() {
 61+ $defaultNS = SearchEngine::defaultNamespaces();
 62+ $EMPTY_REQUEST = array();
 63+ $NO_USER_PREF = null;
 64+
 65+ return array(
 66+ /**
 67+ * Parameters:
 68+ * <Web Request>, <User options>
 69+ * Followed by expected values:
 70+ * <ProfileName>, <NSList>
 71+ * Then an optional message.
 72+ */
 73+ array(
 74+ $EMPTY_REQUEST, $NO_USER_PREF,
 75+ 'default', $defaultNS,
 76+ 'Bug 33270: No request nor user preferences should give default profile'
 77+ ),
 78+ array(
 79+ array( 'ns5' => 1 ), $NO_USER_PREF,
 80+ 'advanced', array( 5),
 81+ 'Web request with specific NS should override user preference'
 82+ ),
 83+ /* FIXME this test is for bug 33583
 84+ array(
 85+ $EMPTY_REQUEST, array( 'searchNs2' ),
 86+ 'advanced', array( 2 ),
 87+ 'Bug 33583: search with no option should honor User search preferences'
 88+ ),
 89+ */
 90+
 91+ );
 92+ }
 93+
 94+ /**
 95+ * Helper to create a new User object with given options
 96+ * User remains anonymous though
 97+ */
 98+ function newUserWithSearchNS( $opt = null ) {
 99+ $u = User::newFromId(0);
 100+ if( $opt === null ) {
 101+ return $u;
 102+ }
 103+ foreach($opt as $name => $value) {
 104+ $u->setOption( $name, $value );
 105+ }
 106+ return $u;
 107+ }
 108+}
 109+
Property changes on: trunk/phase3/tests/phpunit/includes/specials/SpecialSearchTest.php
___________________________________________________________________
Added: svn:eol-style
1110 + native
Index: trunk/phase3/includes/specials/SpecialSearch.php
@@ -37,6 +37,7 @@
3838 * null|string
3939 */
4040 protected $profile;
 41+ function getProfile() { return $this->profile; }
4142
4243 /// Search engine
4344 protected $searchEngine;
@@ -56,6 +57,7 @@
5758 * @var array
5859 */
5960 protected $namespaces;
 61+ function getNamespaces() { return $this->namespaces; }
6062
6163 /**
6264 * @var bool

Follow-up revisions

RevisionCommit summaryAuthorDate
r108712bug 33583 search ns user pref ignored!...hashar09:03, 12 January 2012

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r106780Fix for bug 33270: default to 'default' search profile...nikerabbit11:17, 20 December 2011

Comments

#Comment by 😂 (talk | contribs)   13:52, 9 January 2012

Indentation is funky in the body for provideSearchOptionsTests(). Otherwise ok

Status & tagging log