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-06 14:27:58 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'[[File:image.jpg|300px|lorem ipsum]]',
|
|
|
|
'es',
|
|
|
|
'image.jpg',
|
|
|
|
'Link to filename with canonical namespace, width and caption on a non-EN wiki '
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'[[File:image.jpg|lorem ipsum]]',
|
|
|
|
'es',
|
|
|
|
'image.jpg',
|
|
|
|
'Link to filename with canonical namespace and caption on a non-EN wiki '
|
2015-06-16 12:26:27 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'<gallery>' . PHP_EOL .
|
|
|
|
'</gallery>' . PHP_EOL,
|
|
|
|
'en',
|
|
|
|
'',
|
|
|
|
'Empty gallery'
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'<gallery></gallery>',
|
|
|
|
'en',
|
|
|
|
'',
|
|
|
|
'Empty gallery'
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'<gallery />',
|
|
|
|
'en',
|
|
|
|
'',
|
|
|
|
'Empty gallery'
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'<gallery>' . PHP_EOL .
|
|
|
|
'image.jpg' . PHP_EOL .
|
|
|
|
'</gallery>' . PHP_EOL,
|
|
|
|
'en',
|
|
|
|
'image.jpg',
|
|
|
|
'Gallery with one image'
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'<gallery>' . PHP_EOL .
|
|
|
|
'File:image.jpg' . PHP_EOL .
|
|
|
|
'</gallery>' . PHP_EOL,
|
|
|
|
'en',
|
|
|
|
'image.jpg',
|
|
|
|
'Gallery with one image with canonical namespace',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'<gallery>' . PHP_EOL .
|
|
|
|
'文件名óśłżźćńę?.jpg' . PHP_EOL .
|
|
|
|
'Image010.jpg' . PHP_EOL .
|
|
|
|
'Image009.jpg' . PHP_EOL .
|
|
|
|
'</gallery>' . PHP_EOL,
|
|
|
|
'en',
|
|
|
|
'文件名óśłżźćńę?.jpg',
|
|
|
|
'Gallery with diacritics and UTF characters'
|
2015-06-19 10:31:22 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
PHP_EOL .
|
|
|
|
PHP_EOL,
|
|
|
|
'en',
|
|
|
|
'',
|
|
|
|
'Content of empty gallery with newlines'
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'',
|
|
|
|
'en',
|
|
|
|
'',
|
|
|
|
'Content of empty gallery'
|
|
|
|
],
|
|
|
|
[
|
|
|
|
PHP_EOL .
|
|
|
|
'image.jpg' . PHP_EOL .
|
|
|
|
PHP_EOL,
|
|
|
|
'en',
|
|
|
|
'image.jpg',
|
|
|
|
'Content of gallery with one image'
|
|
|
|
],
|
|
|
|
[
|
|
|
|
PHP_EOL .
|
|
|
|
'File:image.jpg' . PHP_EOL .
|
|
|
|
PHP_EOL,
|
|
|
|
'en',
|
|
|
|
'image.jpg',
|
|
|
|
'Content of gallery with one image with canonical namespace',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
PHP_EOL .
|
|
|
|
'文件名óśłżźćńę?.jpg' . PHP_EOL .
|
|
|
|
'Image010.jpg' . PHP_EOL .
|
|
|
|
'Image009.jpg' . PHP_EOL .
|
|
|
|
PHP_EOL,
|
|
|
|
'en',
|
|
|
|
'文件名óśłżźćńę?.jpg',
|
|
|
|
'Content of gallery with diacritics and UTF characters'
|
2015-05-04 14:43:53 +00:00
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|