public function UploadFileServiceTest::testSuccessWithMultipleFileUploads in GraphQL 8.4
Tests successful scenario with multiple file uploads.
File
- tests/
src/ Kernel/ Framework/ UploadFileServiceTest.php, line 226
Class
- UploadFileServiceTest
- Tests file uploads that should be mapped to a field in a resolver.
Namespace
Drupal\Tests\graphql\Kernel\FrameworkCode
public function testSuccessWithMultipleFileUploads() : 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.txt', 'graphql_upload_test3.txt'),
];
$file_upload_response = $this->uploadService
->saveMultipleFileUploads($uploadFiles, [
'uri_scheme' => 'public',
'file_directory' => 'test',
'file_extensions' => 'txt',
]);
// There must be no violations.
$violations = $file_upload_response
->getViolations();
$this
->assertEmpty($violations);
// There must be three file entities.
$file_entities = $file_upload_response
->getFileEntities();
$this
->assertCount(3, $file_entities);
foreach ($file_entities as $index => $file_entity) {
$this
->assertSame('public://test/test' . ($index + 1) . '.txt', $file_entity
->getFileUri());
$this
->assertFileExists($file_entity
->getFileUri());
}
}