diff --git a/core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php b/core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php index 15454f1fa1..3e18d28b1a 100644 --- a/core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php +++ b/core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php @@ -189,7 +189,7 @@ public function getIds() { if ($this->isTranslationDestination()) { $langcode_key = $this->getKey('langcode'); if (!$langcode_key) { - throw new MigrateException('This entity type does not support translations.'); + throw new MigrateException(sprintf('The "%s" entity type does not support translations.', $this->storage->getEntityTypeId())); } $ids[$langcode_key] = $this->getDefinitionFromEntity($langcode_key); } diff --git a/core/modules/migrate/src/Plugin/migrate/destination/EntityRevision.php b/core/modules/migrate/src/Plugin/migrate/destination/EntityRevision.php index 04efe530e0..ff3f0071c7 100644 --- a/core/modules/migrate/src/Plugin/migrate/destination/EntityRevision.php +++ b/core/modules/migrate/src/Plugin/migrate/destination/EntityRevision.php @@ -183,14 +183,14 @@ public function getIds() { $revision_key = $this->getKey('revision'); if (!$revision_key) { - throw new MigrateException('This entity type does not support revisions.'); + throw new MigrateException(sprintf('The "%s" entity type does not support revisions.', $this->storage->getEntityTypeId())); } $ids[$revision_key] = $this->getDefinitionFromEntity($revision_key); if ($this->isTranslationDestination()) { $langcode_key = $this->getKey('langcode'); if (!$langcode_key) { - throw new MigrateException('This entity type does not support translations.'); + throw new MigrateException(sprintf('The "%s" entity type does not support translations.', $this->storage->getEntityTypeId())); } $ids[$langcode_key] = $this->getDefinitionFromEntity($langcode_key); } diff --git a/core/modules/migrate/tests/src/Unit/Plugin/migrate/destination/EntityContentBaseTest.php b/core/modules/migrate/tests/src/Unit/Plugin/migrate/destination/EntityContentBaseTest.php index 9f43523560..d0fd987dc3 100644 --- a/core/modules/migrate/tests/src/Unit/Plugin/migrate/destination/EntityContentBaseTest.php +++ b/core/modules/migrate/tests/src/Unit/Plugin/migrate/destination/EntityContentBaseTest.php @@ -60,6 +60,7 @@ protected function setUp() { $this->entityType = $this->prophesize(EntityTypeInterface::class); $this->entityType->getPluralLabel()->willReturn('wonkiness'); $this->storage->getEntityType()->willReturn($this->entityType->reveal()); + $this->storage->getEntityTypeId()->willReturn('foo'); $this->entityManager = $this->prophesize(EntityManagerInterface::class); } @@ -129,7 +130,7 @@ public function testUntranslatable() { $this->entityManager->reveal(), $this->prophesize(FieldTypePluginManagerInterface::class)->reveal() ); - $this->setExpectedException(MigrateException::class, 'This entity type does not support translation'); + $this->setExpectedException(MigrateException::class, 'The "foo" entity type does not support translations.'); $destination->getIds(); } diff --git a/core/modules/migrate/tests/src/Unit/Plugin/migrate/destination/EntityRevisionTest.php b/core/modules/migrate/tests/src/Unit/Plugin/migrate/destination/EntityRevisionTest.php new file mode 100644 index 0000000000..3fb4b7dbda --- /dev/null +++ b/core/modules/migrate/tests/src/Unit/Plugin/migrate/destination/EntityRevisionTest.php @@ -0,0 +1,162 @@ +migration = $this->prophesize(MigrationInterface::class); + $this->storage = $this->prophesize(EntityStorageInterface::class); + + $this->entityType = $this->prophesize(EntityTypeInterface::class); + $this->entityType->getSingularLabel()->willReturn('foo'); + $this->entityType->getPluralLabel()->willReturn('bar'); + $this->storage->getEntityType()->willReturn($this->entityType->reveal()); + $this->storage->getEntityTypeId()->willReturn('foo'); + + $this->entityManager = $this->prophesize(EntityManagerInterface::class); + } + + /** + * Tests that revision destination fails for unrevisionable entities. + */ + public function testUnrevisionable() { + $this->entityType->getKey('id')->willReturn('id'); + $this->entityType->getKey('revision')->willReturn(''); + $this->entityManager->getBaseFieldDefinitions('foo') + ->willReturn([ + 'id' => BaseFieldDefinitionTest::create('integer'), + ]); + + $destination = new EntityRevisionTestDestination( + [], + '', + [], + $this->migration->reveal(), + $this->storage->reveal(), + [], + $this->entityManager->reveal(), + $this->prophesize(FieldTypePluginManagerInterface::class)->reveal() + ); + $this->setExpectedException(MigrateException::class, 'The "foo" entity type does not support revisions.'); + $destination->getIds(); + } + + /** + * Tests that translation destination fails for untranslatable entities. + */ + public function testUntranslatable() { + $this->entityType->getKey('id')->willReturn('id'); + $this->entityType->getKey('revision')->willReturn('vid'); + $this->entityType->getKey('langcode')->willReturn(''); + $this->entityManager->getBaseFieldDefinitions('foo') + ->willReturn([ + 'id' => BaseFieldDefinitionTest::create('integer'), + 'vid' => BaseFieldDefinitionTest::create('integer'), + ]); + + $destination = new EntityRevisionTestDestination( + ['translations' => TRUE], + '', + [], + $this->migration->reveal(), + $this->storage->reveal(), + [], + $this->entityManager->reveal(), + $this->prophesize(FieldTypePluginManagerInterface::class)->reveal() + ); + $this->setExpectedException(MigrateException::class, 'The "foo" entity type does not support translations.'); + $destination->getIds(); + } + +} + +/** + * Stub class for testing EntityRevision methods. + */ +class EntityRevisionTestDestination extends EntityRevision { + + private $entity = NULL; + + public function setEntity($entity) { + $this->entity = $entity; + } + + protected function getEntity(Row $row, array $old_destination_id_values) { + return $this->entity; + } + + public static function getEntityTypeId($plugin_id) { + return 'foo'; + } + +} + +/** + * Stub class for BaseFieldDefinition. + */ +class BaseFieldDefinitionTest extends BaseFieldDefinition { + + public static function create($type) { + return new static([]); + } + + public function getSettings() { + return []; + } + + public function getType() { + return 'integer'; + } + +} diff --git a/core/modules/migrate_drupal/tests/src/Kernel/d6/EntityContentBaseTest.php b/core/modules/migrate_drupal/tests/src/Kernel/d6/EntityContentBaseTest.php index 6be7801b6e..db44c63450 100644 --- a/core/modules/migrate_drupal/tests/src/Kernel/d6/EntityContentBaseTest.php +++ b/core/modules/migrate_drupal/tests/src/Kernel/d6/EntityContentBaseTest.php @@ -115,7 +115,7 @@ public function testUntranslatable() { // Match the expected message. Can't use default argument types, because // we need to convert to string from TranslatableMarkup. $argument = Argument::that(function ($msg) { - return strpos((string) $msg, "This entity type does not support translation") !== FALSE; + return strpos((string) $msg, htmlentities('The "no_language_entity_test" entity type does not support translations.')) !== FALSE; }); $message->display($argument, Argument::any()) ->shouldBeCalled();