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