function ContentEntityTest::testTermSource
Same name in other branches
- 9 core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php \Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate\source\ContentEntityTest::testTermSource()
- 8.9.x core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php \Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate\source\ContentEntityTest::testTermSource()
- 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 389
Class
- ContentEntityTest
- Tests the entity content source plugin.
Namespace
Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate\sourceCode
public function testTermSource(array $configuration) : void {
$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']);
$this->assertEquals('Apples', $values['name'][0]['value']);
$this->assertSame([
[
'target_id' => '0',
],
], $values['parent']);
$term_source->next();
$values = $term_source->current()
->getSource();
$this->assertEquals($this->vocabulary, $values['vid'][0]['target_id']);
$this->assertEquals(2, $values['tid']);
$this->assertEquals('Granny Smith', $values['name'][0]['value']);
$this->assertSame([
[
'target_id' => '1',
],
], $values['parent']);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.