Commit 3bc858ec authored by catch's avatar catch

Issue #2782833 by Mile23, martin107, larowlan, effulgentsia: Remove usages of...

Issue #2782833 by Mile23, martin107, larowlan, effulgentsia: Remove usages of deprecated EntityManager from Entity class
parent 5f3b66ed
......@@ -88,6 +88,15 @@ protected function entityTypeManager() {
return \Drupal::entityTypeManager();
}
/**
* Gets the entity type bundle info service.
*
* @return \Drupal\Core\Entity\EntityTypeBundleInfoInterface
*/
protected function entityTypeBundleInfo() {
return \Drupal::service('entity_type.bundle.info');
}
/**
* Gets the language manager.
*
......@@ -198,7 +207,7 @@ public function toUrl($rel = 'canonical', array $options = []) {
$bundle = $this->bundle();
// A bundle-specific callback takes precedence over the generic one for
// the entity type.
$bundles = $this->entityManager()->getBundleInfo($this->getEntityTypeId());
$bundles = $this->entityTypeBundleInfo()->getBundleInfo($this->getEntityTypeId());
if (isset($bundles[$bundle]['uri_callback'])) {
$uri_callback = $bundles[$bundle]['uri_callback'];
}
......@@ -344,11 +353,11 @@ public function uriRelationships() {
*/
public function access($operation, AccountInterface $account = NULL, $return_as_object = FALSE) {
if ($operation == 'create') {
return $this->entityManager()
return $this->entityTypeManager()
->getAccessControlHandler($this->entityTypeId)
->createAccess($this->bundle(), $account, [], $return_as_object);
}
return $this->entityManager()
return $this->entityTypeManager()
->getAccessControlHandler($this->entityTypeId)
->access($this, $operation, $account, $return_as_object);
}
......@@ -374,7 +383,8 @@ public function language() {
* {@inheritdoc}
*/
public function save() {
return $this->entityManager()->getStorage($this->entityTypeId)->save($this);
$storage = $this->entityTypeManager()->getStorage($this->entityTypeId);
return $storage->save($this);
}
/**
......@@ -382,7 +392,7 @@ public function save() {
*/
public function delete() {
if (!$this->isNew()) {
$this->entityManager()->getStorage($this->entityTypeId)->delete([$this->id() => $this]);
$this->entityTypeManager()->getStorage($this->entityTypeId)->delete([$this->id() => $this]);
}
}
......@@ -407,7 +417,7 @@ public function createDuplicate() {
* {@inheritdoc}
*/
public function getEntityType() {
return $this->entityManager()->getDefinition($this->getEntityTypeId());
return $this->entityTypeManager()->getDefinition($this->getEntityTypeId());
}
/**
......@@ -508,24 +518,30 @@ public function getCacheMaxAge() {
* {@inheritdoc}
*/
public static function load($id) {
$entity_manager = \Drupal::entityManager();
return $entity_manager->getStorage($entity_manager->getEntityTypeFromClass(get_called_class()))->load($id);
$entity_type_repository = \Drupal::service('entity_type.repository');
$entity_type_manager = \Drupal::entityTypeManager();
$storage = $entity_type_manager->getStorage($entity_type_repository->getEntityTypeFromClass(get_called_class()));
return $storage->load($id);
}
/**
* {@inheritdoc}
*/
public static function loadMultiple(array $ids = NULL) {
$entity_manager = \Drupal::entityManager();
return $entity_manager->getStorage($entity_manager->getEntityTypeFromClass(get_called_class()))->loadMultiple($ids);
$entity_type_repository = \Drupal::service('entity_type.repository');
$entity_type_manager = \Drupal::entityTypeManager();
$storage = $entity_type_manager->getStorage($entity_type_repository->getEntityTypeFromClass(get_called_class()));
return $storage->loadMultiple($ids);
}
/**
* {@inheritdoc}
*/
public static function create(array $values = []) {
$entity_manager = \Drupal::entityManager();
return $entity_manager->getStorage($entity_manager->getEntityTypeFromClass(get_called_class()))->create($values);
$entity_type_repository = \Drupal::service('entity_type.repository');
$entity_type_manager = \Drupal::entityTypeManager();
$storage = $entity_type_manager->getStorage($entity_type_repository->getEntityTypeFromClass(get_called_class()));
return $storage->create($values);
}
/**
......
......@@ -3,6 +3,7 @@
namespace Drupal\Tests\block\Unit;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Tests\Core\Plugin\Fixtures\TestConfigurablePlugin;
use Drupal\Tests\UnitTestCase;
......@@ -20,11 +21,11 @@ class BlockConfigEntityUnitTest extends UnitTestCase {
protected $entityType;
/**
* The entity manager used for testing.
* The entity type manager used for testing.
*
* @var \Drupal\Core\Entity\EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject
* @var \Drupal\Core\Entity\EntityTypeManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $entityManager;
protected $entityTypeManager;
/**
* The ID of the type of the entity under test.
......@@ -51,8 +52,8 @@ protected function setUp() {
->method('getProvider')
->will($this->returnValue('block'));
$this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface');
$this->entityManager->expects($this->any())
$this->entityTypeManager = $this->getMock(EntityTypeManagerInterface::class);
$this->entityTypeManager->expects($this->any())
->method('getDefinition')
->with($this->entityTypeId)
->will($this->returnValue($this->entityType));
......@@ -60,7 +61,7 @@ protected function setUp() {
$this->uuid = $this->getMock('\Drupal\Component\Uuid\UuidInterface');
$container = new ContainerBuilder();
$container->set('entity.manager', $this->entityManager);
$container->set('entity_type.manager', $this->entityTypeManager);
$container->set('uuid', $this->uuid);
\Drupal::setContainer($container);
}
......
......@@ -3,6 +3,8 @@
namespace Drupal\Tests\editor\Unit;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Entity\EntityManager;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\editor\Entity\Editor;
use Drupal\Tests\UnitTestCase;
......@@ -22,9 +24,9 @@ class EditorConfigEntityUnitTest extends UnitTestCase {
/**
* The entity manager used for testing.
*
* @var \Drupal\Core\Entity\EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject
* @var \Drupal\Core\Entity\EntityTypeManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $entityManager;
protected $entityTypeManager;
/**
* The ID of the type of the entity under test.
......@@ -66,8 +68,8 @@ protected function setUp() {
->method('getProvider')
->will($this->returnValue('editor'));
$this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface');
$this->entityManager->expects($this->any())
$this->entityTypeManager = $this->getMock(EntityTypeManagerInterface::class);
$this->entityTypeManager->expects($this->any())
->method('getDefinition')
->with($this->entityTypeId)
->will($this->returnValue($this->entityType));
......@@ -78,10 +80,16 @@ protected function setUp() {
->disableOriginalConstructor()
->getMock();
$entity_manager = new EntityManager();
$container = new ContainerBuilder();
$container->set('entity.manager', $this->entityManager);
$container->set('entity.manager', $entity_manager);
$container->set('entity_type.manager', $this->entityTypeManager);
$container->set('uuid', $this->uuid);
$container->set('plugin.manager.editor', $this->editorPluginManager);
// Inject the container into entity.manager so it can defer to
// entity_type.manager.
$entity_manager->setContainer($container);
\Drupal::setContainer($container);
}
......@@ -120,7 +128,7 @@ public function testCalculateDependencies() {
->with($format_id)
->will($this->returnValue($filter_format));
$this->entityManager->expects($this->once())
$this->entityTypeManager->expects($this->once())
->method('getStorage')
->with('filter_format')
->will($this->returnValue($storage));
......
......@@ -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;
......@@ -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 @@ protected function setUp() {
$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 @@ protected function setUp() {
$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 @@ protected function setUp() {
->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 @@ public function testCalculateDependencies() {
->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 @@ public function testCalculateDependenciesIncorrectBundle() {
->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 @@ public function testCalculateDependenciesIncorrectBundle() {
'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 @@ public function testToArray() {
'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 testToArray() {
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');
......
......@@ -6,8 +6,9 @@
use Drupal\Core\Cache\Context\CacheContextsManager;
use Drupal\Core\Config\Entity\ConfigEntityTypeInterface;
use Drupal\Core\DependencyInjection\Container;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityManager;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\field\Entity\FieldStorageConfig;
......@@ -126,31 +127,37 @@ protected function setUp() {
$storage_access_control_handler = new FieldStorageConfigAccessControlHandler($storageType);
$storage_access_control_handler->setModuleHandler($this->moduleHandler);
$entityManager = $this->getMock(EntityManagerInterface::class);
$entityManager
$entity_type_manager = $this->getMock(EntityTypeManagerInterface::class);
$entity_type_manager
->expects($this->any())
->method('getDefinition')
->willReturnMap([
['field_storage_config', TRUE, $storageType],
['node', TRUE, $entityType],
]);
$entityManager
$entity_type_manager
->expects($this->any())
->method('getStorage')
->willReturnMap([
['field_storage_config', $this->getMock(EntityStorageInterface::class)],
]);
$entityManager
$entity_type_manager
->expects($this->any())
->method('getAccessControlHandler')
->willReturnMap([
['field_storage_config', $storage_access_control_handler],
]);
$entity_manager = new EntityManager();
$container = new Container();
$container->set('entity.manager', $entityManager);
$container->set('entity.manager', $entity_manager);
$container->set('entity_type.manager', $entity_type_manager);
$container->set('uuid', $this->getMock(UuidInterface::class));
$container->set('cache_contexts_manager', $this->prophesize(CacheContextsManager::class));
// Inject the container into entity.manager so it can defer to
// entity_type.manager.
$entity_manager->setContainer($container);
\Drupal::setContainer($container);
$this->fieldStorage = new FieldStorageConfig([
......
......@@ -8,6 +8,8 @@
namespace Drupal\Tests\field\Unit;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Entity\EntityManager;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Field\FieldException;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Field\FieldTypePluginManagerInterface;
......@@ -22,11 +24,11 @@
class FieldStorageConfigEntityUnitTest extends UnitTestCase {
/**
* The entity manager used for testing.
* The entity type manager used for testing.
*
* @var \Drupal\Core\Entity\EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject
* @var \Drupal\Core\Entity\EntityTypeManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $entityManager;
protected $entityTypeManager;
/**
* The ID of the type of the entity under test.
......@@ -53,14 +55,19 @@ class FieldStorageConfigEntityUnitTest extends UnitTestCase {
* {@inheritdoc}
*/
protected function setUp() {
$this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface');
$entity_manager = new EntityManager();
$this->entityTypeManager = $this->getMock(EntityTypeManagerInterface::class);
$this->uuid = $this->getMock('\Drupal\Component\Uuid\UuidInterface');
$this->fieldTypeManager = $this->getMock(FieldTypePluginManagerInterface::class);
$container = new ContainerBuilder();
$container->set('entity.manager', $this->entityManager);
$container->set('entity.manager', $entity_manager);
$container->set('entity_type.manager', $this->entityTypeManager);
$container->set('uuid', $this->uuid);
$container->set('plugin.manager.field.field_type', $this->fieldTypeManager);
// Inject the container into entity.manager so it can defer to
// entity_type.manager.
$entity_manager->setContainer($container);
\Drupal::setContainer($container);
}
......@@ -85,7 +92,7 @@ public function testCalculateDependencies() {
// ConfigEntityBase::addDependency() to get the provider of the field config
// entity type and once in FieldStorageConfig::calculateDependencies() to
// get the provider of the entity type that field is attached to.
$this->entityManager->expects($this->any())
$this->entityTypeManager->expects($this->any())
->method('getDefinition')
->willReturnMap([
['field_storage_config', TRUE, $fieldStorageConfigentityType],
......
......@@ -4,6 +4,9 @@
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Entity\EntityManager;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Entity\EntityTypeRepositoryInterface;
use Drupal\language\Entity\ContentLanguageSettings;
use Drupal\Tests\UnitTestCase;
......@@ -27,6 +30,13 @@ class ContentLanguageSettingsUnitTest extends UnitTestCase {
*/
protected $entityManager;
/**
* The entity type manager used for testing.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $entityTypeManager;
/**
* The ID of the type of the entity under test.
*
......@@ -62,7 +72,8 @@ protected function setUp() {
$this->entityTypeId = $this->randomMachineName();
$this->entityType = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface');
$this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface');
$this->entityManager = new EntityManager();
$this->entityTypeManager = $this->getMock(EntityTypeManagerInterface::class);
$this->uuid = $this->getMock('\Drupal\Component\Uuid\UuidInterface');
......@@ -72,9 +83,13 @@ protected function setUp() {
$container = new ContainerBuilder();
$container->set('entity.manager', $this->entityManager);
$container->set('entity_type.manager', $this->entityTypeManager);
$container->set('uuid', $this->uuid);
$container->set('config.typed', $this->typedConfigManager);
$container->set('config.storage', $this->configEntityStorageInterface);
// Inject the container into entity.manager so it can defer to other entity
// services.
$this->entityManager->setContainer($container);
\Drupal::setContainer($container);
}
......@@ -88,7 +103,7 @@ public function testCalculateDependencies() {
->method('getBundleConfigDependency')
->will($this->returnValue(['type' => 'config', 'name' => 'test.test_entity_type.id']));
$this->entityManager->expects($this->any())
$this->entityTypeManager->expects($this->any())
->method('getDefinition')
->with('test_entity_type')
->will($this->returnValue($target_entity_type));
......@@ -254,16 +269,20 @@ public function testLoadByEntityTypeBundle($config_id, ContentLanguageSettings $
->method('create')
->will($this->returnValue($nullConfig));
$this->entityManager
$this->entityTypeManager
->expects($this->any())
->method('getStorage')
->with('language_content_settings')
->will($this->returnValue($this->configEntityStorageInterface));
$this->entityManager->expects($this->any())
$entity_type_repository = $this->getMockForAbstractClass(EntityTypeRepositoryInterface::class);
$entity_type_repository->expects($this->any())
->method('getEntityTypeFromClass')
->with('Drupal\language\Entity\ContentLanguageSettings')
->with(ContentLanguageSettings::class)
->willReturn('language_content_settings');
\Drupal::getContainer()->set('entity_type.repository', $entity_type_repository);
$config = ContentLanguageSettings::loadByEntityTypeBundle($type, $bundle);
$this->assertSame($expected_langcode, $config->getDefaultLangcode());
......
......@@ -3,6 +3,8 @@
namespace Drupal\Tests\rdf\Unit;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Entity\EntityManager;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Tests\UnitTestCase;
use Drupal\rdf\Entity\RdfMapping;
......@@ -26,6 +28,13 @@ class RdfMappingConfigEntityUnitTest extends UnitTestCase {
*/
protected $entityManager;
/**
* The entity type manager used for testing.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $entityTypeManager;
/**
* The ID of the type of the entity under test.
*
......@@ -51,13 +60,16 @@ protected function setUp() {
->method('getProvider')
->will($this->returnValue('entity'));
$this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface');
$this->entityManager = new EntityManager();
$this->entityTypeManager = $this->getMock(EntityTypeManagerInterface::class);
$this->uuid = $this->getMock('\Drupal\Component\Uuid\UuidInterface');
$container = new ContainerBuilder();
$container->set('entity.manager', $this->entityManager);
$container->set('entity_type.manager', $this->entityTypeManager);
$container->set('uuid', $this->uuid);
$this->entityManager->setContainer($container);
\Drupal::setContainer($container);
}
......@@ -77,11 +89,11 @@ public function testCalculateDependencies() {
->method('getBundleEntityType')
->will($this->returnValue(NULL));
$this->entityManager->expects($this->at(0))
$this->entityTypeManager->expects($this->at(0))
->method('getDefinition')
->with($target_entity_type_id)
->will($this->returnValue($target_entity_type));
$this->entityManager->expects($this->at(1))
$this->entityTypeManager->expects($this->at(1))
->method('getDefinition')
->with($this->entityTypeId)
->will($this->returnValue($this->entityType));
......@@ -108,11 +120,11 @@ public function testCalculateDependenciesWithEntityBundle() {
->method('getBundleConfigDependency')
->will($this->returnValue(['type' => 'config', 'name' => 'test_module.type.' . $bundle_id]));
$this->entityManager->expects($this->at(0))
$this->entityTypeManager->expects($this->at(0))
->method('getDefinition')
->with($target_entity_type_id)
->will($this->returnValue($target_entity_type));
$this->entityManager->expects($this->at(1))
$this->entityTypeManager->expects($this->at(1))
->method('getDefinition')
->with($this->entityTypeId)
->will($this->returnValue($this->entityType));
......
......@@ -3,6 +3,8 @@
namespace Drupal\Tests\responsive_image\Unit;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Entity\EntityTypeRepositoryInterface;
use Drupal\responsive_image\Entity\ResponsiveImageStyle;
use Drupal\Tests\UnitTestCase;
......@@ -20,11 +22,11 @@ class ResponsiveImageStyleConfigEntityUnitTest extends UnitTestCase {
protected $entityType;
/**
* The entity manager used for testing.
* The entity type manager used for testing.
*
* @var \Drupal\Core\Entity\EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject
* @var \Drupal\Core\Entity\EntityTypeManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $entityManager;
protected $entityTypeManager;
/**
* The breakpoint manager used for testing.
......@@ -42,8 +44,8 @@ protected function setUp() {
->method('getProvider')
->will($this->returnValue('responsive_image'));
$this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface');
$this->entityManager->expects($this->any())
$this->entityTypeManager = $this->getMock(EntityTypeManagerInterface::class);
$this->entityTypeManager->expects($this->any())
->method('getDefinition')
->with('responsive_image_style')
->will($this->returnValue($this->entityType));
......@@ -51,7 +53,7 @@ protected function setUp() {
$this->breakpointManager = $this->getMock('\Drupal\breakpoint\BreakpointManagerInterface');
$container = new ContainerBuilder();
$container->set('entity.manager', $this->entityManager);
$container->set('entity_type.manager', $this->entityTypeManager);
$container->set('breakpoint.manager', $this->breakpointManager);
\Drupal::setContainer($container);
}
......@@ -74,11 +76,14 @@ public function testCalculateDependencies() {
->method('loadMultiple')
->with(array_keys($styles))
->willReturn($styles);
$this->entityManager->expects($this->any())
$this->entityTypeManager->expects($this->any())
->method('getStorage')
->with('image_style')
->willReturn($storage);
$this->entityManager->expects($this->any())
$entity_type_repository = $this->getMockForAbstractClass(EntityTypeRepositoryInterface::class);
$entity_type_repository->expects($this->any())
->method('getEntityTypeFromClass')
->with('Drupal\image\Entity\ImageStyle')
->willReturn('image_style');
......@@ -103,6 +108,8 @@ public function testCalculateDependencies() {
->with('test_group')
->willReturn(['bartik' => 'theme', 'toolbar' => 'module']);
\Drupal::getContainer()->set('entity_type.repository', $entity_type_repository);
$dependencies = $entity->calculateDependencies()->getDependencies();
$this->assertEquals(['toolbar'], $dependencies['module']);
$this->assertEquals(['bartik'], $dependencies['theme']);
......
......@@ -3,6 +3,8 @@
namespace Drupal\Tests\user\Unit\Views\Argument;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Entity\EntityManager;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Tests\UnitTestCase;
use Drupal\user\Entity\Role;
use Drupal\user\Plugin\views\argument\RolesRid;
......@@ -44,23 +46,27 @@ public function testTitleQuery() {
->with('label')
->will($this->returnValue('label'));
$entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
$entity_manager->expects($this->any())
$entity_manager = new EntityManager();
$entity_type_manager = $this->getMock(EntityTypeManagerInterface::class);
$entity_type_manager->expects($this->any())
->method('getDefinition')
->with($this->equalTo('user_role'))
->will($this->returnValue($entity_type));
$entity_manager
$entity_type_manager
->expects($this->once())
->method('getStorage')
->with($this->equalTo('user_role'))
->will($this->returnValue($role_storage));
// @todo \Drupal\Core\Entity\Entity::entityType() uses a global call to
// entity_get_info(), which in turn wraps \Drupal::entityManager(). Set