You are here

public function NameMungingTest::testMunging in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/File/NameMungingTest.php \Drupal\KernelTests\Core\File\NameMungingTest::testMunging()

Create a file and munge/unmunge the name.

File

core/tests/Drupal/KernelTests/Core/File/NameMungingTest.php, line 62

Class

NameMungingTest
Tests filename munging and unmunging.

Namespace

Drupal\KernelTests\Core\File

Code

public function testMunging() {

  // Disable insecure uploads.
  $this
    ->config('system.file')
    ->set('allow_insecure_uploads', 0)
    ->save();
  $munged_name = file_munge_filename($this->name, '', TRUE);
  $messages = \Drupal::messenger()
    ->all();
  \Drupal::messenger()
    ->deleteAll();
  $this
    ->assertContains(strtr('For security reasons, your upload has been renamed to <em class="placeholder">%filename</em>.', [
    '%filename' => $munged_name,
  ]), $messages['status'], 'Alert properly set when a file is renamed.');
  $this
    ->assertNotEqual($munged_name, $this->name, new FormattableMarkup('The new filename (%munged) has been modified from the original (%original)', [
    '%munged' => $munged_name,
    '%original' => $this->name,
  ]));
}