You are here

class IteratorTest in Drupal 8

Tests the iterator process plugin.

@group migrate

Hierarchy

Expanded class hierarchy of IteratorTest

File

core/modules/migrate/tests/src/Unit/process/IteratorTest.php, line 16

Namespace

Drupal\Tests\migrate\Unit\process
View source
class IteratorTest extends MigrateTestCase {

  /**
   * The iterator plugin being tested.
   *
   * @var \Drupal\migrate\Plugin\migrate\process\Iterator
   */
  protected $plugin;

  /**
   * @var array
   */
  protected $migrationConfiguration = [
    'id' => 'test',
  ];

  /**
   * Tests the iterator process plugin.
   *
   * @group legacy
   * @expectedDeprecation The Drupal\migrate\Plugin\migrate\process\Iterator is deprecated in Drupal 8.4.x and will be removed before Drupal 9.0.0. Instead, use Drupal\migrate\Plugin\migrate\process\SubProcess
   */
  public function testIterator() {
    $migration = $this
      ->getMigration();

    // Set up the properties for the iterator.
    $configuration = [
      'process' => [
        'foo' => 'source_foo',
        'id' => 'source_id',
      ],
      'key' => '@id',
    ];
    $plugin = new Iterator($configuration, 'iterator', []);

    // Manually create the plugins. Migration::getProcessPlugins does this
    // normally but the plugin system is not available.
    foreach ($configuration['process'] as $destination => $source) {
      $iterator_plugins[$destination][] = new Get([
        'source' => $source,
      ], 'get', []);
    }
    $migration
      ->expects($this
      ->at(1))
      ->method('getProcessPlugins')
      ->will($this
      ->returnValue($iterator_plugins));

    // Set up the key plugins.
    $key_plugin['key'][] = new Get([
      'source' => '@id',
    ], 'get', []);
    $migration
      ->expects($this
      ->at(2))
      ->method('getProcessPlugins')
      ->will($this
      ->returnValue($key_plugin));
    $event_dispatcher = $this
      ->createMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
    $migrate_executable = new MigrateExecutable($migration, $this
      ->createMock('Drupal\\migrate\\MigrateMessageInterface'), $event_dispatcher);

    // The current value of the pipeline.
    $current_value = [
      [
        'source_foo' => 'test',
        'source_id' => 42,
      ],
    ];

    // This is not used but the interface requires it, so create an empty row.
    $row = new Row();

    // After transformation, check to make sure that source_foo and source_id's
    // values ended up in the proper destinations, and that the value of the
    // key (@id) is the same as the destination ID (42).
    $new_value = $plugin
      ->transform($current_value, $migrate_executable, $row, 'test');
    $this
      ->assertCount(1, $new_value);
    $this
      ->assertCount(2, $new_value[42]);
    $this
      ->assertSame('test', $new_value[42]['foo']);
    $this
      ->assertSame(42, $new_value[42]['id']);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
IteratorTest::$migrationConfiguration protected property Overrides MigrateTestCase::$migrationConfiguration
IteratorTest::$plugin protected property The iterator plugin being tested.
IteratorTest::testIterator public function Tests the iterator process plugin.
MigrateTestCase::$idMap protected property The migration ID map.
MigrateTestCase::$migrationStatus protected property Local store for mocking setStatus()/getStatus().
MigrateTestCase::createSchemaFromRow protected function Generates a table schema from a row.
MigrateTestCase::getDatabase protected function Gets an SQLite database connection object for use in tests.
MigrateTestCase::getMigration protected function Retrieves a mocked migration. 1
MigrateTestCase::getValue protected function Gets the value on a row for a given key. 1
MigrateTestCase::queryResultTest public function Tests a query.
MigrateTestCase::retrievalAssertHelper protected function Asserts tested values during test retrieval.
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.
UnitTestCase::setUp protected function 340