Page MenuHomeWickedGov Phorge

PageImageCandidateTest.php
No OneTemporary

Size
2 KB
Referenced Files
None
Subscribers
None

PageImageCandidateTest.php

<?php
namespace MediaWiki\Tests\PageImages;
use File;
use MediaWiki\Title\Title;
use MediaWikiUnitTestCase;
use PageImages\PageImageCandidate;
/**
* @covers \PageImages\PageImageCandidate
* @package MediaWiki\Tests\PageImages
*/
class PageImageCandidateTest extends MediaWikiUnitTestCase {
/**
* @param int|bool $width
* @param int|bool $height
* @return File
*/
private function fileMock( $width, $height ): File {
$title = $this->createMock( Title::class );
$title->method( 'getDBKey' )->willReturn( 'Testing' );
$file = $this->createMock( File::class );
$file->method( 'getTitle' )->willReturn( $title );
$file->method( 'getWidth' )->willReturn( $width );
$file->method( 'getHeight' )->willReturn( $height );
return $file;
}
public static function provideTestCases() {
yield 'file no width, no height' => [
false, false,
[], 'Testing', 0, 0, 0
];
yield 'file with width and height' => [
42, 24,
[], 'Testing', 42, 24, 0
];
yield 'file with width and height, handler, no width' => [
42, 24,
[ 'handler' => [] ], 'Testing', 42, 24, 0
];
yield 'file with width and height, handler, with width' => [
42, 24,
[ 'handler' => [ 'width' => 4224 ] ], 'Testing', 42, 24, 4224
];
}
/**
* @dataProvider provideTestCases
* @param int|false $mockWidth
* @param int|false $mockHeight
* @param array $params
* @param string $expectedName
* @param int $expectedWidth
* @param int $expectedHeight
* @param int $expectedHandlerWidth
*/
public function testNewFromFileAndParams(
$mockWidth,
$mockHeight,
array $params,
string $expectedName,
int $expectedWidth,
int $expectedHeight,
int $expectedHandlerWidth
) {
$file = $this->fileMock( $mockWidth, $mockHeight );
$image = PageImageCandidate::newFromFileAndParams( $file, $params );
$this->assertSame( $expectedName, $image->getFileName() );
$this->assertSame( $expectedWidth, $image->getFullWidth() );
$this->assertSame( $expectedHeight, $image->getFullHeight() );
$this->assertSame( $expectedHandlerWidth, $image->getHandlerWidth() );
}
/**
* @dataProvider provideTestCases
* @param int|false $mockWidth
* @param int|false $mockHeight
* @param array $params
*/
public function testSerializeDeserialize( $mockWidth, $mockHeight, array $params ) {
$file = $this->fileMock( $mockWidth, $mockHeight );
$candidate = PageImageCandidate::newFromFileAndParams( $file, $params );
$deserialized = PageImageCandidate::newFromArray( $candidate->jsonSerialize() );
$this->assertSame( $candidate->getFileName(), $deserialized->getFileName() );
$this->assertSame( $candidate->getFullHeight(), $deserialized->getFullHeight() );
$this->assertSame( $candidate->getFullHeight(), $deserialized->getFullHeight() );
$this->assertSame( $candidate->getHandlerWidth(), $deserialized->getHandlerWidth() );
}
}

File Metadata

Mime Type
text/x-php
Expires
Sat, Oct 3, 23:27 (2 w, 2 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
4e/db/7b9e72bcae071000b34da3959335
Default Alt Text
PageImageCandidateTest.php (2 KB)

Event Timeline