From: Antoine Musso Date: Mon, 9 Jan 2012 11:41:13 +0000 (+0000) Subject: test skeleton for Special:Search X-Git-Tag: 1.31.0-rc.0~25405 X-Git-Url: https://git.cyclocoop.org/%7B%24admin_url%7Dmembres/%7B%7B%20url_for%28%27vote%27%2C%20idvote=vote.voteid%29%20%7D%7D?a=commitdiff_plain;h=b549176edfbe717c231fac430826df065fc30940;p=lhc%2Fweb%2Fwiklou.git 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. --- diff --git a/includes/specials/SpecialSearch.php b/includes/specials/SpecialSearch.php index f884401b14..927464fbb1 100644 --- a/includes/specials/SpecialSearch.php +++ b/includes/specials/SpecialSearch.php @@ -37,6 +37,7 @@ class SpecialSearch extends SpecialPage { * null|string */ protected $profile; + function getProfile() { return $this->profile; } /// Search engine protected $searchEngine; @@ -56,6 +57,7 @@ class SpecialSearch extends SpecialPage { * @var array */ protected $namespaces; + function getNamespaces() { return $this->namespaces; } /** * @var bool diff --git a/tests/phpunit/includes/specials/SpecialSearchTest.php b/tests/phpunit/includes/specials/SpecialSearchTest.php new file mode 100644 index 0000000000..f444179acf --- /dev/null +++ b/tests/phpunit/includes/specials/SpecialSearchTest.php @@ -0,0 +1,108 @@ + 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( + $requested, $userOptions, $expectedProfile, $expectedNS, + $message = 'Profile name andnamespaces mismatches!' + ) { + $context = new RequestContext; + $context->setUser( + $this->newUserWithSearchNS( $userOptions ) + ); + /* + $context->setRequest( new FauxRequest( array( + 'ns5'=>true, + 'ns6'=>true, + ) )); + */ + $context->setRequest( new FauxRequest( $requested )); + $search = new SpecialSearch(); + $search->setContext( $context ); + $search->load(); + + /** + * Verify profile name and namespace in the same assertion to make + * sure we will be able to fully compare the above code. PHPUnit stop + * after an assertion fail. + */ + $this->assertEquals( + array( /** Expected: */ + 'ProfileName' => $expectedProfile, + 'Namespaces' => $expectedNS, + ) + , array( /** Actual: */ + 'ProfileName' => $search->getProfile(), + 'Namespaces' => $search->getNamespaces(), + ) + , $message + ); + + } + + function provideSearchOptionsTests() { + $defaultNS = SearchEngine::defaultNamespaces(); + $EMPTY_REQUEST = array(); + $NO_USER_PREF = null; + + return array( + /** + * Parameters: + * , + * Followed by expected values: + * , + * Then an optional message. + */ + array( + $EMPTY_REQUEST, $NO_USER_PREF, + 'default', $defaultNS, + 'Bug 33270: No request nor user preferences should give default profile' + ), + array( + array( 'ns5' => 1 ), $NO_USER_PREF, + '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' + ), + */ + + ); + } + + /** + * Helper to create a new User object with given options + * User remains anonymous though + */ + function newUserWithSearchNS( $opt = null ) { + $u = User::newFromId(0); + if( $opt === null ) { + return $u; + } + foreach($opt as $name => $value) { + $u->setOption( $name, $value ); + } + return $u; + } +} +