diff --git a/tests/phpunit/LinksUpdateHookHandlerTest.php b/tests/phpunit/LinksUpdateHookHandlerTest.php index 40bda08..e25e8bd 100644 --- a/tests/phpunit/LinksUpdateHookHandlerTest.php +++ b/tests/phpunit/LinksUpdateHookHandlerTest.php @@ -6,6 +6,7 @@ use PageImages\Hooks\LinksUpdateHookHandler; use PageImages; use ParserOutput; use PHPUnit_Framework_TestCase; +use RepoGroup; /** * @covers PageImages\Hooks\LinksUpdateHookHandler @@ -17,6 +18,12 @@ use PHPUnit_Framework_TestCase; */ class LinksUpdateHookHandlerTest extends PHPUnit_Framework_TestCase { + public function tearDown() { + // remove mock added in testGetMetadata() + RepoGroup::destroySingleton(); + parent::tearDown(); + } + public function testOnLinksUpdate() { $parserOutput = new ParserOutput(); $parserOutput->setExtensionData( 'pageImages', array( @@ -35,4 +42,36 @@ class LinksUpdateHookHandlerTest extends PHPUnit_Framework_TestCase { $this->assertSame( 'A.jpg', $linksUpdate->mProperties[PageImages::PROP_NAME] ); } + public function testGetMetadata() { + $file = $this->getMockBuilder( 'File' ) + ->disableOriginalConstructor() + ->getMock(); + // ugly hack to avoid all the unmockable crap in FormatMetadata + $file->expects( $this->any() ) + ->method( 'isDeleted' ) + ->will( $this->returnValue( true ) ); + + $mockRepoGroup = $this->getMockBuilder( 'RepoGroup' ) + ->disableOriginalConstructor() + ->getMock(); + $mockRepoGroup->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 ), + ) ); + + $linksUpdate = $this->getMockBuilder( 'LinksUpdate' ) + ->disableOriginalConstructor() + ->getMock(); + $linksUpdate->expects( $this->any() ) + ->method( 'getParserOutput' ) + ->will( $this->returnValue( $parserOutput ) ); + + LinksUpdateHookHandler::onLinksUpdate( $linksUpdate ); + $this->assertTrue( true, 'no errors in getMetadata' ); + } }