示例#1
0
 /**
  * Test row skipping when we can't get an entity to save.
  *
  * @covers ::import
  * @expectedException \Drupal\migrate\MigrateException
  * @expectedExceptionMessage Unable to get entity
  */
 public function testImportEntityLoadFailure()
 {
     $bundles = [];
     $destination = new EntityTestDestination([], '', [], $this->migration->reveal(), $this->storage->reveal(), $bundles, $this->entityManager->reveal(), $this->prophesize(FieldTypePluginManagerInterface::class)->reveal());
     $destination->setEntity(FALSE);
     $destination->import(new Row([], []));
 }
 /**
  * Test that translation destination fails for untranslatable entities.
  *
  * @expectedException \Drupal\migrate\MigrateException
  * @expectedExceptionMessage This entity type does not support translation
  */
 public function testUntranslatable()
 {
     // An entity type without a language.
     $entity_type = $this->prophesize(ContentEntityType::class);
     $entity_type->getKey('langcode')->willReturn('');
     $entity_type->getKey('id')->willReturn('id');
     $this->storage->getEntityType()->willReturn($entity_type->reveal());
     $destination = new EntityTestDestination(['translations' => TRUE], '', [], $this->migration->reveal(), $this->storage->reveal(), [], $this->entityManager->reveal(), $this->prophesize(FieldTypePluginManagerInterface::class)->reveal());
     $destination->getIds();
 }
 /**
  * Instantiates the source plugin under test.
  *
  * @param array $configuration
  *   The source plugin configuration.
  *
  * @return \Drupal\migrate\Plugin\MigrateSourceInterface|object
  *   The fully configured source plugin.
  */
 protected function getPlugin(array $configuration)
 {
     // Only create the plugin once per test.
     if ($this->plugin) {
         return $this->plugin;
     }
     $class = ltrim($this->getPluginClass(), '\\');
     /** @var \Drupal\migrate\Plugin\MigratePluginManager $plugin_manager */
     $plugin_manager = $this->container->get('plugin.manager.migrate.source');
     foreach ($plugin_manager->getDefinitions() as $id => $definition) {
         if (ltrim($definition['class'], '\\') == $class) {
             $this->plugin = $plugin_manager->createInstance($id, $configuration, $this->migration->reveal());
             $this->migration->getSourcePlugin()->willReturn($this->plugin);
             return $this->plugin;
         }
     }
     $this->fail('No plugin found for class ' . $class);
 }
示例#4
0
 /**
  * Helper method to create an entity revision destination with mock services.
  *
  * @see \Drupal\Tests\migrate\Unit\Destination\EntityRevision
  *
  * @param $configuration
  *   Configuration for the destination.
  * @param string $plugin_id
  *   The plugin id.
  * @param array $plugin_definition
  *   The plugin definition.
  *
  * @return \Drupal\Tests\migrate\Unit\destination\EntityRevision
  *   Mocked destination.
  */
 protected function getEntityRevisionDestination(array $configuration = [], $plugin_id = 'entity_revision', array $plugin_definition = [])
 {
     return new EntityRevision($configuration, $plugin_id, $plugin_definition, $this->migration->reveal(), $this->storage->reveal(), [], $this->entityManager->reveal(), $this->fieldTypeManager->reveal());
 }