X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Ffield%2Ftests%2Fsrc%2FUnit%2FFieldConfigEntityUnitTest.php;fp=web%2Fcore%2Fmodules%2Ffield%2Ftests%2Fsrc%2FUnit%2FFieldConfigEntityUnitTest.php;h=b7dadf4926b11fccaaa9ea0ea17fa98362bd5cc0;hp=d1824cfcceeda7c9c86b694f75a467d26a8fd10c;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/web/core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php b/web/core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php index d1824cfcc..b7dadf492 100644 --- a/web/core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php +++ b/web/core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php @@ -10,6 +10,9 @@ namespace Drupal\Tests\field\Unit; use Drupal\Core\Entity\EntityType; use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\DependencyInjection\ContainerBuilder; +use Drupal\Core\Entity\EntityFieldManagerInterface; +use Drupal\Core\Entity\EntityManager; +use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\field\Entity\FieldConfig; use Drupal\Tests\UnitTestCase; @@ -33,6 +36,20 @@ class FieldConfigEntityUnitTest extends UnitTestCase { */ protected $entityManager; + /** + * The entity type manager used for testing. + * + * @var \Drupal\Core\Entity\EntityTypeManagerInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $entityTypeManager; + + /** + * The entity field manager used for testing. + * + * @var \Drupal\Core\Entity\EntityFieldManagerInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $entityFieldManager; + /** * The ID of the type of the entity under test. * @@ -75,7 +92,9 @@ class FieldConfigEntityUnitTest extends UnitTestCase { $this->entityTypeId = $this->randomMachineName(); $this->entityType = $this->getMock('\Drupal\Core\Config\Entity\ConfigEntityTypeInterface'); - $this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface'); + $this->entityManager = new EntityManager(); + $this->entityTypeManager = $this->getMock(EntityTypeManagerInterface::class); + $this->entityFieldManager = $this->getMock(EntityFieldManagerInterface::class); $this->uuid = $this->getMock('\Drupal\Component\Uuid\UuidInterface'); @@ -85,9 +104,14 @@ class FieldConfigEntityUnitTest extends UnitTestCase { $container = new ContainerBuilder(); $container->set('entity.manager', $this->entityManager); + $container->set('entity_field.manager', $this->entityFieldManager); + $container->set('entity_type.manager', $this->entityTypeManager); $container->set('uuid', $this->uuid); $container->set('config.typed', $this->typedConfigManager); $container->set('plugin.manager.field.field_type', $this->fieldTypePluginManager); + // Inject the container into entity.manager so it can defer to + // entity_type.manager, etc. + $this->entityManager->setContainer($container); \Drupal::setContainer($container); // Create a mock FieldStorageConfig object. @@ -102,7 +126,7 @@ class FieldConfigEntityUnitTest extends UnitTestCase { ->method('getSettings') ->willReturn([]); // Place the field in the mocked entity manager's field registry. - $this->entityManager->expects($this->any()) + $this->entityFieldManager->expects($this->any()) ->method('getFieldStorageDefinitions') ->with('test_entity_type') ->will($this->returnValue([ @@ -120,19 +144,19 @@ class FieldConfigEntityUnitTest extends UnitTestCase { ->method('getBundleConfigDependency') ->will($this->returnValue(['type' => 'config', 'name' => 'test.test_entity_type.id'])); - $this->entityManager->expects($this->at(0)) + $this->entityTypeManager->expects($this->at(0)) ->method('getDefinition') ->with($this->entityTypeId) ->willReturn($this->entityType); - $this->entityManager->expects($this->at(1)) + $this->entityTypeManager->expects($this->at(1)) ->method('getDefinition') ->with($this->entityTypeId) ->willReturn($this->entityType); - $this->entityManager->expects($this->at(2)) + $this->entityTypeManager->expects($this->at(2)) ->method('getDefinition') ->with($this->entityTypeId) ->willReturn($this->entityType); - $this->entityManager->expects($this->at(3)) + $this->entityTypeManager->expects($this->at(3)) ->method('getDefinition') ->with('test_entity_type') ->willReturn($target_entity_type); @@ -168,7 +192,7 @@ class FieldConfigEntityUnitTest extends UnitTestCase { ->with('test_bundle_not_exists') ->will($this->returnValue(NULL)); - $this->entityManager->expects($this->any()) + $this->entityTypeManager->expects($this->any()) ->method('getStorage') ->with('bundle_entity_type') ->will($this->returnValue($storage)); @@ -178,19 +202,19 @@ class FieldConfigEntityUnitTest extends UnitTestCase { 'bundle_entity_type' => 'bundle_entity_type', ]); - $this->entityManager->expects($this->at(0)) + $this->entityTypeManager->expects($this->at(0)) ->method('getDefinition') ->with($this->entityTypeId) ->willReturn($this->entityType); - $this->entityManager->expects($this->at(1)) + $this->entityTypeManager->expects($this->at(1)) ->method('getDefinition') ->with($this->entityTypeId) ->willReturn($this->entityType); - $this->entityManager->expects($this->at(2)) + $this->entityTypeManager->expects($this->at(2)) ->method('getDefinition') ->with($this->entityTypeId) ->willReturn($this->entityType); - $this->entityManager->expects($this->at(3)) + $this->entityTypeManager->expects($this->at(3)) ->method('getDefinition') ->with('test_entity_type') ->willReturn($target_entity_type); @@ -267,7 +291,7 @@ class FieldConfigEntityUnitTest extends UnitTestCase { 'dependencies' => [], 'field_type' => 'test_field', ]; - $this->entityManager->expects($this->any()) + $this->entityTypeManager->expects($this->any()) ->method('getDefinition') ->with($this->entityTypeId) ->will($this->returnValue($this->entityType)); @@ -289,7 +313,7 @@ class FieldConfigEntityUnitTest extends UnitTestCase { public function testGetType() { // Ensure that FieldConfig::getType() is not delegated to // FieldStorage. - $this->entityManager->expects($this->never()) + $this->entityFieldManager->expects($this->never()) ->method('getFieldStorageDefinitions'); $this->fieldStorage->expects($this->never()) ->method('getType');