class MigrateTaxonomyTermStubTest
Same name and namespace in other branches
- 11.x core/modules/taxonomy/tests/src/Kernel/Migrate/MigrateTaxonomyTermStubTest.php \Drupal\Tests\taxonomy\Kernel\Migrate\MigrateTaxonomyTermStubTest
- 10 core/modules/taxonomy/tests/src/Kernel/Migrate/MigrateTaxonomyTermStubTest.php \Drupal\Tests\taxonomy\Kernel\Migrate\MigrateTaxonomyTermStubTest
- 8.9.x core/modules/taxonomy/tests/src/Kernel/Migrate/MigrateTaxonomyTermStubTest.php \Drupal\Tests\taxonomy\Kernel\Migrate\MigrateTaxonomyTermStubTest
Test stub creation for taxonomy terms.
@group taxonomy
Hierarchy
- class \Drupal\KernelTests\KernelTestBase extends \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\KernelTests\AssertLegacyTrait, \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait implements \PHPUnit\Framework\TestCase
- class \Drupal\Tests\migrate\Kernel\MigrateTestBase extends \Drupal\migrate\MigrateMessageInterface implements \Drupal\KernelTests\KernelTestBase
- class \Drupal\Tests\migrate_drupal\Kernel\MigrateDrupalTestBase implements \Drupal\Tests\migrate\Kernel\MigrateTestBase
- class \Drupal\Tests\taxonomy\Kernel\Migrate\MigrateTaxonomyTermStubTest uses \Drupal\migrate_drupal\Tests\StubTestTrait implements \Drupal\Tests\migrate_drupal\Kernel\MigrateDrupalTestBase
- class \Drupal\Tests\migrate_drupal\Kernel\MigrateDrupalTestBase implements \Drupal\Tests\migrate\Kernel\MigrateTestBase
- class \Drupal\Tests\migrate\Kernel\MigrateTestBase extends \Drupal\migrate\MigrateMessageInterface implements \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of MigrateTaxonomyTermStubTest
File
-
core/
modules/ taxonomy/ tests/ src/ Kernel/ Migrate/ MigrateTaxonomyTermStubTest.php, line 16
Namespace
Drupal\Tests\taxonomy\Kernel\MigrateView source
class MigrateTaxonomyTermStubTest extends MigrateDrupalTestBase {
use StubTestTrait;
/**
* {@inheritdoc}
*/
protected static $modules = [
'taxonomy',
'text',
'taxonomy_term_stub_test',
];
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->installEntitySchema('taxonomy_term');
}
/**
* Tests creation of taxonomy term stubs.
*/
public function testStub() {
Vocabulary::create([
'vid' => 'test_vocabulary',
'name' => 'Test vocabulary',
])->save();
$this->performStubTest('taxonomy_term');
}
/**
* Tests creation of stubs when weight is mapped.
*/
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.