function ContentEntityTest::setUp

Same name 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::setUp()
  2. 8.9.x core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php \Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate\source\ContentEntityTest::setUp()
  3. 10 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 93

Class

ContentEntityTest
Tests the entity content source plugin.

Namespace

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

Code

protected function setUp() : void {
    parent::setUp();
    $this->installEntitySchema('node');
    $this->installEntitySchema('file');
    $this->installEntitySchema('media');
    $this->installEntitySchema('taxonomy_term');
    $this->installEntitySchema('user');
    $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' => 'fr - Apples',
        $this->fieldName => $term->id(),
    ])
        ->save();
    $this->migrationPluginManager = $this->container
        ->get('plugin.manager.migration');
}

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