You are here

public function HorizontalTabsLabelsTest::setUp in Field Group 8.3

Overrides BrowserTestBase::setUp

File

tests/src/FunctionalJavascript/HorizontalTabsLabelsTest.php, line 86

Class

HorizontalTabsLabelsTest
Tests horizontal tabs labels.

Namespace

Drupal\Tests\field_group\FunctionalJavascript

Code

public function setUp() {
  parent::setUp();
  $this->assertSession = $this
    ->assertSession();
  $this->page = $this
    ->getSession()
    ->getPage();
  $this->testNodeType = $this
    ->drupalCreateContentType([
    'type' => 'test_node_bundle',
    'name' => 'Test Node Type',
  ]);

  // Add an extra field to the test content type.
  $entity_type_manager = $this->container
    ->get('entity_type.manager');
  $field_storage = $entity_type_manager
    ->getStorage('field_storage_config')
    ->create([
    'type' => 'string',
    'field_name' => 'test_label',
    'entity_type' => 'node',
  ]);
  assert($field_storage instanceof FieldStorageConfigInterface);
  $field_storage
    ->save();
  $entity_type_manager
    ->getStorage('field_config')
    ->create([
    'label' => 'Test label',
    'field_storage' => $field_storage,
    'bundle' => $this->testNodeType
      ->id(),
  ])
    ->save();
  $tab1 = [
    'label' => 'Tab1',
    'group_name' => 'group_tab1',
    'weight' => '1',
    'children' => [
      0 => 'test_label',
    ],
    'format_type' => 'tab',
    'format_settings' => [
      'label' => 'Tab1',
      'formatter' => 'open',
    ],
  ];
  $this
    ->createGroup('node', $this->testNodeType
    ->id(), 'form', 'default', $tab1);
  $this
    ->createGroup('node', $this->testNodeType
    ->id(), 'view', 'default', $tab1);
  $tab2 = [
    'label' => 'Tab2',
    'group_name' => 'group_tab2',
    'weight' => '2',
    'children' => [
      0 => 'body',
    ],
    'format_type' => 'tab',
    'format_settings' => [
      'label' => 'Tab2',
      'formatter' => 'closed',
    ],
  ];
  $this
    ->createGroup('node', $this->testNodeType
    ->id(), 'form', 'default', $tab2);
  $this
    ->createGroup('node', $this->testNodeType
    ->id(), 'view', 'default', $tab2);
  $horizontal_tabs = [
    'label' => 'Horizontal tabs',
    'group_name' => 'group_horizontal_tabs',
    'weight' => '-5',
    'children' => [
      'group_tab1',
      'group_tab2',
    ],
    'format_type' => 'tabs',
    'format_settings' => [
      'direction' => 'horizontal',
      'label' => 'Horizontal tabs',
    ],
  ];
  $this
    ->createGroup('node', $this->testNodeType
    ->id(), 'form', 'default', $horizontal_tabs);
  $this
    ->createGroup('node', $this->testNodeType
    ->id(), 'view', 'default', $horizontal_tabs);
  $entity_type_manager
    ->getStorage('entity_form_display')
    ->load(implode('.', [
    'node',
    $this->testNodeType
      ->id(),
    'default',
  ]))
    ->setComponent('test_label', [
    'weight' => '1',
  ])
    ->save();
  $entity_type_manager
    ->getStorage('entity_view_display')
    ->load(implode('.', [
    'node',
    $this->testNodeType
      ->id(),
    'default',
  ]))
    ->setComponent('test_label', [
    'weight' => '1',
  ])
    ->save();
}