public function ReferenceTest::testProcessExisting in YAML Content 8
Reference processing returns a reference to existing matching entities.
@covers ::process
File
- tests/
src/ Unit/ Plugin/ yaml_content/ process/ ReferenceTest.php, line 67
Class
- ReferenceTest
- Test entity reference processing.
Namespace
Drupal\Tests\yaml_content\Unit\Plugin\yaml_content\processCode
public function testProcessExisting() {
$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([
1,
]);
$this->entityStorageHandler
->getQuery('AND')
->shouldBeCalled()
->willReturn($query
->reveal());
// Create should not be called.
$this->entityStorageHandler
->create(Argument::any())
->shouldNotBeCalled();
$this->reference
->process(new ProcessingContext(), $data);
$this
->assertArrayEquals([
'target_id' => 1,
], $data);
}