You are here

protected function TaxonomyTestBase::mockStandardInstall in Drupal 9

Same name in this branch
  1. 9 core/modules/taxonomy/tests/src/Functional/Views/TaxonomyTestBase.php \Drupal\Tests\taxonomy\Functional\Views\TaxonomyTestBase::mockStandardInstall()
  2. 9 core/modules/taxonomy/tests/src/Kernel/Views/TaxonomyTestBase.php \Drupal\Tests\taxonomy\Kernel\Views\TaxonomyTestBase::mockStandardInstall()
Same name and namespace in other branches
  1. 8 core/modules/taxonomy/tests/src/Kernel/Views/TaxonomyTestBase.php \Drupal\Tests\taxonomy\Kernel\Views\TaxonomyTestBase::mockStandardInstall()

Provides a workaround for the inability to use the standard profile.

See also

https://www.drupal.org/node/1708692

1 call to TaxonomyTestBase::mockStandardInstall()
TaxonomyTestBase::setUp in core/modules/taxonomy/tests/src/Kernel/Views/TaxonomyTestBase.php

File

core/modules/taxonomy/tests/src/Kernel/Views/TaxonomyTestBase.php, line 107

Class

TaxonomyTestBase
Base class for views kernel taxonomy tests.

Namespace

Drupal\Tests\taxonomy\Kernel\Views

Code

protected function mockStandardInstall() {
  $this
    ->drupalCreateContentType([
    'type' => 'article',
  ]);

  // Create the vocabulary for the tag field.
  $this->vocabulary = Vocabulary::create([
    'name' => 'Views testing tags',
    'vid' => 'views_testing_tags',
  ]);
  $this->vocabulary
    ->save();
  $field_name = 'field_' . $this->vocabulary
    ->id();
  $handler_settings = [
    'target_bundles' => [
      $this->vocabulary
        ->id() => $this->vocabulary
        ->id(),
    ],
    'auto_create' => TRUE,
  ];
  $this
    ->installEntitySchema('node');
  $this
    ->createEntityReferenceField('node', 'article', $field_name, 'Tags', 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
  $entity_type_manager = $this->container
    ->get('entity_type.manager');
  $entity_type_manager
    ->getStorage('entity_form_display')
    ->load('node.article.default')
    ->setComponent($field_name, [
    'type' => 'entity_reference_autocomplete_tags',
    'weight' => -4,
  ])
    ->save();
  $view_modes = [
    'default',
    'teaser',
  ];
  foreach ($view_modes as $view_mode) {
    $entity_type_manager
      ->getStorage('entity_view_display')
      ->load("node.article.{$view_mode}")
      ->setComponent($field_name, [
      'type' => 'entity_reference_label',
      'weight' => 10,
    ])
      ->save();
  }
}