public function FileImportExportTest::testFileImportExport in Acquia Content Hub 8.2
Tests import/export of node with file.
@dataProvider fileImportExportDataProvider
Parameters
int $delta: Delta.
array $validate_data: Data.
string $export_type: Entity type ID.
string $export_uuid: Uuid.
Throws
\Drupal\Core\Entity\EntityStorageException
\Exception
File
- tests/
src/ Kernel/ FileImportExportTest.php, line 88
Class
- FileImportExportTest
- Tests that files are properly exported and imported.
Namespace
Drupal\Tests\acquia_contenthub\KernelCode
public function testFileImportExport($delta, array $validate_data, $export_type, $export_uuid) {
parent::contentEntityImportExport($delta, $validate_data, $export_type, $export_uuid);
/** @var \Drupal\Core\Entity\EntityRepository $repository */
$repository = \Drupal::service('entity.repository');
foreach ($validate_data as $datum) {
if (!isset($datum['file'])) {
continue;
}
$entity_type = $datum['type'];
$validate_uuid = $datum['uuid'];
$file_fixture = $datum['file'];
$file = $repository
->loadEntityByUuid($entity_type, $validate_uuid);
$this
->assertFileExists($file
->getFileUri());
$imported_file_content = file_get_contents($file
->getFileUri());
$this
->assertStringEqualsFile(sprintf($file_fixture, $this
->getPathToFixtures()), $imported_file_content);
}
}