You are here

public function UploadFileServiceTest::testUnsuccessWithMultipleFileUploads in GraphQL 8.4

Tests unsuccessful scenario with multiple file uploads.

File

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

Class

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

Namespace

Drupal\Tests\graphql\Kernel\Framework

Code

public function testUnsuccessWithMultipleFileUploads() : void {
  $uploadFiles = [
    $this
      ->getUploadedFile(UPLOAD_ERR_OK, 0, 'test1.txt', 'graphql_upload_test1.txt'),
    $this
      ->getUploadedFile(UPLOAD_ERR_OK, 0, 'test2.txt', 'graphql_upload_test2.txt'),
    $this
      ->getUploadedFile(UPLOAD_ERR_OK, 0, 'test3.jpg', 'graphql_upload_test3.jpg'),
  ];
  $file_upload_response = $this->uploadService
    ->saveMultipleFileUploads($uploadFiles, [
    'uri_scheme' => 'public',
    'file_directory' => 'test',
    'file_extensions' => 'txt',
  ]);

  // There must be violation regarding forbidden file extension.
  $violations = $file_upload_response
    ->getViolations();
  $this
    ->assertStringMatchesFormat('Only files with the following extensions are allowed: <em class="placeholder">txt</em>.', $violations[0]['message']);

  // There must be no file entities.
  $file_entities = $file_upload_response
    ->getFileEntities();
  $this
    ->assertEmpty($file_entities);
}