function MigrateStubTest::testStubWithDefaultValues

Same name in other branches
  1. 9 core/modules/migrate/tests/src/Kernel/MigrateStubTest.php \Drupal\Tests\migrate\Kernel\MigrateStubTest::testStubWithDefaultValues()
  2. 8.9.x core/modules/migrate/tests/src/Kernel/MigrateStubTest.php \Drupal\Tests\migrate\Kernel\MigrateStubTest::testStubWithDefaultValues()
  3. 10 core/modules/migrate/tests/src/Kernel/MigrateStubTest.php \Drupal\Tests\migrate\Kernel\MigrateStubTest::testStubWithDefaultValues()

Tests stub creation with default values.

File

core/modules/migrate/tests/src/Kernel/MigrateStubTest.php, line 91

Class

MigrateStubTest
Tests the migrate.stub Service.

Namespace

Drupal\Tests\migrate\Kernel

Code

public function testStubWithDefaultValues() : void {
    $this->assertSame([], $this->migrateLookup
        ->lookup('sample_stubbing_migration', [
        17,
    ]));
    $ids = $this->migrateStub
        ->createStub('sample_stubbing_migration', [
        17,
    ], [
        'title' => "Placeholder for source id 17",
    ]);
    $this->assertSame([
        $ids,
    ], $this->migrateLookup
        ->lookup('sample_stubbing_migration', [
        17,
    ]));
    $node = \Drupal::entityTypeManager()->getStorage('node')
        ->load($ids['nid']);
    $this->assertNotNull($node);
    // Test that our default value was set as the node title.
    $this->assertSame("Placeholder for source id 17", $node->label());
    // Test that running the migration replaces the node title.
    $this->executeMigration('sample_stubbing_migration');
    $node = \Drupal::entityTypeManager()->getStorage('node')
        ->loadUnchanged($ids['nid']);
    $this->assertSame("Sample 1", $node->label());
}

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