function FieldLayoutTest::testEntityViewModes

Same name and namespace in other branches
  1. 8.9.x core/modules/field_layout/tests/src/FunctionalJavascript/FieldLayoutTest.php \Drupal\Tests\field_layout\FunctionalJavascript\FieldLayoutTest::testEntityViewModes()
  2. 10 core/modules/field_layout/tests/src/FunctionalJavascript/FieldLayoutTest.php \Drupal\Tests\field_layout\FunctionalJavascript\FieldLayoutTest::testEntityViewModes()
  3. 11.x 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 ');
    $this->drupalGet('entity_test/1');
    $this->assertSession()
        ->elementNotExists('css', '.layout__region--content');
    // 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()
        ->elementTextContains('css', '.layout__region--content', 'The field test text value');
    $this->drupalGet('entity_test/1');
    $this->assertSession()
        ->elementNotExists('css', '.layout__region--content');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.