function MigrateSqlIdMapTest::testCurrentDestinationAndSource

Same name and namespace in other branches
  1. 8.9.x core/modules/migrate/tests/src/Unit/MigrateSqlIdMapTest.php \Drupal\Tests\migrate\Unit\MigrateSqlIdMapTest::testCurrentDestinationAndSource()
  2. 10 core/modules/migrate/tests/src/Unit/MigrateSqlIdMapTest.php \Drupal\Tests\migrate\Unit\MigrateSqlIdMapTest::testCurrentDestinationAndSource()
  3. 11.x core/modules/migrate/tests/src/Unit/MigrateSqlIdMapTest.php \Drupal\Tests\migrate\Unit\MigrateSqlIdMapTest::testCurrentDestinationAndSource()

Tests currentDestination() and currentSource().

File

core/modules/migrate/tests/src/Unit/MigrateSqlIdMapTest.php, line 659

Class

MigrateSqlIdMapTest
Tests the SQL ID map plugin.

Namespace

Drupal\Tests\migrate\Unit

Code

public function testCurrentDestinationAndSource() {
    // Simple map with one source and one destination ID.
    $id_map = $this->setupRows([
        'nid',
    ], [
        'nid',
    ], [
        [
            1,
            101,
        ],
        [
            2,
            102,
        ],
        [
            3,
            103,
        ],
        // Mock a failed row by setting the destination ID to NULL.
[
            4,
            NULL,
        ],
    ]);
    // The rows are ordered by destination ID so the failed row should be first.
    $id_map->rewind();
    $this->assertEquals([], $id_map->currentDestination());
    $this->assertEquals([
        'nid' => 4,
    ], $id_map->currentSource());
    $id_map->next();
    $this->assertEquals([
        'nid' => 101,
    ], $id_map->currentDestination());
    $this->assertEquals([
        'nid' => 1,
    ], $id_map->currentSource());
    $id_map->next();
    $this->assertEquals([
        'nid' => 102,
    ], $id_map->currentDestination());
    $this->assertEquals([
        'nid' => 2,
    ], $id_map->currentSource());
    $id_map->next();
    $this->assertEquals([
        'nid' => 103,
    ], $id_map->currentDestination());
    $this->assertEquals([
        'nid' => 3,
    ], $id_map->currentSource());
    $id_map->next();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.