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