Mercurial > hg > isophonics-drupal-site
diff core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | 4c8ae668cc8c |
children | 129ea1e6d783 |
line wrap: on
line diff
--- a/core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php Mon Apr 23 09:33:26 2018 +0100 +++ b/core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php Mon Apr 23 09:46:53 2018 +0100 @@ -10,6 +10,9 @@ 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; @@ -34,6 +37,20 @@ 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. * * @var string @@ -75,7 +92,9 @@ $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 @@ $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 @@ ->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 @@ ->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 @@ ->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 @@ '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 @@ '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 @@ 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');