View source  
  <?php
namespace Drupal\Tests\migrate\Unit\process;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate\Plugin\migrate\process\Get;
use Drupal\migrate\Plugin\migrate\process\Iterator;
use Drupal\migrate\Row;
use Drupal\Tests\migrate\Unit\MigrateTestCase;
class IteratorTest extends MigrateTestCase {
  
  protected $plugin;
  
  protected $migrationConfiguration = array(
    'id' => 'test',
  );
  
  public function testIterator() {
    $migration = $this
      ->getMigration();
    
    $configuration = array(
      'process' => array(
        'foo' => 'source_foo',
        'id' => 'source_id',
      ),
      'key' => '@id',
    );
    $plugin = new Iterator($configuration, 'iterator', array());
    
    foreach ($configuration['process'] as $destination => $source) {
      $iterator_plugins[$destination][] = new Get(array(
        'source' => $source,
      ), 'get', array());
    }
    $migration
      ->expects($this
      ->at(1))
      ->method('getProcessPlugins')
      ->will($this
      ->returnValue($iterator_plugins));
    
    $key_plugin['key'][] = new Get(array(
      'source' => '@id',
    ), 'get', array());
    $migration
      ->expects($this
      ->at(2))
      ->method('getProcessPlugins')
      ->will($this
      ->returnValue($key_plugin));
    $event_dispatcher = $this
      ->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
    $migrate_executable = new MigrateExecutable($migration, $this
      ->getMock('Drupal\\migrate\\MigrateMessageInterface'), $event_dispatcher);
    
    $current_value = array(
      array(
        'source_foo' => 'test',
        'source_id' => 42,
      ),
    );
    
    $row = new Row(array(), array());
    
    $new_value = $plugin
      ->transform($current_value, $migrate_executable, $row, 'test');
    $this
      ->assertSame(count($new_value), 1);
    $this
      ->assertSame(count($new_value[42]), 2);
    $this
      ->assertSame($new_value[42]['foo'], 'test');
    $this
      ->assertSame($new_value[42]['id'], 42);
  }
}