You are here

public function UploadFileServiceTest::testExtensionValidation in GraphQL 8.4

Tests that the uploaded file extension is validated.

File

tests/src/Kernel/Framework/UploadFileServiceTest.php, line 169

Class

UploadFileServiceTest
Tests file uploads that should be mapped to a field in a resolver.

Namespace

Drupal\Tests\graphql\Kernel\Framework

Code

public function testExtensionValidation() : void {
  $uploadFile = $this
    ->getUploadedFile(UPLOAD_ERR_OK, 0, 'test.txt');
  $file_upload_response = $this->uploadService
    ->saveFileUpload($uploadFile, [
    'uri_scheme' => 'public',
    'file_directory' => 'test',
    // We only allow odt files, so validation must fail.
    'file_extensions' => 'odt',
  ]);
  $violations = $file_upload_response
    ->getViolations();

  // @todo Do we want HTML tags in our violations or not?
  $this
    ->assertStringMatchesFormat('Only files with the following extensions are allowed: <em class="placeholder">odt</em>.', $violations[0]['message']);
}