You are here

public function EntityLoadHelperTest::testLoadEntityWithUuidReturnsMatchedEntity in YAML Content 8

Test that loadEntity returns matched entity if UUID searching returned a match.

@covers ::loadEntity

File

tests/src/Unit/EntityLoadHelper/EntityLoadHelperTest.php, line 281

Class

EntityLoadHelperTest
Test functionality of the EntityLoadHelper class.

Namespace

Drupal\Tests\yaml_content\Unit\EntityLoadHelper

Code

public function testLoadEntityWithUuidReturnsMatchedEntity() {
  $this->loadHelper = $this
    ->getEntityLoadHelperMock([
    'loadByUuid',
    'loadByProperties',
  ]);

  // Prepare the parameters.
  $entity_type = 'test_entity';
  $content_data = [
    'entity' => 'test_entity',
    // Include a UUID property.
    'uuid' => '3c6485e4-69a3-429d-8ab1-3e7df48747bc',
  ];

  // Mock that loadByUuid found a match.
  $matched_entity = $this
    ->getEntityMock();
  $this->loadHelper
    ->method('loadByUuid')
    ->willReturn($matched_entity);

  // Execute the method.
  $actual = $this->loadHelper
    ->loadEntity($entity_type, $content_data);

  // Confirm the return value.
  $this
    ->assertSame($matched_entity, $actual);
}