You are here

protected function ManageFieldsFunctionalTest::setUp in Drupal 8

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

Overrides BrowserTestBase::setUp

File

core/modules/field_ui/tests/src/Functional/ManageFieldsFunctionalTest.php, line 77

Class

ManageFieldsFunctionalTest
Tests the Field UI "Manage fields" screen.

Namespace

Drupal\Tests\field_ui\Functional

Code

protected function setUp() {
  parent::setUp();
  $this
    ->drupalPlaceBlock('system_breadcrumb_block');
  $this
    ->drupalPlaceBlock('local_actions_block');
  $this
    ->drupalPlaceBlock('local_tasks_block');
  $this
    ->drupalPlaceBlock('page_title_block');

  // Create a test user.
  $admin_user = $this
    ->drupalCreateUser([
    'access content',
    'administer content types',
    'administer node fields',
    'administer node form display',
    'administer node display',
    'administer taxonomy',
    'administer taxonomy_term fields',
    'administer taxonomy_term display',
    'administer users',
    'administer account settings',
    'administer user display',
  ]);
  $this
    ->drupalLogin($admin_user);

  // Create content type, with underscores.
  $type_name = strtolower($this
    ->randomMachineName(8)) . '_test';
  $type = $this
    ->drupalCreateContentType([
    'name' => $type_name,
    'type' => $type_name,
  ]);
  $this->contentType = $type
    ->id();

  // Create random field name with markup to test escaping.
  $this->fieldLabel = '<em>' . $this
    ->randomMachineName(8) . '</em>';
  $this->fieldNameInput = strtolower($this
    ->randomMachineName(8));
  $this->fieldName = 'field_' . $this->fieldNameInput;

  // Create Basic page and Article node types.
  $this
    ->drupalCreateContentType([
    'type' => 'page',
    'name' => 'Basic page',
  ]);
  $this
    ->drupalCreateContentType([
    'type' => 'article',
    'name' => 'Article',
  ]);

  // Create a vocabulary named "Tags".
  $vocabulary = Vocabulary::create([
    'name' => 'Tags',
    'vid' => 'tags',
    'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
  ]);
  $vocabulary
    ->save();
  $handler_settings = [
    'target_bundles' => [
      $vocabulary
        ->id() => $vocabulary
        ->id(),
    ],
  ];
  $this
    ->createEntityReferenceField('node', 'article', 'field_' . $vocabulary
    ->id(), 'Tags', 'taxonomy_term', 'default', $handler_settings);
  \Drupal::service('entity_display.repository')
    ->getFormDisplay('node', 'article')
    ->setComponent('field_' . $vocabulary
    ->id())
    ->save();

  // Setup node access testing.
  node_access_rebuild();
  node_access_test_add_field(NodeType::load('article'));
  \Drupal::state()
    ->set('node_access_test.private', TRUE);
}