You are here

public function FileTest::testProcess in YAML Content 8

Test file processing.

@covers ::process

File

tests/src/Functional/Plugin/yaml_content/process/FileTest.php, line 42

Class

FileTest
Test file processing.

Namespace

Drupal\Tests\yaml_content\Functional\Plugin\yaml_content\process

Code

public function testProcess() {
  $args = [
    'my_entity',
    [
      'filename' => 'test_file.txt',
    ],
  ];
  $file = new File($args, '', []);
  $context = new ProcessingContext();
  $context
    ->setContentLoader(new ContentLoader($this
    ->prophesize(ContainerInterface::class)
    ->reveal()));
  $context
    ->getContentLoader()
    ->setContentPath(realpath($this
    ->getFixturePath() . '/../../'));
  $field = new FieldItemList(new BaseFieldDefinition([], new DataDefinition()));
  $context
    ->setField($field);
  $data = [];
  $expected_fid = $file
    ->process($context, $data);
  $this
    ->assertEquals([
    'target_id' => $expected_fid,
  ], $data);
  $storage = \Drupal::entityTypeManager()
    ->getStorage('file');
  $file = $storage
    ->load($expected_fid);
  $this
    ->assertEquals($args[1]['filename'], $file
    ->getFilename());
  $this
    ->assertFileExists($file
    ->getFileUri());
}