function MigrateStubTest::testStubWithBundleFields

Same name and namespace in other branches
  1. 10 core/modules/migrate/tests/src/Kernel/MigrateStubTest.php \Drupal\Tests\migrate\Kernel\MigrateStubTest::testStubWithBundleFields()
  2. 11.x core/modules/migrate/tests/src/Kernel/MigrateStubTest.php \Drupal\Tests\migrate\Kernel\MigrateStubTest::testStubWithBundleFields()

Tests stub creation with bundle fields.

File

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

Class

MigrateStubTest
Tests the migrate.stub Service.

Namespace

Drupal\Tests\migrate\Kernel

Code

public function testStubWithBundleFields() {
    $this->createContentType([
        'type' => 'node_stub',
    ]);
    // Make "Body" field required to make stubbing populate field value.
    $body_field = FieldConfig::loadByName('node', 'node_stub', 'body');
    $body_field->setRequired(TRUE)
        ->save();
    $this->assertSame([], $this->migrateLookup
        ->lookup('sample_stubbing_migration', [
        33,
    ]));
    $ids = $this->migrateStub
        ->createStub('sample_stubbing_migration', [
        33,
    ], []);
    $this->assertSame([
        $ids,
    ], $this->migrateLookup
        ->lookup('sample_stubbing_migration', [
        33,
    ]));
    $node = \Drupal::entityTypeManager()->getStorage('node')
        ->load($ids['nid']);
    $this->assertNotNull($node);
    // Make sure the "Body" field value was populated.
    $this->assertNotEmpty($node->get('body')->value);
}

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