SanitizeNameTest.php in Transliterate filenames for uploads 8
File
tests/src/Unit/SanitizeNameTest.php
View source
<?php
namespace Drupal\Tests\transliterate_filenames\Unit;
use Drupal\Component\Transliteration\PhpTransliteration;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Tests\UnitTestCase;
use Drupal\transliterate_filenames\SanitizeName;
class SanitizeNameTest extends UnitTestCase {
protected function setUp() {
parent::setUp();
$container = new ContainerBuilder();
\Drupal::setContainer($container);
$container
->set('transliterate_filenames.sanitize_name', new SanitizeName(new PhpTransliteration()));
}
public function testSanitizeName($filename, $expected) {
$sanitize_filename = \Drupal::service('transliterate_filenames.sanitize_name');
$this
->assertEquals($expected, $sanitize_filename
->sanitizeFilename($filename));
}
public function providerSanitizeName() {
return [
[
'ąęółżźćśń.pdf',
'aeolzzcsn.pdf',
],
[
chr(0xf8) . chr(0x80) . chr(0x80) . '.txt',
'.txt',
],
[
'LOWERCASE.txt',
'lowercase.txt',
],
[
'test whitespace.txt',
'test-whitespace.txt',
],
[
'test whitespace.txt',
'test-whitespace.txt',
],
[
'---___.txt',
'-_.txt',
],
[
'-- --.txt',
'-.txt',
],
];
}
}