You are here

public function MigrateStubTest::testStubWithDefaultValues in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/migrate/tests/src/Kernel/MigrateStubTest.php \Drupal\Tests\migrate\Kernel\MigrateStubTest::testStubWithDefaultValues()
  2. 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 89

Class

MigrateStubTest
Tests the migrate.stub Service.

Namespace

Drupal\Tests\migrate\Kernel

Code

public function testStubWithDefaultValues() {
  $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());
}