Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / tests / Drupal / Tests / Core / Entity / EntityListBuilderTest.php
index 44e771ceaa5b4e9dd02d67a2f2d50e84b5ba72f4..55928b98a6e226ca2040c9f3f499d42e60c5d29f 100644 (file)
@@ -11,6 +11,7 @@ use Drupal\Core\Access\AccessResult;
 use Drupal\Core\DependencyInjection\ContainerBuilder;
 use Drupal\Core\Entity\EntityInterface;
 use Drupal\Core\Entity\EntityListBuilder;
+use Drupal\Core\Routing\RedirectDestinationInterface;
 use Drupal\entity_test\EntityTestListBuilder;
 use Drupal\Tests\UnitTestCase;
 
@@ -62,6 +63,13 @@ class EntityListBuilderTest extends UnitTestCase {
    */
   protected $role;
 
+  /**
+   * The redirect destination service.
+   *
+   * @var \Drupal\Core\Routing\RedirectDestinationInterface|\PHPUnit_Framework_MockObject_MockObject
+   */
+  protected $redirectDestination;
+
   /**
    * The EntityListBuilder object to test.
    *
@@ -80,7 +88,8 @@ class EntityListBuilderTest extends UnitTestCase {
     $this->moduleHandler = $this->getMock('\Drupal\Core\Extension\ModuleHandlerInterface');
     $this->entityType = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface');
     $this->translationManager = $this->getMock('\Drupal\Core\StringTranslation\TranslationInterface');
-    $this->entityListBuilder = new TestEntityListBuilder($this->entityType, $this->roleStorage, $this->moduleHandler);
+    $this->entityListBuilder = new TestEntityListBuilder($this->entityType, $this->roleStorage);
+    $this->redirectDestination = $this->getMock(RedirectDestinationInterface::class);
     $this->container = new ContainerBuilder();
     \Drupal::setContainer($this->container);
   }
@@ -114,15 +123,20 @@ class EntityListBuilderTest extends UnitTestCase {
     $url = $this->getMockBuilder('\Drupal\Core\Url')
       ->disableOriginalConstructor()
       ->getMock();
-    $url->expects($this->any())
-      ->method('toArray')
-      ->will($this->returnValue([]));
+    $url->expects($this->atLeastOnce())
+      ->method('mergeOptions')
+      ->with(['query' => ['destination' => '/foo/bar']]);
     $this->role->expects($this->any())
-      ->method('urlInfo')
+      ->method('toUrl')
       ->will($this->returnValue($url));
 
-    $list = new EntityListBuilder($this->entityType, $this->roleStorage, $this->moduleHandler);
+    $this->redirectDestination->expects($this->atLeastOnce())
+      ->method('getAsArray')
+      ->willReturn(['destination' => '/foo/bar']);
+
+    $list = new EntityListBuilder($this->entityType, $this->roleStorage);
     $list->setStringTranslation($this->translationManager);
+    $list->setRedirectDestination($this->redirectDestination);
 
     $operations = $list->getOperations($this->role);
     $this->assertInternalType('array', $operations);