Same filename and directory in other branches
- 8.9.x core/modules/serialization/tests/src/Unit/EntityResolver/UuidResolverTest.php
- 9 core/modules/serialization/tests/src/Unit/EntityResolver/UuidResolverTest.php
Namespace
Drupal\Tests\serialization\Unit\EntityResolver
File
core/modules/serialization/tests/src/Unit/EntityResolver/UuidResolverTest.php
View source
<?php
declare (strict_types=1);
namespace Drupal\Tests\serialization\Unit\EntityResolver;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Tests\UnitTestCase;
use Drupal\serialization\EntityResolver\UuidResolver;
class UuidResolverTest extends UnitTestCase {
protected $resolver;
protected $entityRepository;
protected function setUp() : void {
parent::setUp();
$this->entityRepository = $this
->createMock(EntityRepositoryInterface::class);
$this->resolver = new UuidResolver($this->entityRepository);
}
public function testResolveNotInInterface() {
$this->entityRepository
->expects($this
->never())
->method('loadEntityByUuid');
$normalizer = $this
->createMock('Symfony\\Component\\Serializer\\Normalizer\\NormalizerInterface');
$this
->assertNull($this->resolver
->resolve($normalizer, [], 'test_type'));
}
public function testResolveNoUuid() {
$this->entityRepository
->expects($this
->never())
->method('loadEntityByUuid');
$normalizer = $this
->createMock('Drupal\\serialization\\EntityResolver\\UuidReferenceInterface');
$normalizer
->expects($this
->once())
->method('getUuid')
->with([])
->willReturn(NULL);
$this
->assertNull($this->resolver
->resolve($normalizer, [], 'test_type'));
}
public function testResolveNoEntity() {
$uuid = '392eab92-35c2-4625-872d-a9dab4da008e';
$this->entityRepository
->expects($this
->once())
->method('loadEntityByUuid')
->with('test_type')
->willReturn(NULL);
$normalizer = $this
->createMock('Drupal\\serialization\\EntityResolver\\UuidReferenceInterface');
$normalizer
->expects($this
->once())
->method('getUuid')
->with([])
->willReturn($uuid);
$this
->assertNull($this->resolver
->resolve($normalizer, [], 'test_type'));
}
public function testResolveWithEntity() {
$uuid = '392eab92-35c2-4625-872d-a9dab4da008e';
$entity = $this
->createMock('Drupal\\Core\\Entity\\EntityInterface');
$entity
->expects($this
->once())
->method('id')
->willReturn(1);
$this->entityRepository
->expects($this
->once())
->method('loadEntityByUuid')
->with('test_type', $uuid)
->willReturn($entity);
$normalizer = $this
->createMock('Drupal\\serialization\\EntityResolver\\UuidReferenceInterface');
$normalizer
->expects($this
->once())
->method('getUuid')
->with([])
->willReturn($uuid);
$this
->assertSame(1, $this->resolver
->resolve($normalizer, [], 'test_type'));
}
}
Classes