Adrian Lang has uploaded a new change for review. https://gerrit.wikimedia.org/r/191268
Change subject: Isolate EntityTermsView tests from SectionEditLinkGenerator implementation ...................................................................... Isolate EntityTermsView tests from SectionEditLinkGenerator implementation Change-Id: I91c3d1253934fc4407efbfce9422e49c38af2142 --- M repo/tests/phpunit/includes/View/EntityTermsViewTest.php 1 file changed, 22 insertions(+), 11 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/68/191268/1 diff --git a/repo/tests/phpunit/includes/View/EntityTermsViewTest.php b/repo/tests/phpunit/includes/View/EntityTermsViewTest.php index 43a926f..6eb1a23 100644 --- a/repo/tests/phpunit/includes/View/EntityTermsViewTest.php +++ b/repo/tests/phpunit/includes/View/EntityTermsViewTest.php @@ -2,11 +2,11 @@ namespace Wikibase\Test; +use MediaWikiLangTestCase; use MessageCache; use Wikibase\DataModel\Entity\ItemId; use Wikibase\DataModel\Term\Fingerprint; use Wikibase\Repo\View\EntityTermsView; -use Wikibase\Repo\View\SectionEditLinkGenerator; use Wikibase\Repo\View\TextInjector; use Wikibase\Template\TemplateFactory; use Wikibase\Template\TemplateRegistry; @@ -21,7 +21,7 @@ * @author Bene* < [email protected] > * @author Thiemo Mättig */ -class EntityTermsViewTest extends \MediaWikiLangTestCase { +class EntityTermsViewTest extends MediaWikiLangTestCase { protected function setUp() { parent::setUp(); @@ -42,12 +42,24 @@ parent::tearDown(); } - private function getEntityTermsView( $languageCode = 'en' ) { + private function getEntityTermsView( $languageCode = 'en', $called = null ) { $templateFactory = new TemplateFactory( TemplateRegistry::getDefaultInstance() ); + + if ( $called === null ) { + $called = $this->any(); + } + + $sectionEditLinkGenerator = $this->getMockBuilder( 'Wikibase\Repo\View\SectionEditLinkGenerator' ) + ->disableOriginalConstructor() + ->getMock(); + + $sectionEditLinkGenerator->expects( $called ) + ->method( 'getHtmlForEditSection' ) + ->will( $this->returnValue( '~EDITSECTION~' ) ); return new EntityTermsView( $templateFactory, - new SectionEditLinkGenerator( $templateFactory ), + $sectionEditLinkGenerator, $this->getMock( 'Wikibase\Lib\LanguageNameLookup' ), $languageCode ); @@ -93,21 +105,20 @@ * @dataProvider entityFingerprintProvider */ public function testGetHtml_isEditable( Fingerprint $fingerprint, ItemId $entityId, $languageCode ) { - $entityTermsView = $this->getEntityTermsView( $languageCode ); + $entityTermsView = $this->getEntityTermsView( $languageCode, $this->once() ); $html = $entityTermsView->getHtml( $fingerprint, $entityId, '', new TextInjector() ); - $idString = $entityId->getSerialization(); - $this->assertRegExp( '@<a href="[^"]*\bSpecial:SetLabel/' . $idString . '/' . $languageCode . '"@', $html ); + $this->assertContains( '~EDITSECTION~', $html ); } /** * @dataProvider entityFingerprintProvider */ public function testGetHtml_isNotEditable( Fingerprint $fingerprint, ItemId $entityId, $languageCode ) { - $entityTermsView = $this->getEntityTermsView( $languageCode ); + $entityTermsView = $this->getEntityTermsView( $languageCode, $this->never() ); $html = $entityTermsView->getHtml( $fingerprint, $entityId, '', new TextInjector(), false ); - $this->assertNotContains( '<a ', $html ); + $this->assertNotContains( '~EDITSECTION~', $html ); } public function testGetHtml_valuesAreEscaped() { @@ -164,12 +175,12 @@ * @dataProvider entityFingerprintProvider */ public function testGetHtml_withEntityId( Fingerprint $fingerprint, ItemId $entityId, $languageCode ) { - $entityTermsView = $this->getEntityTermsView( $languageCode ); + $entityTermsView = $this->getEntityTermsView( $languageCode, $this->once() ); $html = $entityTermsView->getHtml( $fingerprint, $entityId, '', new TextInjector() ); $idString = $entityId->getSerialization(); $this->assertContains( '(' . $idString . ')', $html ); - $this->assertContains( '<a ', $html ); + $this->assertContains( '~EDITSECTION~', $html ); } public function testGetHtml_withoutEntityId() { -- To view, visit https://gerrit.wikimedia.org/r/191268 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I91c3d1253934fc4407efbfce9422e49c38af2142 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Adrian Lang <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
