2015-11-16 15:40:07 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace PageImages\Tests\Hooks;
|
|
|
|
|
2020-03-31 17:24:33 +00:00
|
|
|
use AbstractContent;
|
|
|
|
use File;
|
2016-03-10 15:27:40 +00:00
|
|
|
use LinksUpdate;
|
2020-03-04 03:05:44 +00:00
|
|
|
use MediaWiki\Revision\RevisionRecord;
|
2020-01-14 08:47:58 +00:00
|
|
|
use MediaWikiTestCase;
|
2016-11-10 00:02:00 +00:00
|
|
|
use PageImages\Hooks\LinksUpdateHookHandler;
|
2020-10-22 20:04:23 +00:00
|
|
|
use PageImages\PageImageCandidate;
|
2020-04-19 22:41:19 +00:00
|
|
|
use PageImages\PageImages;
|
2015-11-16 15:40:07 +00:00
|
|
|
use ParserOutput;
|
2016-03-07 22:48:15 +00:00
|
|
|
use RepoGroup;
|
2016-12-06 01:19:06 +00:00
|
|
|
use Title;
|
2017-04-20 07:48:48 +00:00
|
|
|
use Wikimedia\TestingAccessWrapper;
|
2015-11-16 15:40:07 +00:00
|
|
|
|
|
|
|
/**
|
2017-12-27 19:25:59 +00:00
|
|
|
* @covers \PageImages\Hooks\LinksUpdateHookHandler
|
2015-11-16 15:40:07 +00:00
|
|
|
*
|
|
|
|
* @group PageImages
|
|
|
|
*
|
2018-05-25 04:42:29 +00:00
|
|
|
* @license WTFPL
|
2017-11-24 07:33:49 +00:00
|
|
|
* @author Thiemo Kreuz
|
2015-11-16 15:40:07 +00:00
|
|
|
*/
|
2016-12-06 01:19:06 +00:00
|
|
|
class LinksUpdateHookHandlerTest extends MediaWikiTestCase {
|
2015-11-16 15:40:07 +00:00
|
|
|
|
2019-10-11 18:05:53 +00:00
|
|
|
public function setUp() : void {
|
2017-04-16 01:26:58 +00:00
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
// Force LinksUpdateHookHandler::getPageImageCanditates to look at all
|
|
|
|
// sections.
|
|
|
|
$this->setMwGlobals( 'wgPageImagesLeadSectionOnly', false );
|
|
|
|
}
|
|
|
|
|
2016-03-10 15:27:40 +00:00
|
|
|
/**
|
2017-11-23 16:06:51 +00:00
|
|
|
* @param array[] $images
|
|
|
|
* @param array[]|bool $leadImages
|
|
|
|
*
|
2016-03-10 15:27:40 +00:00
|
|
|
* @return LinksUpdate
|
|
|
|
*/
|
2016-12-06 01:19:06 +00:00
|
|
|
private function getLinksUpdate( array $images, $leadImages = false ) {
|
2015-11-16 15:40:07 +00:00
|
|
|
$parserOutput = new ParserOutput();
|
2016-11-10 00:02:00 +00:00
|
|
|
$parserOutput->setExtensionData( 'pageImages', $images );
|
2016-12-06 01:19:06 +00:00
|
|
|
$parserOutputLead = new ParserOutput();
|
2018-04-14 05:20:54 +00:00
|
|
|
$parserOutputLead->setExtensionData( 'pageImages', $leadImages ?: $images );
|
2016-12-06 01:19:06 +00:00
|
|
|
|
2020-03-31 17:24:33 +00:00
|
|
|
$sectionContent = $this->getMockBuilder( AbstractContent::class )
|
2016-12-06 01:19:06 +00:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
|
2021-05-04 14:48:45 +00:00
|
|
|
$sectionContent->method( 'getParserOutput' )
|
2021-03-20 05:22:04 +00:00
|
|
|
->willReturn( $parserOutputLead );
|
2020-03-04 03:05:44 +00:00
|
|
|
|
2020-03-31 17:24:33 +00:00
|
|
|
$content = $this->getMockBuilder( AbstractContent::class )
|
2016-12-06 01:19:06 +00:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
|
2021-05-04 14:48:45 +00:00
|
|
|
$content->method( 'getSection' )
|
2021-03-20 05:22:04 +00:00
|
|
|
->willReturn( $sectionContent );
|
2020-03-04 03:05:44 +00:00
|
|
|
|
|
|
|
$revRecord = $this->getMockBuilder( RevisionRecord::class )
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
|
2021-05-04 14:48:45 +00:00
|
|
|
$revRecord->method( 'getContent' )
|
2021-03-20 05:22:04 +00:00
|
|
|
->willReturn( $content );
|
2020-03-04 03:05:44 +00:00
|
|
|
|
2020-03-31 17:24:33 +00:00
|
|
|
$linksUpdate = $this->getMockBuilder( LinksUpdate::class )
|
2015-11-16 15:40:07 +00:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2016-12-06 01:19:06 +00:00
|
|
|
|
2021-05-04 14:48:45 +00:00
|
|
|
$linksUpdate->method( 'getTitle' )
|
2021-03-20 05:22:04 +00:00
|
|
|
->willReturn( $this->createMock( Title::class ) );
|
2016-12-06 01:19:06 +00:00
|
|
|
|
2021-05-04 14:48:45 +00:00
|
|
|
$linksUpdate->method( 'getParserOutput' )
|
2021-03-20 05:22:04 +00:00
|
|
|
->willReturn( $parserOutput );
|
2015-11-16 15:40:07 +00:00
|
|
|
|
2021-05-04 14:48:45 +00:00
|
|
|
$linksUpdate->method( 'getRevisionRecord' )
|
2021-03-20 05:22:04 +00:00
|
|
|
->willReturn( $revRecord );
|
2016-12-06 01:19:06 +00:00
|
|
|
|
2016-03-10 15:27:40 +00:00
|
|
|
return $linksUpdate;
|
2015-11-16 15:40:07 +00:00
|
|
|
}
|
|
|
|
|
2016-03-10 15:27:40 +00:00
|
|
|
/**
|
2020-03-31 17:24:33 +00:00
|
|
|
* Required to make RepoGroup::findFile in LinksUpdateHookHandler::getScore return something.
|
2016-03-10 15:27:40 +00:00
|
|
|
* @return RepoGroup
|
|
|
|
*/
|
|
|
|
private function getRepoGroup() {
|
2020-03-31 17:24:33 +00:00
|
|
|
$file = $this->getMockBuilder( File::class )
|
2016-03-07 22:48:15 +00:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
// ugly hack to avoid all the unmockable crap in FormatMetadata
|
2021-05-04 14:48:45 +00:00
|
|
|
$file->method( 'isDeleted' )
|
2021-03-20 05:22:04 +00:00
|
|
|
->willReturn( true );
|
2016-03-07 22:48:15 +00:00
|
|
|
|
2020-03-31 17:24:33 +00:00
|
|
|
$repoGroup = $this->getMockBuilder( RepoGroup::class )
|
2016-03-07 22:48:15 +00:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2021-05-04 14:48:45 +00:00
|
|
|
$repoGroup->method( 'findFile' )
|
2021-03-20 05:22:04 +00:00
|
|
|
->willReturn( $file );
|
2016-03-07 22:48:15 +00:00
|
|
|
|
2016-03-10 15:27:40 +00:00
|
|
|
return $repoGroup;
|
|
|
|
}
|
2016-03-07 22:48:15 +00:00
|
|
|
|
2016-11-10 00:02:00 +00:00
|
|
|
/**
|
|
|
|
* @dataProvider provideDoLinksUpdate
|
2017-12-27 19:25:59 +00:00
|
|
|
* @covers \PageImages\Hooks\LinksUpdateHookHandler::doLinksUpdate
|
2016-11-10 00:02:00 +00:00
|
|
|
*/
|
2017-05-30 20:36:57 +00:00
|
|
|
public function testDoLinksUpdate(
|
|
|
|
array $images,
|
|
|
|
$expectedFreeFileName,
|
|
|
|
$expectedNonFreeFileName
|
|
|
|
) {
|
2016-11-10 00:02:00 +00:00
|
|
|
$linksUpdate = $this->getLinksUpdate( $images );
|
|
|
|
$mock = TestingAccessWrapper::newFromObject(
|
|
|
|
$this->getMockBuilder( LinksUpdateHookHandler::class )
|
2021-05-12 09:23:38 +00:00
|
|
|
->onlyMethods( [ 'getScore', 'isImageFree' ] )
|
2016-11-10 00:02:00 +00:00
|
|
|
->getMock()
|
|
|
|
);
|
|
|
|
|
|
|
|
$isFreeMap = [];
|
|
|
|
foreach ( $images as $image ) {
|
2016-12-02 00:49:13 +00:00
|
|
|
array_push( $isFreeMap, [ $image['filename'], $image['isFree'] ] );
|
2016-11-10 00:02:00 +00:00
|
|
|
}
|
|
|
|
|
2021-05-04 14:48:45 +00:00
|
|
|
$mock->method( 'getScore' )
|
2021-03-20 05:22:04 +00:00
|
|
|
->willReturnCallback(
|
2021-05-12 09:23:38 +00:00
|
|
|
static function ( PageImageCandidate $_, $position ) use ( $images ) {
|
2021-03-20 05:22:04 +00:00
|
|
|
return $images[$position]['score'];
|
|
|
|
}
|
|
|
|
);
|
2016-11-10 00:02:00 +00:00
|
|
|
|
2021-05-04 14:48:45 +00:00
|
|
|
$mock->method( 'isImageFree' )
|
2021-03-20 05:22:04 +00:00
|
|
|
->willReturnMap( $isFreeMap );
|
2016-03-10 15:27:40 +00:00
|
|
|
|
2016-11-10 00:02:00 +00:00
|
|
|
$mock->doLinksUpdate( $linksUpdate );
|
2016-03-10 15:27:40 +00:00
|
|
|
|
|
|
|
$this->assertTrue( property_exists( $linksUpdate, 'mProperties' ), 'precondition' );
|
2020-01-14 08:47:58 +00:00
|
|
|
if ( $expectedFreeFileName === null ) {
|
2017-05-30 20:36:57 +00:00
|
|
|
$this->assertArrayNotHasKey( PageImages::PROP_NAME_FREE, $linksUpdate->mProperties );
|
2016-11-10 00:02:00 +00:00
|
|
|
} else {
|
2017-05-30 19:49:44 +00:00
|
|
|
$this->assertSame( $expectedFreeFileName,
|
|
|
|
$linksUpdate->mProperties[PageImages::PROP_NAME_FREE] );
|
2016-11-10 00:02:00 +00:00
|
|
|
}
|
2020-01-14 08:47:58 +00:00
|
|
|
if ( $expectedNonFreeFileName === null ) {
|
2017-05-30 20:36:57 +00:00
|
|
|
$this->assertArrayNotHasKey( PageImages::PROP_NAME, $linksUpdate->mProperties );
|
2016-11-10 00:02:00 +00:00
|
|
|
} else {
|
|
|
|
$this->assertSame( $expectedNonFreeFileName, $linksUpdate->mProperties[PageImages::PROP_NAME] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function provideDoLinksUpdate() {
|
|
|
|
return [
|
|
|
|
// both images are non-free
|
|
|
|
[
|
|
|
|
[
|
|
|
|
[ 'filename' => 'A.jpg', 'score' => 100, 'isFree' => false ],
|
|
|
|
[ 'filename' => 'B.jpg', 'score' => 90, 'isFree' => false ],
|
|
|
|
],
|
|
|
|
null,
|
|
|
|
'A.jpg'
|
|
|
|
],
|
|
|
|
// both images are free
|
|
|
|
[
|
|
|
|
[
|
|
|
|
[ 'filename' => 'A.jpg', 'score' => 100, 'isFree' => true ],
|
|
|
|
[ 'filename' => 'B.jpg', 'score' => 90, 'isFree' => true ],
|
|
|
|
],
|
|
|
|
'A.jpg',
|
|
|
|
null
|
|
|
|
],
|
|
|
|
// one free (with a higher score), one non-free image
|
|
|
|
[
|
|
|
|
[
|
|
|
|
[ 'filename' => 'A.jpg', 'score' => 100, 'isFree' => true ],
|
|
|
|
[ 'filename' => 'B.jpg', 'score' => 90, 'isFree' => false ],
|
|
|
|
],
|
|
|
|
'A.jpg',
|
|
|
|
null
|
|
|
|
],
|
|
|
|
// one non-free (with a higher score), one free image
|
|
|
|
[
|
|
|
|
[
|
|
|
|
[ 'filename' => 'A.jpg', 'score' => 100, 'isFree' => false ],
|
|
|
|
[ 'filename' => 'B.jpg', 'score' => 90, 'isFree' => true ],
|
|
|
|
],
|
|
|
|
'B.jpg',
|
|
|
|
'A.jpg'
|
|
|
|
]
|
|
|
|
];
|
2016-03-10 15:27:40 +00:00
|
|
|
}
|
|
|
|
|
2016-12-06 01:19:06 +00:00
|
|
|
/**
|
2017-12-27 19:25:59 +00:00
|
|
|
* @covers \PageImages\Hooks\LinksUpdateHookHandler::getPageImageCandidates
|
2016-12-06 01:19:06 +00:00
|
|
|
*/
|
|
|
|
public function testGetPageImageCandidates() {
|
|
|
|
$candidates = [
|
2021-03-20 05:22:04 +00:00
|
|
|
[ 'filename' => 'A.jpg', 'score' => 100, 'isFree' => false ],
|
|
|
|
[ 'filename' => 'B.jpg', 'score' => 90, 'isFree' => false ],
|
2016-12-06 01:19:06 +00:00
|
|
|
];
|
|
|
|
$linksUpdate = $this->getLinksUpdate( $candidates, array_slice( $candidates, 0, 1 ) );
|
|
|
|
|
|
|
|
// should get without lead.
|
|
|
|
$handler = new LinksUpdateHookHandler();
|
|
|
|
$this->setMwGlobals( 'wgPageImagesLeadSectionOnly', false );
|
|
|
|
$images = $handler->getPageImageCandidates( $linksUpdate );
|
2018-04-14 05:20:54 +00:00
|
|
|
$this->assertCount( 2, $images, 'All images are returned.' );
|
2016-12-06 01:19:06 +00:00
|
|
|
|
|
|
|
$this->setMwGlobals( 'wgPageImagesLeadSectionOnly', true );
|
|
|
|
$images = $handler->getPageImageCandidates( $linksUpdate );
|
2018-04-14 05:20:54 +00:00
|
|
|
$this->assertCount( 1, $images, 'Only lead images are returned.' );
|
2016-12-06 01:19:06 +00:00
|
|
|
}
|
|
|
|
|
2016-11-16 21:29:03 +00:00
|
|
|
/**
|
|
|
|
* @dataProvider provideGetScore
|
|
|
|
*/
|
2016-11-10 00:02:00 +00:00
|
|
|
public function testGetScore( $image, $scoreFromTable, $position, $expected ) {
|
|
|
|
$mock = TestingAccessWrapper::newFromObject(
|
|
|
|
$this->getMockBuilder( LinksUpdateHookHandler::class )
|
2021-05-12 09:23:38 +00:00
|
|
|
->onlyMethods( [ 'scoreFromTable', 'fetchFileMetadata', 'getRatio', 'getDenylist' ] )
|
2016-11-10 00:02:00 +00:00
|
|
|
->getMock()
|
|
|
|
);
|
2021-05-04 14:48:45 +00:00
|
|
|
$mock->method( 'scoreFromTable' )
|
2021-03-20 05:22:04 +00:00
|
|
|
->willReturn( $scoreFromTable );
|
2021-05-04 14:48:45 +00:00
|
|
|
$mock->method( 'getRatio' )
|
2021-03-20 05:22:04 +00:00
|
|
|
->willReturn( 0 );
|
2021-05-07 20:19:07 +00:00
|
|
|
$mock->method( 'getDenylist' )
|
|
|
|
->willReturn( [ 'denylisted.jpg' => 1 ] );
|
2016-11-16 21:29:03 +00:00
|
|
|
|
2020-10-22 20:04:23 +00:00
|
|
|
$score = $mock->getScore( PageImageCandidate::newFromArray( $image ), $position );
|
2021-05-04 14:48:45 +00:00
|
|
|
$this->assertSame( $expected, $score );
|
2016-11-16 21:29:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function provideGetScore() {
|
|
|
|
return [
|
|
|
|
[
|
2016-12-02 00:49:13 +00:00
|
|
|
[ 'filename' => 'A.jpg', 'handler' => [ 'width' => 100 ] ],
|
2016-11-16 21:29:03 +00:00
|
|
|
100,
|
|
|
|
0,
|
|
|
|
// width score + ratio score + position score
|
|
|
|
100 + 100 + 8
|
|
|
|
],
|
|
|
|
[
|
2016-12-02 00:49:13 +00:00
|
|
|
[ 'filename' => 'A.jpg', 'fullwidth' => 100 ],
|
2016-11-16 21:29:03 +00:00
|
|
|
50,
|
|
|
|
1,
|
|
|
|
// width score + ratio score + position score
|
|
|
|
106
|
|
|
|
],
|
|
|
|
[
|
2016-12-02 00:49:13 +00:00
|
|
|
[ 'filename' => 'A.jpg', 'fullwidth' => 100 ],
|
2016-11-16 21:29:03 +00:00
|
|
|
50,
|
|
|
|
2,
|
|
|
|
// width score + ratio score + position score
|
|
|
|
104
|
|
|
|
],
|
|
|
|
[
|
2016-12-02 00:49:13 +00:00
|
|
|
[ 'filename' => 'A.jpg', 'fullwidth' => 100 ],
|
2016-11-16 21:29:03 +00:00
|
|
|
50,
|
|
|
|
3,
|
|
|
|
// width score + ratio score + position score
|
|
|
|
103
|
|
|
|
],
|
|
|
|
[
|
2021-05-07 20:19:07 +00:00
|
|
|
[ 'filename' => 'denylisted.jpg', 'fullwidth' => 100 ],
|
2016-11-16 21:29:03 +00:00
|
|
|
50,
|
|
|
|
3,
|
2021-05-07 20:19:07 +00:00
|
|
|
// denylist score
|
2017-08-11 04:15:33 +00:00
|
|
|
- 1000
|
2016-11-16 21:29:03 +00:00
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider provideScoreFromTable
|
2017-12-27 19:25:59 +00:00
|
|
|
* @covers \PageImages\Hooks\LinksUpdateHookHandler::scoreFromTable
|
2016-11-16 21:29:03 +00:00
|
|
|
*/
|
2019-01-09 10:42:44 +00:00
|
|
|
public function testScoreFromTable( array $scores, $value, $expected ) {
|
2021-05-04 14:51:18 +00:00
|
|
|
/** @var LinksUpdateHookHandler $handlerWrapper */
|
2016-11-10 00:02:00 +00:00
|
|
|
$handlerWrapper = TestingAccessWrapper::newFromObject( new LinksUpdateHookHandler );
|
2016-11-16 21:29:03 +00:00
|
|
|
|
2019-01-09 10:42:44 +00:00
|
|
|
$score = $handlerWrapper->scoreFromTable( $value, $scores );
|
2016-11-16 21:29:03 +00:00
|
|
|
$this->assertEquals( $expected, $score );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function provideScoreFromTable() {
|
2019-01-09 10:42:44 +00:00
|
|
|
global $wgPageImagesScores;
|
|
|
|
|
2016-11-16 21:29:03 +00:00
|
|
|
return [
|
2019-01-09 10:42:44 +00:00
|
|
|
'no match' => [ [], 100, 0 ],
|
2019-01-09 10:49:50 +00:00
|
|
|
'float' => [ [ 0.5 ], 0, 0.5 ],
|
2019-01-09 10:42:44 +00:00
|
|
|
|
|
|
|
'always min when below range' => [ [ 200 => 2, 800 => 1 ], 0, 2 ],
|
|
|
|
'always max when above range' => [ [ 200 => 2, 800 => 1 ], 1000, 1 ],
|
|
|
|
|
|
|
|
'always min when below range (reversed)' => [ [ 800 => 1, 200 => 2 ], 0, 2 ],
|
|
|
|
'always max when above range (reversed)' => [ [ 800 => 1, 200 => 2 ], 1000, 1 ],
|
|
|
|
|
|
|
|
'min match' => [ [ 200 => 2, 400 => 3, 800 => 1 ], 200, 2 ],
|
|
|
|
'above min' => [ [ 200 => 2, 400 => 3, 800 => 1 ], 201, 3 ],
|
|
|
|
'second last match' => [ [ 200 => 2, 400 => 3, 800 => 1 ], 400, 3 ],
|
|
|
|
'above second last' => [ [ 200 => 2, 400 => 3, 800 => 1 ], 401, 1 ],
|
|
|
|
|
|
|
|
// These test cases use the default values from extension.json
|
|
|
|
[ $wgPageImagesScores['width'], 100, -100 ],
|
|
|
|
[ $wgPageImagesScores['width'], 119, -100 ],
|
|
|
|
[ $wgPageImagesScores['width'], 300, 10 ],
|
|
|
|
[ $wgPageImagesScores['width'], 400, 10 ],
|
|
|
|
[ $wgPageImagesScores['width'], 500, 5 ],
|
|
|
|
[ $wgPageImagesScores['width'], 600, 5 ],
|
|
|
|
[ $wgPageImagesScores['width'], 601, 0 ],
|
|
|
|
[ $wgPageImagesScores['width'], 999, 0 ],
|
|
|
|
[ $wgPageImagesScores['galleryImageWidth'], 99, -100 ],
|
|
|
|
[ $wgPageImagesScores['galleryImageWidth'], 100, 0 ],
|
|
|
|
[ $wgPageImagesScores['galleryImageWidth'], 500, 0 ],
|
|
|
|
[ $wgPageImagesScores['ratio'], 1, -100 ],
|
|
|
|
[ $wgPageImagesScores['ratio'], 3, -100 ],
|
|
|
|
[ $wgPageImagesScores['ratio'], 4, 0 ],
|
|
|
|
[ $wgPageImagesScores['ratio'], 5, 0 ],
|
|
|
|
[ $wgPageImagesScores['ratio'], 10, 5 ],
|
|
|
|
[ $wgPageImagesScores['ratio'], 20, 5 ],
|
|
|
|
[ $wgPageImagesScores['ratio'], 25, 0 ],
|
|
|
|
[ $wgPageImagesScores['ratio'], 30, 0 ],
|
|
|
|
[ $wgPageImagesScores['ratio'], 31, -100 ],
|
|
|
|
[ $wgPageImagesScores['ratio'], 40, -100 ],
|
|
|
|
|
|
|
|
'T212013' => [ $wgPageImagesScores['width'], 0, -100 ],
|
2016-11-16 21:29:03 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2016-11-10 00:02:00 +00:00
|
|
|
/**
|
|
|
|
* @dataProvider provideIsFreeImage
|
2017-12-27 19:25:59 +00:00
|
|
|
* @covers \PageImages\Hooks\LinksUpdateHookHandler::isImageFree
|
2016-11-10 00:02:00 +00:00
|
|
|
*/
|
|
|
|
public function testIsFreeImage( $fileName, $metadata, $expected ) {
|
2020-03-31 17:24:33 +00:00
|
|
|
$this->overrideMwServices( null, [
|
|
|
|
'RepoGroup' => function () {
|
|
|
|
return $this->getRepoGroup();
|
|
|
|
}
|
|
|
|
] );
|
|
|
|
|
2016-11-10 00:02:00 +00:00
|
|
|
$mock = TestingAccessWrapper::newFromObject(
|
|
|
|
$this->getMockBuilder( LinksUpdateHookHandler::class )
|
2021-05-12 09:23:38 +00:00
|
|
|
->onlyMethods( [ 'fetchFileMetadata' ] )
|
2016-11-10 00:02:00 +00:00
|
|
|
->getMock()
|
|
|
|
);
|
2021-05-04 14:48:45 +00:00
|
|
|
$mock->method( 'fetchFileMetadata' )
|
2021-03-20 05:22:04 +00:00
|
|
|
->willReturn( $metadata );
|
2021-05-04 14:48:45 +00:00
|
|
|
/** @var LinksUpdateHookHandler $mock */
|
|
|
|
$this->assertSame( $expected, $mock->isImageFree( $fileName ) );
|
2016-03-07 22:48:15 +00:00
|
|
|
}
|
2016-03-10 15:27:40 +00:00
|
|
|
|
2016-11-10 00:02:00 +00:00
|
|
|
public function provideIsFreeImage() {
|
|
|
|
return [
|
2016-12-02 00:49:13 +00:00
|
|
|
[ 'A.jpg', [], true ],
|
|
|
|
[ 'A.jpg', [ 'NonFree' => [ 'value' => '0' ] ], true ],
|
|
|
|
[ 'A.jpg', [ 'NonFree' => [ 'value' => 0 ] ], true ],
|
|
|
|
[ 'A.jpg', [ 'NonFree' => [ 'value' => false ] ], true ],
|
|
|
|
[ 'A.jpg', [ 'NonFree' => [ 'value' => 'something' ] ], false ],
|
|
|
|
[ 'A.jpg', [ 'something' => [ 'value' => 'something' ] ], true ],
|
2016-11-10 00:02:00 +00:00
|
|
|
];
|
|
|
|
}
|
2015-11-16 15:40:07 +00:00
|
|
|
}
|