FilenameTransliterationTest.php in Thunder 6.2.x
File
modules/thunder_media/tests/src/Functional/FilenameTransliterationTest.php
View source
<?php
namespace Drupal\Tests\thunder_media\Functional;
use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\StreamWrapper\PublicStream;
use Drupal\file\Entity\File;
use Drupal\Tests\thunder\Functional\ThunderTestBase;
class FilenameTransliterationTest extends ThunderTestBase {
public static $modules = [
'file_test',
'file',
];
protected function setUp() {
parent::setUp();
$this
->config('thunder_media.settings')
->set('enable_filename_transliteration', TRUE)
->save();
}
public function testFileTransliteration() {
$account = $this
->drupalCreateUser([
'access site reports',
]);
$this
->drupalLogin($account);
if (file_exists('core/tests/fixtures/files/image-1.png')) {
\Drupal::service('file_system')
->copy('core/tests/fixtures/files/image-1.png', PublicStream::basePath() . '/foo°.png');
}
else {
$original = drupal_get_path('module', 'simpletest') . '/files';
\Drupal::service('file_system')
->copy($original . '/image-1.png', PublicStream::basePath() . '/foo°.png');
}
$edit = [
'file_test_replace' => FileSystemInterface::EXISTS_RENAME,
'files[file_test_upload]' => \Drupal::service('file_system')
->realpath('public://foo°.png'),
];
$this
->drupalGet('file-test/upload');
$this
->submitForm($edit, $this
->t('Submit'));
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->responseContains('You WIN!');
$this
->assertTrue(file_exists('temporary://foodeg.png'));
$max_fid_after = \Drupal::database()
->query('SELECT MAX(fid) AS fid FROM {file_managed}')
->fetchField();
$file = File::load($max_fid_after);
$this
->assertSame('foodeg.png', $file
->getFilename());
$this
->assertSame('temporary://foodeg.png', $file
->getFileUri());
}
}