You are here

protected function TaxonomyImageTest::setUp in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/taxonomy/tests/src/Functional/TaxonomyImageTest.php \Drupal\Tests\taxonomy\Functional\TaxonomyImageTest::setUp()
  2. 9 core/modules/taxonomy/tests/src/Functional/TaxonomyImageTest.php \Drupal\Tests\taxonomy\Functional\TaxonomyImageTest::setUp()

File

core/modules/taxonomy/tests/src/Functional/TaxonomyImageTest.php, line 42

Class

TaxonomyImageTest
Tests access checks of private image fields.

Namespace

Drupal\Tests\taxonomy\Functional

Code

protected function setUp() : void {
  parent::setUp();

  // Remove access content permission from registered users.
  user_role_revoke_permissions(RoleInterface::AUTHENTICATED_ID, [
    'access content',
  ]);
  $this->vocabulary = $this
    ->createVocabulary();

  // Add a field to the vocabulary.
  $entity_type = 'taxonomy_term';
  $name = 'field_test';
  FieldStorageConfig::create([
    'field_name' => $name,
    'entity_type' => $entity_type,
    'type' => 'image',
    'settings' => [
      'uri_scheme' => 'private',
    ],
  ])
    ->save();
  FieldConfig::create([
    'field_name' => $name,
    'entity_type' => $entity_type,
    'bundle' => $this->vocabulary
      ->id(),
    'settings' => [],
  ])
    ->save();

  /** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $display_repository */
  $display_repository = \Drupal::service('entity_display.repository');
  $display_repository
    ->getViewDisplay($entity_type, $this->vocabulary
    ->id())
    ->setComponent($name, [
    'type' => 'image',
    'settings' => [],
  ])
    ->save();
  $display_repository
    ->getFormDisplay($entity_type, $this->vocabulary
    ->id())
    ->setComponent($name, [
    'type' => 'image_image',
    'settings' => [],
  ])
    ->save();
}