function ContentEntityTest::testTermSource

Same name and namespace in other branches
  1. 9 core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php \Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate\source\ContentEntityTest::testTermSource()
  2. 10 core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php \Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate\source\ContentEntityTest::testTermSource()
  3. 11.x core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php \Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate\source\ContentEntityTest::testTermSource()

Tests term source plugin.

@dataProvider migrationConfigurationProvider

File

core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php, line 437

Class

ContentEntityTest
Tests the entity content source plugin.

Namespace

Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate\source

Code

public function testTermSource(array $configuration) {
    $term2 = Term::create([
        'vid' => $this->vocabulary,
        'name' => 'Granny Smith',
        'uid' => $this->user
            ->id(),
        'parent' => 1,
    ]);
    $term2->save();
    $configuration += [
        'bundle' => $this->vocabulary,
    ];
    $migration = $this->migrationPluginManager
        ->createStubMigration($this->migrationDefinition('content_entity:taxonomy_term', $configuration));
    $term_source = $migration->getSourcePlugin();
    $this->assertSame('taxonomy terms', $term_source->__toString());
    if (!$configuration['include_translations']) {
        $this->assertEquals(2, $term_source->count());
    }
    $this->assertIds($term_source, $configuration);
    $fields = $term_source->fields();
    $this->assertArrayHasKey('vid', $fields);
    $this->assertArrayHasKey('revision_id', $fields);
    $this->assertArrayHasKey('tid', $fields);
    $this->assertArrayHasKey('name', $fields);
    $term_source->rewind();
    $values = $term_source->current()
        ->getSource();
    $this->assertEquals($this->vocabulary, $values['vid'][0]['target_id']);
    $this->assertEquals(1, $values['tid']);
    // @TODO: Add test coverage for parent in
    // https://www.drupal.org/project/drupal/issues/2940198
    $this->assertEquals('Apples', $values['name'][0]['value']);
    $term_source->next();
    $values = $term_source->current()
        ->getSource();
    $this->assertEquals($this->vocabulary, $values['vid'][0]['target_id']);
    $this->assertEquals(2, $values['tid']);
    // @TODO: Add test coverage for parent in
    // https://www.drupal.org/project/drupal/issues/2940198
    $this->assertEquals('Granny Smith', $values['name'][0]['value']);
}

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