You are here

protected function TestBase::setUp in Display Suite 8.4

Same name and namespace in other branches
  1. 8.3 tests/src/Functional/TestBase.php \Drupal\Tests\ds\Functional\TestBase::setUp()

Overrides BrowserTestBase::setUp

4 calls to TestBase::setUp()
BlockFieldPluginTest::setUp in tests/src/Functional/BlockFieldPluginTest.php
BlockTest::setUp in tests/src/Functional/BlockTest.php
DsFieldCacheTest::setUp in tests/src/Functional/DsFieldCacheTest.php
ViewsTest::setUp in tests/src/Functional/ViewsTest.php
4 methods override TestBase::setUp()
BlockFieldPluginTest::setUp in tests/src/Functional/BlockFieldPluginTest.php
BlockTest::setUp in tests/src/Functional/BlockTest.php
DsFieldCacheTest::setUp in tests/src/Functional/DsFieldCacheTest.php
ViewsTest::setUp in tests/src/Functional/ViewsTest.php

File

tests/src/Functional/TestBase.php, line 86

Class

TestBase
Base test for Display Suite.

Namespace

Drupal\Tests\ds\Functional

Code

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

  // Create a test user.
  $this->adminUser = $this
    ->drupalCreateUser([
    'access content',
    'access in-place editing',
    'access user profiles',
    'admin classes',
    'admin display suite',
    'admin fields',
    'administer nodes',
    'view all revisions',
    '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 permissions',
    'administer account settings',
    'administer user display',
    'administer software updates',
    'access site in maintenance mode',
    'administer site configuration',
    'bypass node access',
    'ds switch view mode',
  ]);
  $this
    ->drupalLogin($this->adminUser);

  // Create random field name.
  $this->fieldLabel = $this
    ->randomMachineName(8);
  $this->fieldNameInput = strtolower($this
    ->randomMachineName(8));
  $this->fieldName = 'field_' . $this->fieldNameInput;

  // Create Article node type.
  $this
    ->drupalCreateContentType([
    'type' => 'article',
    'name' => 'Article',
    'revision' => TRUE,
  ]);
  $this
    ->drupalCreateContentType([
    'type' => 'page',
    'name' => 'Page',
    'revision' => TRUE,
  ]);

  // Create a vocabulary named "Tags".
  $this->vocabulary = Vocabulary::create([
    'name' => 'Tags',
    'vid' => 'tags',
    'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
  ]);
  $this->vocabulary
    ->save();
  $term1 = Term::create([
    'name' => 'Tag 1',
    'vid' => 'tags',
    'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
  ]);
  $term1
    ->save();
  $term2 = Term::create([
    'name' => 'Tag 2',
    'vid' => 'tags',
    'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
  ]);
  $term2
    ->save();
  $handler_settings = [
    'target_bundles' => [
      $this->vocabulary
        ->id() => $this->vocabulary
        ->id(),
    ],
    // Enable auto-create.
    'auto_create' => TRUE,
  ];
  $this
    ->createEntityReferenceField('node', 'article', 'field_' . $this->vocabulary
    ->id(), 'Tags', 'taxonomy_term', 'default', $handler_settings, 10);

  /** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $display */
  $display = \Drupal::entityTypeManager()
    ->getStorage('entity_form_display')
    ->load('node.article.default');
  $display
    ->setComponent('field_' . $this->vocabulary
    ->id())
    ->save();
}