You are here

public function FieldLayoutTest::testEntityViewModes in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/field_layout/tests/src/FunctionalJavascript/FieldLayoutTest.php \Drupal\Tests\field_layout\FunctionalJavascript\FieldLayoutTest::testEntityViewModes()

Tests that layouts are unique per view mode.

File

core/modules/field_layout/tests/src/FunctionalJavascript/FieldLayoutTest.php, line 57

Class

FieldLayoutTest
Tests using field layout for entity displays.

Namespace

Drupal\Tests\field_layout\FunctionalJavascript

Code

public function testEntityViewModes() {

  // By default, the field is not visible.
  $this
    ->drupalGet('entity_test/1/test');
  $this
    ->assertSession()
    ->elementNotExists('css', '.layout__region--content .field--name-field-test-text');
  $this
    ->drupalGet('entity_test/1');
  $this
    ->assertSession()
    ->elementNotExists('css', '.layout__region--content .field--name-field-test-text');

  // Change the layout for the "test" view mode. See
  // core.entity_view_mode.entity_test.test.yml.
  $this
    ->drupalGet('entity_test/structure/entity_test/display');
  $this
    ->click('#edit-modes');
  $this
    ->getSession()
    ->getPage()
    ->checkField('display_modes_custom[test]');
  $this
    ->submitForm([], 'Save');
  $this
    ->clickLink('configure them');
  $this
    ->getSession()
    ->getPage()
    ->pressButton('Show row weights');
  $this
    ->getSession()
    ->getPage()
    ->selectFieldOption('fields[field_test_text][region]', 'content');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $this
    ->submitForm([], 'Save');

  // Each view mode has a different layout.
  $this
    ->drupalGet('entity_test/1/test');
  $this
    ->assertSession()
    ->elementExists('css', '.layout__region--content .field--name-field-test-text');
  $this
    ->drupalGet('entity_test/1');
  $this
    ->assertSession()
    ->elementNotExists('css', '.layout__region--content .field--name-field-test-text');
}