function MigrateTaxonomyTermStubTest::testStubWithWeightMapping

Same name and namespace in other branches
  1. 9 core/modules/taxonomy/tests/src/Kernel/Migrate/MigrateTaxonomyTermStubTest.php \Drupal\Tests\taxonomy\Kernel\Migrate\MigrateTaxonomyTermStubTest::testStubWithWeightMapping()
  2. 10 core/modules/taxonomy/tests/src/Kernel/Migrate/MigrateTaxonomyTermStubTest.php \Drupal\Tests\taxonomy\Kernel\Migrate\MigrateTaxonomyTermStubTest::testStubWithWeightMapping()
  3. 11.x core/modules/taxonomy/tests/src/Kernel/Migrate/MigrateTaxonomyTermStubTest.php \Drupal\Tests\taxonomy\Kernel\Migrate\MigrateTaxonomyTermStubTest::testStubWithWeightMapping()

Tests creation of stubs when weight is mapped.

File

core/modules/taxonomy/tests/src/Kernel/Migrate/MigrateTaxonomyTermStubTest.php, line 47

Class

MigrateTaxonomyTermStubTest
Test stub creation for taxonomy terms.

Namespace

Drupal\Tests\taxonomy\Kernel\Migrate

Code

public function testStubWithWeightMapping() {
    // Create a vocabulary via migration for the terms to reference.
    $vocabulary_data_rows = [
        [
            'id' => '1',
            'name' => 'tags',
        ],
    ];
    $ids = [
        'id' => [
            'type' => 'integer',
        ],
    ];
    $definition = [
        'migration_tags' => [
            'Stub test',
        ],
        'source' => [
            'plugin' => 'embedded_data',
            'data_rows' => $vocabulary_data_rows,
            'ids' => $ids,
        ],
        'process' => [
            'vid' => 'id',
            'name' => 'name',
        ],
        'destination' => [
            'plugin' => 'entity:taxonomy_vocabulary',
        ],
    ];
    $vocabulary_migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
    $vocabulary_executable = new MigrateExecutable($vocabulary_migration, $this);
    $vocabulary_executable->import();
    // We have a term referencing an unmigrated parent, forcing a stub to be
    // created.
    $migration = $this->getMigration('taxonomy_term_stub_test');
    $term_executable = new MigrateExecutable($migration, $this);
    $term_executable->import();
    $this->assertNotEmpty($migration->getIdMap()
        ->getRowBySource([
        '2',
    ]), 'Stub row exists in the ID map table');
    // Load the referenced term, which should exist as a stub.
    
    /** @var \Drupal\Core\Entity\ContentEntityBase $stub_entity */
    $stub_entity = Term::load(2);
    $this->assertNotEmpty($stub_entity, 'Stub successfully created');
    if ($stub_entity) {
        $this->assertCount(0, $stub_entity->validate(), 'Stub is a valid entity');
    }
}

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