Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / modules / user / tests / src / Unit / Views / Argument / RolesRidTest.php
index b8f28884260ce605683e3c063ad439e2c76d79b3..4e48fba0307955fb95999be43d5bb9b7ba28e06a 100644 (file)
@@ -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 @@ class RolesRidTest extends UnitTestCase {
       ->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
-    //   the entity manager until this is fixed.
+    // Set up a minimal container to satisfy Drupal\Core\Entity\Entity's
+    // dependency on it.
     $container = new ContainerBuilder();
     $container->set('entity.manager', $entity_manager);
+    $container->set('entity_type.manager', $entity_type_manager);
+    // Inject the container into entity.manager so it can defer to
+    // entity_type.manager.
+    $entity_manager->setContainer($container);
     \Drupal::setContainer($container);
 
     $roles_rid_argument = new RolesRid([], 'user__roles_rid', [], $entity_manager);