protected function ContentEntityTest::setUp in Drupal 10
Same name and namespace in other branches
- 8 core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php \Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate\source\ContentEntityTest::setUp()
- 9 core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php \Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate\source\ContentEntityTest::setUp()
Overrides KernelTestBase::setUp
File
- core/
modules/ migrate_drupal/ tests/ src/ Kernel/ Plugin/ migrate/ source/ ContentEntityTest.php, line 90
Class
- ContentEntityTest
- Tests the entity content source plugin.
Namespace
Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate\sourceCode
protected function setUp() : void {
parent::setUp();
$this
->installEntitySchema('node');
$this
->installEntitySchema('file');
$this
->installEntitySchema('media');
$this
->installEntitySchema('taxonomy_term');
$this
->installEntitySchema('taxonomy_vocabulary');
$this
->installEntitySchema('user');
$this
->installSchema('system', [
'sequences',
]);
$this
->installSchema('user', 'users_data');
$this
->installSchema('file', 'file_usage');
$this
->installSchema('node', [
'node_access',
]);
$this
->installConfig(static::$modules);
ConfigurableLanguage::createFromLangcode('fr')
->save();
// Create article content type.
$node_type = NodeType::create([
'type' => $this->bundle,
'name' => 'Article',
]);
$node_type
->save();
// Create a vocabulary.
$vocabulary = Vocabulary::create([
'name' => $this->vocabulary,
'description' => $this->vocabulary,
'vid' => $this->vocabulary,
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
]);
$vocabulary
->save();
// Create a term reference field on node.
$this
->createEntityReferenceField('node', $this->bundle, $this->fieldName, 'Term reference', 'taxonomy_term', 'default', [
'target_bundles' => [
$this->vocabulary,
],
], FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
// Create a term reference field on user.
$this
->createEntityReferenceField('user', 'user', $this->fieldName, 'Term reference', 'taxonomy_term', 'default', [
'target_bundles' => [
$this->vocabulary,
],
], FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
// Create a node, with data in a term reference field, and then add a French
// translation of the node.
$this->user = User::create([
'name' => 'user123',
'uid' => 1,
'mail' => 'example@example.com',
]);
$this->user
->save();
// Add the anonymous user so we can test later that it is not provided in a
// source row.
User::create([
'name' => 'anon',
'uid' => 0,
])
->save();
$term = Term::create([
'vid' => $this->vocabulary,
'name' => 'Apples',
'uid' => $this->user
->id(),
]);
$term
->save();
$this->user
->set($this->fieldName, $term
->id());
$this->user
->save();
$node = Node::create([
'type' => $this->bundle,
'title' => 'Apples',
$this->fieldName => $term
->id(),
'uid' => $this->user
->id(),
]);
$node
->save();
$node
->addTranslation('fr', [
'title' => 'Pommes',
$this->fieldName => $term
->id(),
])
->save();
$this->migrationPluginManager = $this->container
->get('plugin.manager.migration');
}