MediaWiki  1.29.1
ResourceLoaderImageTest.php
Go to the documentation of this file.
1 <?php
2 
7 
8  protected $imagesPath;
9 
10  protected function setUp() {
11  parent::setUp();
12  $this->imagesPath = __DIR__ . '/../../data/resourceloader';
13  }
14 
15  protected function getTestImage( $name ) {
17  $fileDescriptor = is_string( $options ) ? $options : $options['file'];
18  $allowedVariants = is_array( $options ) &&
19  isset( $options['variants'] ) ? $options['variants'] : [];
20  $variants = array_fill_keys( $allowedVariants, [ 'color' => 'red' ] );
21  return new ResourceLoaderImageTestable(
22  $name,
23  'test',
24  $fileDescriptor,
25  $this->imagesPath,
26  $variants
27  );
28  }
29 
30  public static function provideGetPath() {
31  return [
32  [ 'add', 'en', 'add.gif' ],
33  [ 'add', 'he', 'add.gif' ],
34  [ 'remove', 'en', 'remove.svg' ],
35  [ 'remove', 'he', 'remove.svg' ],
36  [ 'next', 'en', 'next.svg' ],
37  [ 'next', 'he', 'prev.svg' ],
38  [ 'help', 'en', 'help-ltr.svg' ],
39  [ 'help', 'ar', 'help-rtl.svg' ],
40  [ 'help', 'he', 'help-ltr.svg' ],
41  [ 'bold', 'en', 'bold-b.svg' ],
42  [ 'bold', 'de', 'bold-f.svg' ],
43  [ 'bold', 'ar', 'bold-f.svg' ],
44  [ 'bold', 'fr', 'bold-a.svg' ],
45  [ 'bold', 'he', 'bold-a.svg' ],
46  ];
47  }
48 
53  public function testGetPath( $imageName, $languageCode, $path ) {
54  static $dirMap = [
55  'en' => 'ltr',
56  'de' => 'ltr',
57  'fr' => 'ltr',
58  'he' => 'rtl',
59  'ar' => 'rtl',
60  ];
61  static $contexts = [];
62 
63  $image = $this->getTestImage( $imageName );
65  'lang' => $languageCode,
66  'dir' => $dirMap[$languageCode],
67  ] );
68 
69  $this->assertEquals( $image->getPath( $context ), $this->imagesPath . '/' . $path );
70  }
71 
76  public function testGetExtension() {
77  $image = $this->getTestImage( 'remove' );
78  $this->assertEquals( $image->getExtension(), 'svg' );
79  $this->assertEquals( $image->getExtension( 'original' ), 'svg' );
80  $this->assertEquals( $image->getExtension( 'rasterized' ), 'png' );
81  $image = $this->getTestImage( 'add' );
82  $this->assertEquals( $image->getExtension(), 'gif' );
83  $this->assertEquals( $image->getExtension( 'original' ), 'gif' );
84  $this->assertEquals( $image->getExtension( 'rasterized' ), 'gif' );
85  }
86 
92  public function testGetImageData() {
94 
95  $image = $this->getTestImage( 'remove' );
96  $data = file_get_contents( $this->imagesPath . '/remove.svg' );
97  $dataConstructive = file_get_contents( $this->imagesPath . '/remove_variantize.svg' );
98  $this->assertEquals( $image->getImageData( $context, null, 'original' ), $data );
99  $this->assertEquals(
100  $image->getImageData( $context, 'destructive', 'original' ),
101  $dataConstructive
102  );
103  // Stub, since we don't know if we even have a SVG handler, much less what exactly it'll output
104  $this->assertEquals( $image->getImageData( $context, null, 'rasterized' ), 'RASTERIZESTUB' );
105 
106  $image = $this->getTestImage( 'add' );
107  $data = file_get_contents( $this->imagesPath . '/add.gif' );
108  $this->assertEquals( $image->getImageData( $context, null, 'original' ), $data );
109  $this->assertEquals( $image->getImageData( $context, null, 'rasterized' ), $data );
110  }
111 
115  public function testMassageSvgPathdata() {
116  $image = $this->getTestImage( 'next' );
117  $data = file_get_contents( $this->imagesPath . '/next.svg' );
118  $dataMassaged = file_get_contents( $this->imagesPath . '/next_massage.svg' );
119  $this->assertEquals( $image->massageSvgPathdata( $data ), $dataMassaged );
120  }
121 }
122 
124  // Make some protected methods public
125  public function massageSvgPathdata( $svg ) {
126  return parent::massageSvgPathdata( $svg );
127  }
128  // Stub, since we don't know if we even have a SVG handler, much less what exactly it'll output
129  public function rasterize( $svg ) {
130  return 'RASTERIZESTUB';
131  }
132 }
$context
error also a ContextSource you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
Definition: hooks.txt:2612
ResourceLoaderImageTestable\rasterize
rasterize( $svg)
Convert passed image data, which is assumed to be SVG, to PNG.
Definition: ResourceLoaderImageTest.php:129
ResourceLoaderImageTest\testMassageSvgPathdata
testMassageSvgPathdata()
ResourceLoaderImage::massageSvgPathdata.
Definition: ResourceLoaderImageTest.php:115
ResourceLoaderImageTest\$imagesPath
$imagesPath
Definition: ResourceLoaderImageTest.php:8
ResourceLoaderImageTest\setUp
setUp()
Definition: ResourceLoaderImageTest.php:10
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:304
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:35
ResourceLoaderImageTestable
Definition: ResourceLoaderImageTest.php:123
ResourceLoaderImageTest\testGetPath
testGetPath( $imageName, $languageCode, $path)
ResourceLoaderImage::getPath provideGetPath.
Definition: ResourceLoaderImageTest.php:53
ResourceLoaderImageTest\testGetImageData
testGetImageData()
ResourceLoaderImage::getImageData ResourceLoaderImage::variantize ResourceLoaderImage::massageSvgPath...
Definition: ResourceLoaderImageTest.php:92
ResourceLoaderImageTestable\massageSvgPathdata
massageSvgPathdata( $svg)
Massage the SVG image data for converters which don't understand some path data syntax.
Definition: ResourceLoaderImageTest.php:125
ResourceLoaderImageTest\getTestImage
getTestImage( $name)
Definition: ResourceLoaderImageTest.php:15
$image
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable modifiable after all normalizations have been except for the $wgMaxImageArea check $image
Definition: hooks.txt:783
ResourceLoaderImage
Class encapsulating an image used in a ResourceLoaderImageModule.
Definition: ResourceLoaderImage.php:28
ResourceLoaderImageModuleTest\$commonImageData
static $commonImageData
Definition: ResourceLoaderImageModuleTest.php:10
ResourceLoaderImageTest\provideGetPath
static provideGetPath()
Definition: ResourceLoaderImageTest.php:30
ResourceLoaderImageTest
ResourceLoader.
Definition: ResourceLoaderImageTest.php:6
$path
$path
Definition: NoLocalSettings.php:26
ResourceLoaderTestCase\getResourceLoaderContext
getResourceLoaderContext( $options=[], ResourceLoader $rl=null)
Definition: ResourceLoaderTestCase.php:22
ResourceLoaderImageTest\testGetExtension
testGetExtension()
ResourceLoaderImage::getExtension ResourceLoaderImage::getMimeType.
Definition: ResourceLoaderImageTest.php:76
$options
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context $options
Definition: hooks.txt:1049
ResourceLoaderTestCase
Definition: ResourceLoaderTestCase.php:7