diff --git a/core/modules/migrate/tests/src/Unit/MigrateTestCase.php b/core/modules/migrate/tests/src/Unit/MigrateTestCase.php index 75348fa..b1f8dbc 100644 --- a/core/modules/migrate/tests/src/Unit/MigrateTestCase.php +++ b/core/modules/migrate/tests/src/Unit/MigrateTestCase.php @@ -24,13 +24,14 @@ * The mocked migration. */ protected function getMigration() { + $this->migrationConfiguration += ['migrationClass' => 'Drupal\migrate\Entity\Migration']; $this->idMap = $this->getMock('Drupal\migrate\Plugin\MigrateIdMapInterface'); $this->idMap->expects($this->any()) ->method('getQualifiedMapTableName') ->will($this->returnValue('test_map')); - $migration = $this->getMockBuilder('Drupal\migrate\Entity\Migration') + $migration = $this->getMockBuilder($this->migrationConfiguration['migrationClass']) ->disableOriginalConstructor() ->getMock(); $migration->expects($this->any()) diff --git a/core/modules/migrate_drupal/src/MigrationStorage.php b/core/modules/migrate_drupal/src/MigrationStorage.php index 28afe63..e495122 100644 --- a/core/modules/migrate_drupal/src/MigrationStorage.php +++ b/core/modules/migrate_drupal/src/MigrationStorage.php @@ -58,6 +58,7 @@ public function loadMultiple(array $ids = NULL) { foreach ($entities as $entity_id => $entity) { if ($plugin = $entity->getLoadPlugin()) { $new_entities = $plugin->loadMultiple($this); + $this->postLoad($new_entities); $this->getDynamicIds($dynamic_ids, $new_entities); $return += $new_entities; } @@ -73,6 +74,7 @@ public function loadMultiple(array $ids = NULL) { if ($plugin = $entity->getLoadPlugin()) { unset($entities[$base_id]); $new_entities = $plugin->loadMultiple($this, $sub_ids); + $this->postLoad($new_entities); if (!isset($sub_ids)) { unset($dynamic_ids[$base_id]); $this->getDynamicIds($dynamic_ids, $new_entities); diff --git a/core/modules/migrate_drupal/tests/src/Unit/MigrationStorageTest.php b/core/modules/migrate_drupal/tests/src/Unit/MigrationStorageTest.php new file mode 100644 index 0000000..f1a5f70 --- /dev/null +++ b/core/modules/migrate_drupal/tests/src/Unit/MigrationStorageTest.php @@ -0,0 +1,78 @@ + 'test_migration', 'migrationClass' => 'Drupal\migrate_drupal\Entity\Migration'); + + /** + * Test that the entity load hooks are called on dynamic migrations. + * + * @dataProvider entityIdsDataProvider + */ + public function testMigrationStorage($entity_ids) { + $entity_type = $this->getMock('Drupal\Core\Entity\EntityTypeInterface'); + $entity_type + ->expects($this->exactly(2)) + ->method('isStaticallyCacheable') + ->willReturn(FALSE); + + $load_plugin = $this->getMock('Drupal\migrate_drupal\Plugin\MigrateLoadInterface'); + $load_plugin + ->expects($this->once(1)) + ->method('loadMultiple') + ->willReturn([]); + + $migration = $this->getMigration(); + $migration + ->expects($this->once()) + ->method('getLoadPlugin') + ->willReturn($load_plugin); + + $storage = $this->getMock('Drupal\migrate_drupal\TestMigrationStorage', ['postLoad', 'doLoadMultiple'], [$entity_type]); + $storage + ->expects($this->exactly(2)) + ->method('postLoad'); + $storage + ->expects($this->once()) + ->method('doLoadMultiple') + ->willReturn(['test_migration' => $migration]); + + $storage->loadMultiple($entity_ids); + } + + /** + * The data provider for migration storage. + * + * @return array + * The entity ids. + */ + public function entityIdsDataProvider() { + return [ + [['test_migration:bundle']], + [NULL], + ]; + } + +} + +namespace Drupal\migrate_drupal; + +class TestMigrationStorage extends MigrationStorage { + public function __construct($entity_type) { + $this->entityType = $entity_type; + } +}