You are here

public function UuidResolverTest::testResolveWithEntity in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/serialization/tests/src/Unit/EntityResolver/UuidResolverTest.php \Drupal\Tests\serialization\Unit\EntityResolver\UuidResolverTest::testResolveWithEntity()

Test resolve() when a UUID corresponds to an entity.

File

core/modules/serialization/tests/src/Unit/EntityResolver/UuidResolverTest.php, line 87

Class

UuidResolverTest
@coversDefaultClass \Drupal\serialization\EntityResolver\UuidResolver @group serialization

Namespace

Drupal\Tests\serialization\Unit\EntityResolver

Code

public function testResolveWithEntity() {
  $uuid = '392eab92-35c2-4625-872d-a9dab4da008e';
  $entity = $this
    ->createMock('Drupal\\Core\\Entity\\EntityInterface');
  $entity
    ->expects($this
    ->once())
    ->method('id')
    ->will($this
    ->returnValue(1));
  $this->entityRepository
    ->expects($this
    ->once())
    ->method('loadEntityByUuid')
    ->with('test_type', $uuid)
    ->will($this
    ->returnValue($entity));
  $normalizer = $this
    ->createMock('Drupal\\serialization\\EntityResolver\\UuidReferenceInterface');
  $normalizer
    ->expects($this
    ->once())
    ->method('getUuid')
    ->with([])
    ->will($this
    ->returnValue($uuid));
  $this
    ->assertSame(1, $this->resolver
    ->resolve($normalizer, [], 'test_type'));
}