You are here

protected function ContentEntityTest::setUp in Drupal 8

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::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() {
  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($this->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 some data.
  $this->user = User::create([
    'name' => 'user123',
    'uid' => 1,
    'mail' => 'example@example.com',
  ]);
  $this->user
    ->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');
}