|
| 1 | +<?php |
| 2 | + |
| 3 | +declare( strict_types = 1 ); |
| 4 | + |
| 5 | +namespace Wikibase\LocalMedia\Tests\Integration; |
| 6 | + |
| 7 | +use DataValues\StringValue; |
| 8 | +use File; |
| 9 | +use MediaWiki\MainConfigNames; |
| 10 | +use MediaWikiIntegrationTestCase; |
| 11 | +use ParserOptions; |
| 12 | +use RepoGroup; |
| 13 | +use Wikibase\LocalMedia\Services\InlineImageFormatter; |
| 14 | +use Wikibase\LocalMedia\Services\LocalImageLinker; |
| 15 | + |
| 16 | +/** |
| 17 | + * @covers \Wikibase\LocalMedia\Services\InlineImageFormatter |
| 18 | + */ |
| 19 | +class InlineImageFormatterTest extends MediaWikiIntegrationTestCase { |
| 20 | + |
| 21 | + public function testFileMetadataIncludesDimensions(): void { |
| 22 | + $this->overrideConfigValue( MainConfigNames::ResponsiveImages, false ); |
| 23 | + $this->setService( 'RepoGroup', $this->newRepoGroupFindingFile() ); |
| 24 | + |
| 25 | + $html = $this->newFormatter()->format( new StringValue( 'Jonas-revenge.png' ) ); |
| 26 | + |
| 27 | + $this->assertStringContainsString( '800 × 600 pixels', $html ); |
| 28 | + } |
| 29 | + |
| 30 | + private function newRepoGroupFindingFile(): RepoGroup { |
| 31 | + $file = $this->createStub( File::class ); |
| 32 | + $file->method( 'transform' )->willReturn( $this->newThumbnail() ); |
| 33 | + $file->method( 'getDimensionsString' )->willReturn( '800 × 600 pixels' ); |
| 34 | + $file->method( 'getSize' )->willReturn( 12345 ); |
| 35 | + |
| 36 | + $repoGroup = $this->createStub( RepoGroup::class ); |
| 37 | + $repoGroup->method( 'findFile' )->willReturn( $file ); |
| 38 | + |
| 39 | + return $repoGroup; |
| 40 | + } |
| 41 | + |
| 42 | + private function newThumbnail(): object { |
| 43 | + return new class { |
| 44 | + public function toHtml(): string { |
| 45 | + return '<img src="thumbnail.png">'; |
| 46 | + } |
| 47 | + }; |
| 48 | + } |
| 49 | + |
| 50 | + private function newFormatter(): InlineImageFormatter { |
| 51 | + return new InlineImageFormatter( |
| 52 | + ParserOptions::newFromAnon(), |
| 53 | + [], |
| 54 | + 'en', |
| 55 | + new LocalImageLinker(), |
| 56 | + 'commons-media-caption' |
| 57 | + ); |
| 58 | + } |
| 59 | + |
| 60 | +} |
0 commit comments