You are here

public function EntityLoadHelperTest::testLoadEntityWithPropertiesdReturnsMatchedEntity in YAML Content 8

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

@covers ::loadEntity

File

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

Class

EntityLoadHelperTest
Test functionality of the EntityLoadHelper class.

Namespace

Drupal\Tests\yaml_content\Unit\EntityLoadHelper

Code

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

  // Prepare the parameters.
  $entity_type = 'test_entity';

  // Do not include a UUID property.
  $content_data = [
    'entity' => 'test_entity',
  ];

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

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

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