mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/PageImages
synced 2024-11-15 03:43:46 +00:00
Add sanity check test for LinksUpdateHookHandler::getMetadata
Change-Id: I840902c8397c8442def8239504ce1cfa8eafbb8e
This commit is contained in:
parent
4fee70fc1f
commit
151a5d7248
|
@ -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' );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue