Row example

if ($this->configuration['include_source']) {
      $key = $this->configuration['source_key'];
      $source[$key] = $row->getSource();
    }

    if (is_array($value) || $value instanceof \Traversable) {
      foreach ($value as $key => $new_value) {
        if (!is_array($new_value)) {
          throw new MigrateException(sprintf("Input array should hold elements of type array, instead element was of type '%s'", gettype($new_value)));
        }
        $new_row = new Row($new_value + $source);
        $migrate_executable->processRow($new_row$this->configuration['process']);
        $destination = $new_row->getDestination();
        if (array_key_exists('key', $this->configuration)) {
          $key = $this->transformKey($key$migrate_executable$new_row);
        }
        // Do not save the result if the key is NULL. The configured process         // pipeline used in transformKey() will return NULL if a         // MigrateSkipProcessException is thrown.         // @see \Drupal\filter\Plugin\migrate\process\FilterID         if ($key !== NULL) {
          $return[$key] = $destination;
        }

  protected function doTransform($destination_uri$configuration = []) {
    // Prepare a mock HTTP client.     $this->container->set('http_client', $this->createMock(Client::class));

    // Instantiate the plugin statically so it can pull dependencies out of     // the container.     $plugin = Download::create($this->container, $configuration, 'download', []);

    // Execute the transformation.     $executable = $this->createMock(MigrateExecutableInterface::class);
    $row = new Row([][]);

    // Return the downloaded file's local URI.     $value = [
      'http://drupal.org/favicon.ico',
      $destination_uri,
    ];

    // Assert that number of stream resources in use is the same before and     // after the download.     $initial_count = count(get_resources('stream'));
    $return = $plugin->transform($value$executable$row, 'foo');
    

  public function testSaveIdMapping() {
    $source = [
      'source_id_property' => 'source_value',
    ];
    $row = new Row($source['source_id_property' => []]);
    $id_map = $this->getIdMap();
    $id_map->saveIdMapping($row['destination_id_property' => 2]);
    $expected_result = [
      [
        'sourceid1' => 'source_value',
        'source_ids_hash' => $this->getIdMap()->getSourceIdsHash($source),
        'destid1' => 2,
      ] + $this->idMapDefaults(),
    ];
    $this->queryResultTest($this->getIdMapContents()$expected_result);
    $source = [
      

  protected function createEntityStub($entity_type_id) {
    // Create a dummy migration to pass to the destination plugin.     $definition = [
      'migration_tags' => ['Stub test'],
      'source' => ['plugin' => 'empty'],
      'process' => [],
      'destination' => ['plugin' => 'entity:' . $entity_type_id],
    ];
    $migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
    $destination_plugin = $migration->getDestinationPlugin(TRUE);
    $stub_row = new Row([][], TRUE);
    $destination_ids = $destination_plugin->import($stub_row);
    return reset($destination_ids);
  }

  /** * Perform validation on a stub entity. * * @param string $entity_type_id * The entity type we are stubbing. * @param string $entity_id * ID of the stubbed entity to validate. * * @return \Drupal\Core\Entity\EntityConstraintViolationListInterface * List of constraint violations identified. */
// New translation.       ['id' => 2, 'langcode' => 'en', 'action' => MigrateIdMapInterface::ROLLBACK_DELETE],
      // Existing non-default translation.       ['id' => 3, 'langcode' => 'fr', 'action' => MigrateIdMapInterface::ROLLBACK_PRESERVE],
      // Brand new row.       ['id' => 4, 'langcode' => 'fr', 'action' => MigrateIdMapInterface::ROLLBACK_DELETE],
    ];
    $rollback_actions = [];

    // Import some rows.     foreach ($destination_rows as $idx => $destination_row) {
      $row = new Row();
      foreach ($destination_row as $key => $value) {
        $row->setDestinationProperty($key$value);
      }
      $this->destination->import($row);

      // Check that the rollback action is correct, and save it.       $this->assertEquals($destination_row['action']$this->destination->rollbackAction());
      $rollback_actions[$idx] = $this->destination->rollbackAction();
    }

    $this->assertTranslations(1, 'en');
    
