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;
*/
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.
*
$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');
$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.
->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([
->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);
->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));
'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);
'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));
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');