/** * {@inheritdoc} */ public function getFilename(UploadedFile $file) { $original_name = $file->getClientOriginalName(); // There should be a filename and it should not contain a semicolon, // which we use to separate filenames. if (!isset($original_name)) { throw new UploadException(UploadException::FILENAME_ERROR); } // Transliterate. $processed_filename = $this->transliteration->transliterate($original_name); // For security reasons append the txt extension. It will be removed in // Drupal\dropzonejs\Element::valueCallback when we will know the valid // extension and we will be able to properly sanitize the filename. $processed_filename = $processed_filename . '.txt'; return $processed_filename; }
/** * Tests the PhpTransliteration with an alter hook. * * @param string $langcode * The langcode of the string. * @param string $original * The string which was not transliterated yet. * @param string $expected * The string expected after the transliteration. * @param string|NULL $printable * (optional) An alternative version of the original string which is * printable in the output. * * @dataProvider providerTestPhpTransliterationWithAlter */ public function testPhpTransliterationWithAlter($langcode, $original, $expected, $printable = NULL) { if ($printable === NULL) { $printable = $original; } // Test each case both with a new instance of the transliteration class, // and with one that builds as it goes. $module_handler = $this->getMock('Drupal\\Core\\Extension\\ModuleHandlerInterface'); $module_handler->expects($this->any())->method('alter')->will($this->returnCallback(function ($hook, &$overrides, $langcode) { if ($langcode == 'zz') { // The default transliteration of Ä is A, but change it to Z for testing. $overrides[0xc4] = 'Z'; // Also provide transliterations of two 5-byte characters from // http://en.wikipedia.org/wiki/Gothic_alphabet. $overrides[0x10330] = 'A'; $overrides[0x10338] = 'Th'; } })); $transliteration = new PhpTransliteration(NULL, $module_handler); $actual = $transliteration->transliterate($original, $langcode); $this->assertSame($expected, $actual, "'{$printable}' transliteration to '{$actual}' is identical to '{$expected}' for language '{$langcode}' in service instance."); }