jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/334333 )
Change subject: Refactoring SpecialItemByTitleTest
......................................................................
Refactoring SpecialItemByTitleTest
Before we can get rid of assertTag we should understand
what is actually tested.
Bug: T69122
Change-Id: I5315e5a48cb4e4bfc6680e101c3cb587b64e9df6
---
M repo/tests/phpunit/includes/Specials/SpecialItemByTitleTest.php
1 file changed, 81 insertions(+), 81 deletions(-)
Approvals:
WMDE-leszek: Looks good to me, approved
jenkins-bot: Verified
diff --git a/repo/tests/phpunit/includes/Specials/SpecialItemByTitleTest.php
b/repo/tests/phpunit/includes/Specials/SpecialItemByTitleTest.php
index 9d39bf4..b502b8a 100644
--- a/repo/tests/phpunit/includes/Specials/SpecialItemByTitleTest.php
+++ b/repo/tests/phpunit/includes/Specials/SpecialItemByTitleTest.php
@@ -3,6 +3,7 @@
namespace Wikibase\Repo\Tests\Specials;
use HashSiteStore;
+use Prophecy\Argument;
use Site;
use SiteLookup;
use SpecialPageTestBase;
@@ -32,13 +33,17 @@
*/
class SpecialItemByTitleTest extends SpecialPageTestBase {
+ const EXISTING_WIKI = 'dewiki';
+ const EXISTING_PAGE = 'Gefunden';
+ const EXISTING_ITEM_ID = 'Q123';
+
/**
- * @return EntityTitleLookup
+ * @return EntityTitleLookup|\PHPUnit_Framework_MockObject_MockObject
*/
private function getMockTitleLookup() {
$mock = $this->getMock( EntityTitleLookup::class );
- $mock->expects( $this->any() )
- ->method( 'getTitleForId' )
+
+ $mock->method( 'getTitleForId' )
->will( $this->returnCallback( function( EntityId $id )
{
return Title::makeTitle( NS_MAIN,
$id->getSerialization() );
} ) );
@@ -47,12 +52,12 @@
}
/**
- * @return LanguageNameLookup
+ * @return LanguageNameLookup|\PHPUnit_Framework_MockObject_MockObject
*/
private function getMockLanguageNameLookup() {
$mock = $this->getMock( LanguageNameLookup::class );
- $mock->expects( $this->any() )
- ->method( 'getName' )
+
+ $mock->method( 'getName' )
->will( $this->returnValue( '<LANG>' ) );
return $mock;
@@ -62,17 +67,14 @@
* @return SiteLinkLookup
*/
private function getMockSiteLinkLookup() {
- $itemId = new ItemId( 'Q123' );
+ $siteLinkLookup = $this->prophesize( SiteLinkLookup::class );
- $mock = $this->getMock( SiteLinkLookup::class );
+ $siteLinkLookup->getItemIdForLink( self::EXISTING_WIKI,
self::EXISTING_PAGE )
+ ->willReturn( new ItemId( self::EXISTING_ITEM_ID ) );
- $mock->expects( $this->any() )
- ->method( 'getItemIdForLink' )
- ->will( $this->returnCallback( function( $siteId,
$pageName ) use ( $itemId ) {
- return $siteId === 'dewiki' ? $itemId : null;
- } ) );
+ $siteLinkLookup->getItemIdForLink( Argument::any(),
Argument::any() )->willReturn( null );
- return $mock;
+ return $siteLinkLookup->reveal();
}
/**
@@ -80,8 +82,8 @@
*/
private function getMockSiteLookup() {
$dewiki = new Site();
- $dewiki->setGlobalId( 'dewiki' );
- $dewiki->setLinkPath( 'http://dewiki.com/$1' );
+ $dewiki->setGlobalId( self::EXISTING_WIKI );
+ $dewiki->setLinkPath( 'http://any-domain.com/$1' );
return new HashSiteStore( [ $dewiki ] );
}
@@ -93,7 +95,7 @@
$siteLookup = $this->getMockSiteLookup();
- $siteLinkTargetProvider = new SiteLinkTargetProvider(
$siteLookup, array() );
+ $siteLinkTargetProvider = new SiteLinkTargetProvider(
$siteLookup, [] );
$page = new SpecialItemByTitle(
$this->getMockTitleLookup(),
@@ -107,77 +109,75 @@
return $page;
}
- public function requestProvider() {
- $cases = array();
- $matchers = array();
+ public function testAllNeededFieldsArePresent_WhenRendered() {
- $matchers['site'] = array(
- 'tag' => 'div',
- 'attributes' => array(
- 'id' => 'wb-itembytitle-sitename',
- ),
- 'child' => array(
- 'tag' => 'input',
- 'attributes' => array(
- 'name' => 'site',
- )
- ) );
- $matchers['page'] = array(
- 'tag' => 'div',
- 'attributes' => array(
- 'id' => 'pagename',
- ),
- 'child' => array(
- 'tag' => 'input',
- 'attributes' => array(
- 'name' => 'page',
- )
- ) );
- $matchers['submit'] = array(
- 'tag' => 'div',
- 'attributes' => array(
- 'id' => 'wb-itembytitle-submit',
- ),
- 'child' => array(
- 'tag' => 'button',
- 'attributes' => array(
- 'type' => 'submit',
- 'name' => '',
- )
- ) );
+ list( $output ) = $this->executeSpecialPage();
- $cases['empty'] = array( '', null, $matchers );
+ $matchers = [];
- // enwiki/NotFound (mock returns null for everything but
dewiki)
- $matchers['site']['child'][0]['attributes']['value'] = 'enwiki';
- $matchers['page']['child'][0]['attributes']['value'] =
'NotFound';
-
- $cases['enwiki/NotFound'] = array( 'enwiki/NotFound', null,
$matchers );
-
- // dewiki/Gefunden (mock returns Q123 for dewiki)
- $matchers = array();
-
- $cases['dewiki/Gefunden'] = array( 'dewiki/Gefunden', 'Q123',
$matchers );
-
- return $cases;
- }
-
- /**
- * @dataProvider requestProvider
- */
- public function testExecute( $sub, $target, array $matchers ) {
- /* @var WebResponse $response */
- list( $output, $response ) = $this->executeSpecialPage( $sub );
-
- if ( $target !== null ) {
- $target = Title::newFromText( $target )->getFullURL();
- $expected = wfExpandUrl( $target, PROTO_CURRENT );
- $this->assertEquals( $expected, $response->getHeader(
'Location' ), 'Redirect' );
- }
+ $matchers['site'] = [
+ 'tag' => 'input',
+ 'attributes' => [
+ 'name' => 'site',
+ ],
+ ];
+ $matchers['page'] = [
+ 'tag' => 'input',
+ 'attributes' => [
+ 'name' => 'page',
+ ],
+ ];
+ $matchers['submit'] = [
+ 'tag' => 'button',
+ 'attributes' => [
+ 'type' => 'submit',
+ 'name' => '',
+ ],
+ ];
foreach ( $matchers as $key => $matcher ) {
$this->assertTag( $matcher, $output, "Failed to match
html output with tag '{$key}''" );
}
}
+ public function
testSiteAndPageFieldsAreFilledIn_WhenRenderedWithSubpageReferingToNonexistentTitle()
{
+ $wiki = 'non_existent_wiki';
+ $page = 'AnyPage';
+ list( $output ) = $this->executeSpecialPage( $wiki . '/' .
$page );
+
+ $matchers = [];
+
+ $matchers['site'] = [
+ 'tag' => 'input',
+ 'attributes' => [
+ 'name' => 'site',
+ 'value' => $wiki
+ ],
+ ];
+ $matchers['page'] = [
+ 'tag' => 'input',
+ 'attributes' => [
+ 'name' => 'page',
+ 'value' => $page
+ ],
+ ];
+
+ foreach ( $matchers as $key => $matcher ) {
+ $this->assertTag( $matcher, $output, "Failed to match
html output with tag '{$key}''" );
+ }
+ }
+
+ public function
testRedirectsToCorrespondingItem_WhenGivenSubPageReferencesExistingPage() {
+
+ $itemId = self::EXISTING_ITEM_ID;
+ $subPage = self::EXISTING_WIKI . '/' . self::EXISTING_PAGE;
+
+ /* @var WebResponse $response */
+ list( $_, $response ) = $this->executeSpecialPage( $subPage );
+
+ $itemUrl = Title::newFromText( $itemId )->getFullURL();
+ $expectedUrl = wfExpandUrl( $itemUrl, PROTO_CURRENT );
+ $this->assertEquals( $expectedUrl, $response->getHeader(
'Location' ), 'Redirect' );
+ }
+
}
--
To view, visit https://gerrit.wikimedia.org/r/334333
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I5315e5a48cb4e4bfc6680e101c3cb587b64e9df6
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Aleksey Bekh-Ivanov (WMDE) <[email protected]>
Gerrit-Reviewer: Jonas Kress (WMDE) <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: WMDE-leszek <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits