Debian Codegraph @

tests/phpunit/includes/media/JpegPixelFormatTest.php

raw symbols SCIP
1 <?php
2
3 use MediaWiki\MainConfigNames;
4 use MediaWiki\Shell\Shell;
5
6 /**
7 * Tests related to JPEG chroma subsampling via $wgJpegPixelFormat setting.
8 *
9 * @group Media
10 * @group medium
11 */
12 class JpegPixelFormatTest extends MediaWikiMediaTestCase {
13
14 /**
15 * Mark this test as creating thumbnail files.
16 * @inheritDoc
17 */
18 protected function createsThumbnails() {
19 return true;
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->overrideConfigValue( MainConfigNames::JpegPixelFormat, $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->assertIsString( $path, "path returned for JPEG thumbnail for $fmtStr" );
48
49 $result = Shell::command( 'identify',
50 '-format',
51 '%[jpeg:sampling-factor]',
52 $path
53 )->execute();
54 $this->assertSame( 0,
55 $result->getExitCode(),
56 "ImageMagick's identify command should return success"
57 );
58
59 $expected = $samplingFactor;
60 $actual = trim( $result->getStdout() );
61 $this->assertEquals(
62 $expected,
63 $actual,
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 }