jenkins-bot has submitted this change and it was merged.

Change subject: Refactor duplicate code in LinksUpdateHookHandlerTest
......................................................................


Refactor duplicate code in LinksUpdateHookHandlerTest

Change-Id: I9acaadf18e859758cd7bdcb7d260007402695060
---
M tests/phpunit/LinksUpdateHookHandlerTest.php
1 file changed, 29 insertions(+), 18 deletions(-)

Approvals:
  Hoo man: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/tests/phpunit/LinksUpdateHookHandlerTest.php 
b/tests/phpunit/LinksUpdateHookHandlerTest.php
index e25e8bd..0cdec8e 100644
--- a/tests/phpunit/LinksUpdateHookHandlerTest.php
+++ b/tests/phpunit/LinksUpdateHookHandlerTest.php
@@ -2,6 +2,7 @@
 
 namespace PageImages\Tests\Hooks;
 
+use LinksUpdate;
 use PageImages\Hooks\LinksUpdateHookHandler;
 use PageImages;
 use ParserOutput;
@@ -24,7 +25,10 @@
                parent::tearDown();
        }
 
-       public function testOnLinksUpdate() {
+       /**
+        * @return LinksUpdate
+        */
+       private function getLinksUpdate() {
                $parserOutput = new ParserOutput();
                $parserOutput->setExtensionData( 'pageImages', array(
                        array( 'filename' => 'A.jpg', 'fullwidth' => 100, 
'fullheight' => 50 ),
@@ -37,12 +41,13 @@
                        ->method( 'getParserOutput' )
                        ->will( $this->returnValue( $parserOutput ) );
 
-               LinksUpdateHookHandler::onLinksUpdate( $linksUpdate );
-               $this->assertTrue( property_exists( $linksUpdate, 'mProperties' 
), 'precondition' );
-               $this->assertSame( 'A.jpg', 
$linksUpdate->mProperties[PageImages::PROP_NAME] );
+               return $linksUpdate;
        }
 
-       public function testGetMetadata() {
+       /**
+        * @return RepoGroup
+        */
+       private function getRepoGroup() {
                $file = $this->getMockBuilder( 'File' )
                        ->disableOriginalConstructor()
                        ->getMock();
@@ -51,27 +56,33 @@
                        ->method( 'isDeleted' )
                        ->will( $this->returnValue( true ) );
 
-               $mockRepoGroup = $this->getMockBuilder( 'RepoGroup' )
+               $repoGroup = $this->getMockBuilder( 'RepoGroup' )
                        ->disableOriginalConstructor()
                        ->getMock();
-               $mockRepoGroup->expects( $this->any() )
+               $repoGroup->expects( $this->any() )
                        ->method( 'findFile' )
                        ->will( $this->returnValue( $file ) );
-               RepoGroup::setSingleton( $mockRepoGroup );
 
-               $parserOutput = new ParserOutput();
-               $parserOutput->setExtensionData( 'pageImages', array(
-                       array( 'filename' => 'A.jpg', 'fullwidth' => 100, 
'fullheight' => 50 ),
-               ) );
+               return $repoGroup;
+       }
 
-               $linksUpdate = $this->getMockBuilder( 'LinksUpdate' )
-                       ->disableOriginalConstructor()
-                       ->getMock();
-               $linksUpdate->expects( $this->any() )
-                       ->method( 'getParserOutput' )
-                       ->will( $this->returnValue( $parserOutput ) );
+       public function testOnLinksUpdate() {
+               $linksUpdate = $this->getLinksUpdate();
 
                LinksUpdateHookHandler::onLinksUpdate( $linksUpdate );
+
+               $this->assertTrue( property_exists( $linksUpdate, 'mProperties' 
), 'precondition' );
+               $this->assertSame( 'A.jpg', 
$linksUpdate->mProperties[PageImages::PROP_NAME] );
+       }
+
+       public function testFetchingExtendedMetadataFromFile() {
+               // Required to make wfFindFile in 
LinksUpdateHookHandler::getScore return something.
+               RepoGroup::setSingleton( $this->getRepoGroup() );
+               $linksUpdate = $this->getLinksUpdate();
+
+               LinksUpdateHookHandler::onLinksUpdate( $linksUpdate );
+
                $this->assertTrue( true, 'no errors in getMetadata' );
        }
+
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/276479
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I9acaadf18e859758cd7bdcb7d260007402695060
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/PageImages
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: Gergő Tisza <[email protected]>
Gerrit-Reviewer: Hoo man <[email protected]>
Gerrit-Reviewer: MaxSem <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to