MediaWiki  REL1_31
JpegPixelFormatTest.php
Go to the documentation of this file.
1 <?php
11 
12  protected function setUp() {
13  parent::setUp();
14  }
15 
19  protected function createsThumbnails() {
20  return true;
21  }
22 
27  public function testPixelFormatRendering( $sourceFile, $pixelFormat, $samplingFactor ) {
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 }
JpegPixelFormatTest
Tests related to JPEG chroma subsampling via $wgJpegPixelFormat setting.
Definition: JpegPixelFormatTest.php:10
$output
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title after the basic globals have been set but before ordinary actions take place $output
Definition: hooks.txt:2255
File\RENDER_FORCE
const RENDER_FORCE
Force rendering even if thumbnail already exist and using RENDER_NOW I.e.
Definition: File.php:64
$params
$params
Definition: styleTest.css.php:40
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:37
MediaWikiMediaTestCase
Specificly for testing Media handlers.
Definition: MediaWikiMediaTestCase.php:5
$wgUseImageMagick
$wgUseImageMagick
Resizing can be done using PHP's internal image libraries or using ImageMagick or another third-party...
Definition: DefaultSettings.php:1038
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
Definition: MediaWikiTestCase.php:678
MediaWikiMediaTestCase\dataFile
dataFile( $name, $type=null)
Utility function: Get a new file object for a file on disk but not actually in db.
Definition: MediaWikiMediaTestCase.php:76
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:95
JpegPixelFormatTest\setUp
setUp()
Definition: JpegPixelFormatTest.php:12
JpegPixelFormatTest\createsThumbnails
createsThumbnails()
Mark this test as creating thumbnail files.
Definition: JpegPixelFormatTest.php:19
File\RENDER_NOW
const RENDER_NOW
Force rendering in the current process.
Definition: File.php:59
$path
$path
Definition: NoLocalSettings.php:25
JpegPixelFormatTest\testPixelFormatRendering
testPixelFormatRendering( $sourceFile, $pixelFormat, $samplingFactor)
providePixelFormats
Definition: JpegPixelFormatTest.php:27
$wgUseImageResize
$wgUseImageResize
Whether to enable server-side image thumbnailing.
Definition: DefaultSettings.php:1028
$retval
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account incomplete not yet checked for validity & $retval
Definition: hooks.txt:266
JpegPixelFormatTest\providePixelFormats
static providePixelFormats()
Definition: JpegPixelFormatTest.php:69
wfShellExec
wfShellExec( $cmd, &$retval=null, $environ=[], $limits=[], $options=[])
Execute a shell command, with time and memory limits mirrored from the PHP configuration if supported...
Definition: GlobalFunctions.php:2250