Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / tests / Drupal / Tests / Core / ParamConverter / EntityConverterTest.php
index 54fcfbd73d9a603a9584c193b2e662b09f1a7076..b48b9b73a978dab0214ab4497e0dfde8bc2f4af3 100644 (file)
@@ -3,9 +3,15 @@
 namespace Drupal\Tests\Core\ParamConverter;
 
 use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException;
+use Drupal\Core\Entity\ContentEntityInterface;
+use Drupal\Core\Entity\ContentEntityStorageInterface;
+use Drupal\Core\Entity\ContentEntityTypeInterface;
+use Drupal\Core\Language\LanguageInterface;
+use Drupal\Core\Language\LanguageManagerInterface;
 use Drupal\Core\ParamConverter\EntityConverter;
 use Drupal\Core\ParamConverter\ParamNotConvertedException;
 use Drupal\Tests\UnitTestCase;
+use Symfony\Component\DependencyInjection\ContainerInterface;
 use Symfony\Component\Routing\Route;
 
 /**
@@ -130,4 +136,74 @@ class EntityConverterTest extends UnitTestCase {
     $this->entityConverter->convert('id', ['type' => 'entity:{invalid_id}'], 'foo', ['foo' => 'id']);
   }
 
+  /**
+   * Tests that omitting the language manager triggers a deprecation error.
+   *
+   * @group legacy
+   *
+   * @expectedDeprecation The language manager parameter has been added to EntityConverter since version 8.5.0 and will be made required in version 9.0.0 when requesting the latest translation-affected revision of an entity.
+   */
+  public function testDeprecatedOptionalLanguageManager() {
+    $entity = $this->createMock(ContentEntityInterface::class);
+    $entity->expects($this->any())
+      ->method('getEntityTypeId')
+      ->willReturn('entity_test');
+    $entity->expects($this->any())
+      ->method('id')
+      ->willReturn('id');
+    $entity->expects($this->any())
+      ->method('isTranslatable')
+      ->willReturn(FALSE);
+    $entity->expects($this->any())
+      ->method('getLoadedRevisionId')
+      ->willReturn('revision_id');
+
+    $storage = $this->createMock(ContentEntityStorageInterface::class);
+    $storage->expects($this->any())
+      ->method('load')
+      ->with('id')
+      ->willReturn($entity);
+    $storage->expects($this->any())
+      ->method('getLatestRevisionId')
+      ->with('id')
+      ->willReturn('revision_id');
+
+    $this->entityManager->expects($this->any())
+      ->method('getStorage')
+      ->with('entity_test')
+      ->willReturn($storage);
+
+    $entity_type = $this->createMock(ContentEntityTypeInterface::class);
+    $entity_type->expects($this->any())
+      ->method('isRevisionable')
+      ->willReturn(TRUE);
+
+    $this->entityManager->expects($this->any())
+      ->method('getDefinition')
+      ->with('entity_test')
+      ->willReturn($entity_type);
+
+    $language = $this->createMock(LanguageInterface::class);
+    $language->expects($this->any())
+      ->method('getId')
+      ->willReturn('en');
+
+    $language_manager = $this->createMock(LanguageManagerInterface::class);
+    $language_manager->expects($this->any())
+      ->method('getCurrentLanguage')
+      ->with(LanguageInterface::TYPE_CONTENT)
+      ->willReturn($language);
+
+    /** @var \Symfony\Component\DependencyInjection\ContainerInterface|\PHPUnit_Framework_MockObject_MockObject $container */
+    $container = $this->createMock(ContainerInterface::class);
+    $container->expects($this->any())
+      ->method('get')
+      ->with('language_manager')
+      ->willReturn($language_manager);
+
+    \Drupal::setContainer($container);
+    $definition = ['type' => 'entity:entity_test', 'load_latest_revision' => TRUE];
+    $this->entityConverter->convert('id', $definition, 'foo', []);
+  }
+
 }