Add missing @covers to media related tests
[lhc/web/wiklou.git] / tests / phpunit / includes / media / JpegPixelFormatTest.php
1 <?php
2 /**
3 * Tests related to JPEG chroma subsampling via $wgJpegPixelFormat setting.
4 *
5 * @group Media
6 * @group medium
7 */
8 class JpegPixelFormatTest extends MediaWikiMediaTestCase {
9
10 protected function setUp() {
11 parent::setUp();
12 }
13
14 /**
15 * Mark this test as creating thumbnail files.
16 */
17 protected function createsThumbnails() {
18 return true;
19 }
20
21 /**
22 *
23 * @dataProvider providePixelFormats
24 * @covers BitmapHandler::imageMagickSubsampling
25 */
26 public function testPixelFormatRendering( $sourceFile, $pixelFormat, $samplingFactor ) {
27 global $wgUseImageMagick, $wgUseImageResize;
28 if ( !$wgUseImageMagick ) {
29 $this->markTestSkipped( "This test is only applicable when using ImageMagick thumbnailing" );
30 }
31 if ( !$wgUseImageResize ) {
32 $this->markTestSkipped( "This test is only applicable when using thumbnailing" );
33 }
34
35 $fmtStr = var_export( $pixelFormat, true );
36 $this->setMwGlobals( 'wgJpegPixelFormat', $pixelFormat );
37
38 $file = $this->dataFile( $sourceFile, 'image/jpeg' );
39
40 $params = [
41 'width' => 320,
42 ];
43 $thumb = $file->transform( $params, File::RENDER_NOW | File::RENDER_FORCE );
44 $this->assertTrue( !$thumb->isError(), "created JPEG thumbnail for pixel format $fmtStr" );
45
46 $path = $thumb->getLocalCopyPath();
47 $this->assertTrue( is_string( $path ), "path returned for JPEG thumbnail for $fmtStr" );
48
49 $cmd = [
50 'identify',
51 '-format',
52 '%[jpeg:sampling-factor]',
53 $path
54 ];
55 $retval = null;
56 $output = wfShellExec( $cmd, $retval );
57 $this->assertTrue( $retval === 0, "ImageMagick's identify command should return success" );
58
59 $expected = $samplingFactor;
60 $actual = trim( $output );
61 $this->assertEquals(
62 $expected,
63 trim( $output ),
64 "IM identify expects JPEG chroma subsampling \"$expected\" for $fmtStr"
65 );
66 }
67
68 public static function providePixelFormats() {
69 return [
70 // From 4:4:4 source file
71 [
72 'yuv444.jpg',
73 false,
74 '1x1,1x1,1x1'
75 ],
76 [
77 'yuv444.jpg',
78 'yuv444',
79 '1x1,1x1,1x1'
80 ],
81 [
82 'yuv444.jpg',
83 'yuv422',
84 '2x1,1x1,1x1'
85 ],
86 [
87 'yuv444.jpg',
88 'yuv420',
89 '2x2,1x1,1x1'
90 ],
91 // From 4:2:0 source file
92 [
93 'yuv420.jpg',
94 false,
95 '2x2,1x1,1x1'
96 ],
97 [
98 'yuv420.jpg',
99 'yuv444',
100 '1x1,1x1,1x1'
101 ],
102 [
103 'yuv420.jpg',
104 'yuv422',
105 '2x1,1x1,1x1'
106 ],
107 [
108 'yuv420.jpg',
109 'yuv420',
110 '2x2,1x1,1x1'
111 ]
112 ];
113 }
114 }