You are here

public function ExporterIntegrationTest::testExportFiles in Default Content for D8 2.0.x

Tests exporting files.

File

tests/src/Kernel/ExporterIntegrationTest.php, line 305

Class

ExporterIntegrationTest
Tests export functionality.

Namespace

Drupal\Tests\default_content\Kernel

Code

public function testExportFiles() {
  \Drupal::service('module_installer')
    ->install([
    'default_content',
  ]);
  $this->exporter = \Drupal::service('default_content.exporter');
  $test_files = $this
    ->getTestFiles('image');
  $test_file = reset($test_files);

  /** @var \Drupal\file\FileInterface $file */
  $file = File::create([
    'uri' => $test_file->uri,
    'status' => \FILE_STATUS_PERMANENT,
  ]);
  $file
    ->save();
  $folder = 'temporary://default_content';
  $exported_by_entity_type = $this->exporter
    ->exportContentWithReferences('file', $file
    ->id(), $folder);
  $normalized_file = Yaml::decode($exported_by_entity_type['file'][$file
    ->uuid()]);
  $expected = [
    '_meta' => [
      'version' => '1.0',
      'entity_type' => 'file',
      'uuid' => $file
        ->uuid(),
      'default_langcode' => 'en',
    ],
    'default' => [
      'filename' => [
        0 => [
          'value' => $file
            ->getFilename(),
        ],
      ],
      'uri' => [
        0 => [
          'value' => $file
            ->getFileUri(),
        ],
      ],
      'filemime' => [
        0 => [
          'value' => $file
            ->getMimeType(),
        ],
      ],
      'filesize' => [
        0 => [
          'value' => $file
            ->getSize(),
        ],
      ],
      'status' => [
        0 => [
          'value' => TRUE,
        ],
      ],
      'created' => [
        0 => [
          'value' => $file
            ->getCreatedTime(),
        ],
      ],
    ],
  ];
  $this
    ->assertEquals($expected, $normalized_file);
  $this
    ->assertFileExists($folder . '/file/' . $file
    ->uuid() . '.yml');
  $this
    ->assertFileExists($folder . '/file/' . $file
    ->getFilename());
}