2015-05-04 14:43:53 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class ImageFilenameSanitizerTest extends WikiaBaseTest {
|
|
|
|
private $imageFilenameSanitizer;
|
|
|
|
|
|
|
|
protected function setUp() {
|
|
|
|
$this->setupFile = dirname( __FILE__ ) . '/../PortableInfobox.setup.php';
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->imageFilenameSanitizer = \Wikia\PortableInfobox\Helpers\ImageFilenameSanitizer::getInstance();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $inputFileName
|
|
|
|
* @param $expectedOutput
|
|
|
|
* @param $description
|
|
|
|
* @dataProvider testSanitizeFilenameDataProvider
|
|
|
|
*/
|
2015-05-04 15:43:09 +00:00
|
|
|
public function testSanitizeFilename( $inputFileName, $contentLanguageCode, $expectedOutput, $description ) {
|
|
|
|
$language = new \Language();
|
|
|
|
$language->setCode( $contentLanguageCode );
|
|
|
|
$actualOutput = $this->imageFilenameSanitizer->sanitizeImageFileName( $inputFileName, $language );
|
2015-05-04 14:43:53 +00:00
|
|
|
|
|
|
|
$this->assertEquals( $expectedOutput, $actualOutput, $description );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSanitizeFilenameDataProvider() {
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
'filename.jpg',
|
2015-05-04 15:43:09 +00:00
|
|
|
'en',
|
|
|
|
'filename.jpg',
|
|
|
|
'Plain filename'
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'File:filename.jpg',
|
|
|
|
'en',
|
|
|
|
'filename.jpg',
|
|
|
|
'Filename with namespace'
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'Plik:filename.jpg',
|
|
|
|
'pl',
|
|
|
|
'filename.jpg',
|
|
|
|
'Filename with localized namespace'
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'Grafika:filename.jpg',
|
|
|
|
'pl',
|
|
|
|
'filename.jpg',
|
|
|
|
'Filename with localized namespace alias'
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'File:filename.jpg|300px',
|
|
|
|
'en',
|
|
|
|
'filename.jpg',
|
|
|
|
'Filename with namespace and width'
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'[[File:filename.jpg|300px|lorem ipsum]]',
|
|
|
|
'en',
|
|
|
|
'filename.jpg',
|
|
|
|
'Link to filename with namespace, width and caption'
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'[[File:filename.jpg|lorem ipsum]]',
|
|
|
|
'en',
|
|
|
|
'filename.jpg',
|
|
|
|
'Link to filename with namespace and caption'
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'{{File:filename.jpg|lorem ipsum}}',
|
|
|
|
'en',
|
|
|
|
'{{File:filename.jpg',
|
|
|
|
'Non-file string; sanitized, though useless'
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'',
|
|
|
|
'en',
|
|
|
|
'',
|
|
|
|
'Empty file name'
|
2015-05-04 14:43:53 +00:00
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|