You are here

public function FieldGroupLinkDisplayTest::setUp in Field Group Link 8.3

Overrides BrowserTestBase::setUp

File

tests/src/Functional/FieldGroupLinkDisplayTest.php, line 65

Class

FieldGroupLinkDisplayTest
Tests for displaying entities.

Namespace

Drupal\Tests\field_group_link\Functional

Code

public function setUp() {
  parent::setUp();

  // Configure 'node' as front page.
  $this
    ->config('system.site')
    ->set('page.front', '/node')
    ->save();

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

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

  /** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display */
  $display = \Drupal::entityTypeManager()
    ->getStorage('entity_view_display')
    ->load('node' . '.' . $type_name . '.' . 'default');

  // Create a node.
  $node_values = array(
    'type' => $type_name,
  );
  $this
    ->setupFields();

  // Assign a test value for the field.
  $this->testFieldValue = mt_rand(1, 127);
  $node_values['field_test'][0]['value'] = $this->testFieldValue;

  // Set the field visible on the display object.
  $display_options = array(
    'label' => 'above',
    'type' => 'field_test_default',
    'settings' => array(
      'test_formatter_setting' => $this
        ->randomMachineName(),
    ),
  );
  $display
    ->setComponent('field_test', $display_options);
  $this->referencedNode = $this
    ->drupalCreateNode([
    'type' => $type_name,
  ]);
  $node_values['field_test_entity_reference'][0]['target_id'] = $this->referencedNode
    ->id();
  $node_values['field_test_link'][0] = [
    'uri' => 'internal:/node/' . $this->referencedNode
      ->id(),
  ];

  // Save display + create node.
  $display
    ->save();
  $this->node = $this
    ->drupalCreateNode($node_values);
}