'url' => [
        'value' => Url::fromUri('https://en.wikipedia.org/wiki/Drupal#Community'),
        'expected_message' => "'foo' value is Drupal\Core\Url:\n'https://en.wikipedia.org/wiki/Drupal#Community'",
      ],
    ];

    $i = 1;
    foreach ($data as $datum) {
      $this->executable->sourceIdValues = ['id' => $i++];

      // Test the input value is not altered.       $new_value = $this->logPlugin->transform($datum['value']$this->executable, new Row(), 'foo');
      $this->assertSame($datum['value']$new_value);

      // Test the stored message.       $message = $this->executable->getIdMap()
        ->getMessages($this->executable->sourceIdValues)
        ->fetchAllAssoc('message');
      $actual_message = key($message);
      $this->assertSame($datum['expected_message']$actual_message);
    }
  }

}
$plugins[$key][0]->expects($this->once())
        ->method('getPluginDefinition')
        ->willReturn([]);
      $plugins[$key][0]->expects($this->once())
        ->method('transform')
        ->willReturn($value);
    }
    $this->migration->expects($this->once())
      ->method('getProcessPlugins')
      ->with(NULL)
      ->willReturn($plugins);
    $row = new Row();
    $this->executable->processRow($row);
    foreach ($expected as $key => $value) {
      $this->assertSame($row->getDestinationProperty($key)$value);
    }
    $this->assertSameSize($expected$row->getDestination());
  }

  /** * Tests the processRow method with an empty pipeline. */
  public function testProcessRowEmptyPipeline() {
    

      $this->randomMachineName(),
      [],
      $this->container->get('stream_wrapper_manager'),
      $this->container->get('file_system'),
      $download_plugin
    );

    $plugin->transform(
      ['http://drupal.org/favicon.ico', '/destination/path'],
      $this->createMock(MigrateExecutableInterface::class),
      new Row([][]),
      $this->randomMachineName()
    );
  }

  /** * Do an import using the destination. * * @param string $source_path * Source path to copy from. * @param string $destination_path * The destination path to copy to. * @param array $configuration * Process plugin configuration settings. * * @return string * The URI of the copied file. */

  protected function doCreateStub(MigrationInterface $migration, array $source_ids, array $default_values = []) {
    $destination = $migration->getDestinationPlugin(TRUE);
    $process = $migration->getProcess();
    $id_map = $migration->getIdMap();
    $migrate_executable = new MigrateExecutable($migration);
    $row = new Row($source_ids + $migration->getSourceConfiguration()$migration->getSourcePlugin()->getIds(), TRUE);
    $migrate_executable->processRow($row$process);
    foreach ($default_values as $key => $value) {
      $row->setDestinationProperty($key$value);
    }
    $destination_ids = [];
    try {
      $destination_ids = $destination->import($row);
    }
    catch (\Exception $e) {
      $id_map->saveMessage($row->getSourceIdValues()$e->getMessage());
    }
    
#[\ReturnTypeWillChange]   public function next() {
    $this->currentSourceIds = NULL;
    $this->currentRow = NULL;

    // In order to find the next row we want to process, we ask the source     // plugin for the next possible row.     while (!isset($this->currentRow) && $this->getIterator()->valid()) {

      $row_data = $this->getIterator()->current() + $this->configuration;
      $this->fetchNextRow();
      $row = new Row($row_data$this->getIds());

      // Populate the source key for this row.       $this->currentSourceIds = $row->getSourceIdValues();

      // Pick up the existing map row, if any, unless fetchNextRow() did it.       if (!$this->mapRowAdded && ($id_map = $this->idMap->getRowBySource($this->currentSourceIds))) {
        $row->setIdMap($id_map);
      }

      // Clear any previous messages for this row before potentially adding       // new ones.

  public function testGetEntityDestinationValues() {
    $destination = $this->getEntityRevisionDestination([]);
    // Return a dummy because we don't care what gets called.     $entity = $this->prophesize('\Drupal\Core\Entity\RevisionableInterface');
    // Assert that the first ID from the destination values is used to load the     // entity.     $this->storage->loadRevision(12)
      ->shouldBeCalled()
      ->willReturn($entity->reveal());
    $row = new Row();
    $this->assertEquals($entity->reveal()$destination->getEntity($row[12, 13]));
  }

  /** * Tests that revision updates update. * * @covers ::getEntity */
  public function testGetEntityUpdateRevision() {
    $destination = $this->getEntityRevisionDestination([]);
    $entity = $this->prophesize('\Drupal\Core\Entity\RevisionableInterface');

    
/** * Tests the entity display import method. */
  public function testImport() {
    $values = [
      'entity_type' => 'entity_type_test',
      'bundle' => 'bundle_test',
      'view_mode' => 'view_mode_test',
      'field_name' => 'field_name_test',
      'options' => ['test setting'],
    ];
    $row = new Row();
    foreach ($values as $key => $value) {
      $row->setDestinationProperty($key$value);
    }
    $entity = $this->getMockBuilder('Drupal\Core\Entity\Entity\EntityViewDisplay')
      ->disableOriginalConstructor()
      ->getMock();
    $entity->expects($this->once())
      ->method('setComponent')
      ->with('field_name_test', ['test setting'])
      ->will($this->returnSelf());
    $entity->expects($this->once())
      
'image', 'imagefield_widget'],
      ['file', 'filefield_widget'],
      ['file', 'x_widget'],
    ];
  }

  /** * @covers ::getFieldType * @dataProvider getFieldTypeProvider */
  public function testGetFieldType($expected_type$widget_type, array $settings = []) {
    $row = new Row();
    $row->setSourceProperty('widget_type', $widget_type);
    $row->setSourceProperty('global_settings', $settings);
    $this->assertSame($expected_type$this->plugin->getFieldType($row));
  }

}
/** * Tests basic row preparation. * * @covers ::prepareRow */
  public function testPrepareRow() {
    $this->migrationConfiguration['id'] = 'test_migration';

    // Get a new migration with an id.     $migration = $this->getMigration();
    $source = new StubSourcePlugin([], '', []$migration);
    $row = new Row();

    $module_handler = $this->prophesize(ModuleHandlerInterface::class);
    $module_handler->invokeAll('migrate_prepare_row', [$row$source$migration])
      ->willReturn([TRUE, TRUE])
      ->shouldBeCalled();
    $module_handler->invokeAll('migrate_' . $migration->id() . '_prepare_row', [$row$source$migration])
      ->willReturn([TRUE, TRUE])
      ->shouldBeCalled();
    $source->setModuleHandler($module_handler->reveal());

    // Ensure we don't log this to the mapping table.
// Pre-create a term, to make sure it isn't deleted on rollback.     $preserved_term_ids[] = 1;
    $new_term = Term::create(['tid' => 1, 'vid' => 1, 'name' => 'music']);
    $new_term->save();

    // Import and validate term entities were created.     $term_executable = new MigrateExecutable($term_migration$this);
    $term_executable->import();
    // Also explicitly mark one row to be preserved on rollback.     $preserved_term_ids[] = 2;
    $map_row = $term_id_map->getRowBySource(['id' => 2]);
    $dummy_row = new Row(['id' => 2]$ids);
    $term_id_map->saveIdMapping($dummy_row[$map_row['destid1']],
      $map_row['source_row_status'], MigrateIdMapInterface::ROLLBACK_PRESERVE);

    foreach ($term_data_rows as $row) {
      /** @var \Drupal\taxonomy\Entity\Term $term */
      $term = Term::load($row['id']);
      $this->assertNotEmpty($term);
      $map_row = $term_id_map->getRowBySource(['id' => $row['id']]);
      $this->assertNotNull($map_row['destid1']);
    }

    
Home | Imprint | This part of the site doesn't use cookies.