You are here

public function ReferenceTest::testProcessCreateFail in YAML Content 8

Test reference processing failure.

File

tests/src/Unit/Plugin/yaml_content/process/ReferenceTest.php, line 124

Class

ReferenceTest
Test entity reference processing.

Namespace

Drupal\Tests\yaml_content\Unit\Plugin\yaml_content\process

Code

public function testProcessCreateFail() {
  $data = [
    '#process' => [
      'callback' => 'reference',
    ],
  ];

  // Mock a query so we can control and assert the mapping of arguments to entity.
  $query = $this
    ->prophesize(QueryInterface::class);
  $query
    ->condition('title', 'My First Blog Post')
    ->shouldBeCalled();
  $query
    ->execute()
    ->shouldBeCalled()
    ->willReturn();
  $this->entityStorageHandler
    ->getQuery('AND')
    ->shouldBeCalled()
    ->willReturn($query
    ->reveal());

  // Stub an existing entity since entities are complex and db bound.
  $entity = $this
    ->prophesize(EntityInterface::class);
  $entity
    ->id()
    ->willReturn(NULL);
  $this
    ->markTestIncomplete('How do we fail? Id will always be called and the array will always have something and not be empty.');

  // Create should not be called.
  $this->entityStorageHandler
    ->create(Argument::any())
    ->shouldBeCalled()
    ->willReturn($entity);
  $this->reference
    ->process(new ProcessingContext(), $data);
  $this
    ->assertArrayEquals([
    'target_id' => 2,
  ], $data);
}