jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/330387 )
Change subject: Do not use assertRegExp in Entity diff classes ...................................................................... Do not use assertRegExp in Entity diff classes This is a small step in a bigger refactoring. This does not much, just gets rid of the condition in the test method by extracting the relevant test cases into dedicated test methods. Change-Id: Ia1b23a64099d194c20f4f20282642aa11f56d795 --- M repo/tests/phpunit/includes/Diff/EntityContentDiffViewTest.php M repo/tests/phpunit/includes/Diff/EntityDiffVisualizerTest.php 2 files changed, 47 insertions(+), 32 deletions(-) Approvals: Aleksey Bekh-Ivanov (WMDE): Looks good to me, approved jenkins-bot: Verified diff --git a/repo/tests/phpunit/includes/Diff/EntityContentDiffViewTest.php b/repo/tests/phpunit/includes/Diff/EntityContentDiffViewTest.php index 69bc0c2..b69de73 100644 --- a/repo/tests/phpunit/includes/Diff/EntityContentDiffViewTest.php +++ b/repo/tests/phpunit/includes/Diff/EntityContentDiffViewTest.php @@ -21,14 +21,32 @@ * * @license GPL-2.0+ * @author Jeroen De Dauw < jeroended...@gmail.com > + * @author Thiemo Mättig */ class EntityContentDiffViewTest extends \MediaWikiTestCase { - - //@todo: make this a baseclass to use with all types of entities. public function testConstructor() { new EntityContentDiffView( RequestContext::getMain() ); $this->assertTrue( true ); + } + + public function testDiffingEmptyContent() { + $emptyItem = new Item( new ItemId( 'Q1' ) ); + $emptyContent = ItemContent::newFromItem( $emptyItem ); + + $html = $this->newDiffView()->generateContentDiffBody( $emptyContent, $emptyContent ); + + $this->assertSame( '', $html ); + } + + public function testDiffingSameContent() { + $item = new Item( new ItemId( 'Q1' ) ); + $item->setLabel( 'en', 'Not empty any more' ); + $itemContent = ItemContent::newFromItem( $item ); + + $html = $this->newDiffView()->generateContentDiffBody( $itemContent, $itemContent ); + + $this->assertSame( '', $html ); } public function itemProvider() { @@ -114,8 +132,6 @@ ); return array( - 'empty' => array( $empty, $empty, array( 'empty' => '/^$/', ) ), - 'same' => array( $itemContent, $itemContent, array( 'empty' => '/^$/', ) ), 'from emtpy' => array( $empty, $itemContent, $insTags ), 'to empty' => array( $itemContent, $empty, $delTags ), 'changed' => array( $itemContent, $itemContent2, $changeTags ), @@ -129,22 +145,22 @@ * @dataProvider itemProvider */ public function testGenerateContentDiffBody( ItemContent $itemContent, ItemContent $itemContent2, array $matchers ) { + $html = $this->newDiffView()->generateContentDiffBody( $itemContent, $itemContent2 ); + + $this->assertInternalType( 'string', $html ); + foreach ( $matchers as $name => $matcher ) { + $this->assertTag( $matcher, $html, $name ); + } + } + + /** + * @return EntityContentDiffView + */ + private function newDiffView() { $context = new DerivativeContext( RequestContext::getMain() ); $context->setLanguage( Language::factory( 'en' ) ); - $diffView = new EntityContentDiffView( $context ); - - $html = $diffView->generateContentDiffBody( $itemContent, $itemContent2 ); - - $this->assertInternalType( 'string', $html ); - - foreach ( $matchers as $name => $matcher ) { - if ( is_string( $matcher ) ) { - $this->assertRegExp( $matcher, $html ); - } else { - $this->assertTag( $matcher, $html, $name ); - } - } + return new EntityContentDiffView( $context ); } } diff --git a/repo/tests/phpunit/includes/Diff/EntityDiffVisualizerTest.php b/repo/tests/phpunit/includes/Diff/EntityDiffVisualizerTest.php index 0776a09..a817ab0 100644 --- a/repo/tests/phpunit/includes/Diff/EntityDiffVisualizerTest.php +++ b/repo/tests/phpunit/includes/Diff/EntityDiffVisualizerTest.php @@ -25,12 +25,19 @@ * * @license GPL-2.0+ * @author Daniel Kinzler + * @author Thiemo Mättig */ class EntityDiffVisualizerTest extends MediaWikiTestCase { - public function diffProvider() { + public function testVisualizingEmptyDiff() { $emptyDiff = new EntityContentDiff( new EntityDiff(), new Diff() ); + $html = $this->getVisualizer()->visualizeEntityContentDiff( $emptyDiff ); + + $this->assertSame( '', $html ); + } + + public function diffProvider() { $fingerprintDiff = new EntityContentDiff( new EntityDiff( array( 'label' => new Diff( array( @@ -75,7 +82,6 @@ ); return array( - 'empty' => array( $emptyDiff, array( 'empty' => '/^$/', ) ), 'fingerprint changed' => array( $fingerprintDiff, $fingerprintTags ), 'redirect changed' => array( $redirectDiff, $redirectTags ), ); @@ -84,7 +90,7 @@ /** * @return IContextSource */ - protected function getMockContext() { + private function getMockContext() { $en = Language::factory( 'en' ); $mock = $this->getMock( IContextSource::class ); @@ -98,7 +104,7 @@ /** * @return ClaimDiffer */ - protected function getMockClaimDiffer() { + private function getMockClaimDiffer() { $mock = $this->getMockBuilder( ClaimDiffer::class ) ->disableOriginalConstructor() ->getMock(); @@ -108,7 +114,7 @@ /** * @return ClaimDifferenceVisualizer */ - protected function getMockClaimDiffVisualizer() { + private function getMockClaimDiffVisualizer() { $mock = $this->getMockBuilder( ClaimDifferenceVisualizer::class ) ->disableOriginalConstructor() ->getMock(); @@ -118,7 +124,7 @@ /** * @return EntityDiffVisualizer */ - protected function getVisualizer() { + private function getVisualizer() { $enwiki = new Site(); $enwiki->setGlobalId( 'enwiki' ); @@ -135,18 +141,11 @@ * @dataProvider diffProvider */ public function testGenerateEntityContentDiffBody( EntityContentDiff $diff, array $matchers ) { - $visualizer = $this->getVisualizer(); - - $html = $visualizer->visualizeEntityContentDiff( $diff ); + $html = $this->getVisualizer()->visualizeEntityContentDiff( $diff ); $this->assertInternalType( 'string', $html ); - foreach ( $matchers as $name => $matcher ) { - if ( is_string( $matcher ) ) { - $this->assertRegExp( $matcher, $html ); - } else { - $this->assertTag( $matcher, $html, $name ); - } + $this->assertTag( $matcher, $html, $name ); } } -- To view, visit https://gerrit.wikimedia.org/r/330387 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ia1b23a64099d194c20f4f20282642aa11f56d795 Gerrit-PatchSet: 3 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de> Gerrit-Reviewer: Addshore <addshorew...@gmail.com> Gerrit-Reviewer: Aleksey Bekh-Ivanov (WMDE) <aleksey.bekh-iva...@wikimedia.de> Gerrit-Reviewer: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits