You are here

public function UploadFileServiceTest::testLockReleased in GraphQL 8.4

Tests that the file lock is released on validation errors.

File

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

Class

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

Namespace

Drupal\Tests\graphql\Kernel\Framework

Code

public function testLockReleased() : void {

  // Mock the lock system to check that the lock is released.
  $lock = $this
    ->prophesize(LockBackendInterface::class);
  $lock
    ->acquire(Argument::any())
    ->willReturn(TRUE);

  // This is our only assertion - that the lock release method is called.
  $lock
    ->release(Argument::any())
    ->shouldBeCalled();
  $upload_service = new FileUpload(\Drupal::service('entity_type.manager'), \Drupal::service('current_user'), \Drupal::service('file.mime_type.guesser'), \Drupal::service('file_system'), \Drupal::service('logger.channel.graphql'), \Drupal::service('token'), $lock
    ->reveal(), \Drupal::service('config.factory'), \Drupal::service('renderer'));

  // Create a Symfony dummy uploaded file in test mode.
  $uploadFile = $this
    ->getUploadedFile(UPLOAD_ERR_OK, 4);

  // Create a file with 4 bytes.
  file_put_contents($uploadFile
    ->getRealPath(), 'test');
  $upload_service
    ->saveFileUpload($uploadFile, [
    'uri_scheme' => 'public',
    'file_directory' => 'test',
    // Only allow 1 byte.
    'max_filesize' => 1,
  ]);
}