You are here

public function SecurityFileUploadEventSubscriberTest::testSanitizeNameNoMunge in Drupal 9

Tests file name sanitization without file munging.

@dataProvider provideFilenamesNoMunge

@covers ::sanitizeName

Parameters

string $filename: The original filename.

string $allowed_extensions: The allowed extensions.

File

core/modules/system/tests/src/Unit/Event/SecurityFileUploadEventSubscriberTest.php, line 103

Class

SecurityFileUploadEventSubscriberTest
SecurityFileUploadEventSubscriber tests.

Namespace

Drupal\Tests\system\Unit\Event

Code

public function testSanitizeNameNoMunge(string $filename, string $allowed_extensions) {
  $config_factory = $this
    ->getConfigFactoryStub([
    'system.file' => [
      'allow_insecure_uploads' => FALSE,
    ],
  ]);
  $subscriber = new SecurityFileUploadEventSubscriber($config_factory);
  $event = new FileUploadSanitizeNameEvent($filename, $allowed_extensions);
  $subscriber
    ->sanitizeName($event);

  // Check the results of the configured sanitization.
  $this
    ->assertSame($filename, $event
    ->getFilename());
  $this
    ->assertSame(FALSE, $event
    ->isSecurityRename());
  $config_factory = $this
    ->getConfigFactoryStub([
    'system.file' => [
      'allow_insecure_uploads' => TRUE,
    ],
  ]);
  $event = new FileUploadSanitizeNameEvent($filename, $allowed_extensions);
  $subscriber = new SecurityFileUploadEventSubscriber($config_factory);
  $subscriber
    ->sanitizeName($event);

  // Check the results of the configured sanitization.
  $this
    ->assertSame($filename, $event
    ->getFilename());
  $this
    ->assertSame(FALSE, $event
    ->isSecurityRename());
}