EntityDisplayTest.php

Same filename in this branch
  1. 9 core/modules/field_ui/tests/src/Kernel/EntityDisplayTest.php
  2. 9 core/modules/field_ui/tests/src/Functional/EntityDisplayTest.php
Same filename in other branches
  1. 8.9.x core/modules/field_ui/tests/src/FunctionalJavascript/EntityDisplayTest.php
  2. 8.9.x core/modules/field_ui/tests/src/Kernel/EntityDisplayTest.php
  3. 8.9.x core/modules/field_ui/tests/src/Functional/EntityDisplayTest.php
  4. 10 core/modules/field_ui/tests/src/FunctionalJavascript/EntityDisplayTest.php
  5. 10 core/modules/field_ui/tests/src/Kernel/EntityDisplayTest.php
  6. 10 core/modules/field_ui/tests/src/Functional/EntityDisplayTest.php
  7. 11.x core/modules/field_ui/tests/src/FunctionalJavascript/EntityDisplayTest.php
  8. 11.x core/modules/field_ui/tests/src/Kernel/EntityDisplayTest.php
  9. 11.x core/modules/field_ui/tests/src/Functional/EntityDisplayTest.php

Namespace

Drupal\Tests\field_ui\FunctionalJavascript

File

core/modules/field_ui/tests/src/FunctionalJavascript/EntityDisplayTest.php

View source
<?php

namespace Drupal\Tests\field_ui\FunctionalJavascript;

use Drupal\entity_test\Entity\EntityTest;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;

/**
 * Tests the UI for entity displays.
 *
 * @group field_ui
 */
class EntityDisplayTest extends WebDriverTestBase {
    
    /**
     * {@inheritdoc}
     */
    protected static $modules = [
        'field_ui',
        'entity_test',
    ];
    
    /**
     * {@inheritdoc}
     */
    protected $defaultTheme = 'stark';
    
    /**
     * {@inheritdoc}
     */
    protected function setUp() : void {
        parent::setUp();
        $entity = EntityTest::create([
            'name' => 'The name for this entity',
            'field_test_text' => [
                [
                    'value' => 'The field test text value',
                ],
            ],
        ]);
        $entity->save();
        $this->drupalLogin($this->drupalCreateUser([
            'access administration pages',
            'view test entity',
            'administer entity_test content',
            'administer entity_test fields',
            'administer entity_test display',
            'administer entity_test form display',
            'view the administration theme',
        ]));
    }
    
    /**
     * Tests the use of regions for entity form displays.
     */
    public function testEntityForm() {
        $this->drupalGet('entity_test/manage/1/edit');
        $this->assertSession()
            ->fieldExists('field_test_text[0][value]');
        $this->drupalGet('entity_test/structure/entity_test/form-display');
        $this->assertTrue($this->assertSession()
            ->optionExists('fields[field_test_text][region]', 'content')
            ->isSelected());
        $this->getSession()
            ->getPage()
            ->pressButton('Show row weights');
        $this->assertSession()
            ->waitForElementVisible('css', '[name="fields[field_test_text][region]"]');
        $this->getSession()
            ->getPage()
            ->selectFieldOption('fields[field_test_text][region]', 'hidden');
        $this->assertSession()
            ->assertWaitOnAjaxRequest();
        $this->assertTrue($this->assertSession()
            ->optionExists('fields[field_test_text][region]', 'hidden')
            ->isSelected());
        $this->submitForm([], 'Save');
        $this->assertSession()
            ->pageTextContains('Your settings have been saved.');
        $this->assertTrue($this->assertSession()
            ->optionExists('fields[field_test_text][region]', 'hidden')
            ->isSelected());
        $this->drupalGet('entity_test/manage/1/edit');
        $this->assertSession()
            ->fieldNotExists('field_test_text[0][value]');
    }
    
    /**
     * Tests the use of regions for entity view displays.
     */
    public function testEntityView() {
        $this->drupalGet('entity_test/1');
        $this->assertSession()
            ->pageTextNotContains('The field test text value');
        $this->drupalGet('entity_test/structure/entity_test/display');
        $this->assertSession()
            ->elementExists('css', '.region-content-message.region-empty');
        $this->getSession()
            ->getPage()
            ->pressButton('Show row weights');
        $this->assertSession()
            ->waitForElementVisible('css', '[name="fields[field_test_text][region]"]');
        $this->assertTrue($this->assertSession()
            ->optionExists('fields[field_test_text][region]', 'hidden')
            ->isSelected());
        $this->getSession()
            ->getPage()
            ->selectFieldOption('fields[field_test_text][region]', 'content');
        $this->assertSession()
            ->assertWaitOnAjaxRequest();
        $this->assertTrue($this->assertSession()
            ->optionExists('fields[field_test_text][region]', 'content')
            ->isSelected());
        $this->submitForm([], 'Save');
        $this->assertSession()
            ->pageTextContains('Your settings have been saved.');
        $this->assertTrue($this->assertSession()
            ->optionExists('fields[field_test_text][region]', 'content')
            ->isSelected());
        $this->drupalGet('entity_test/1');
        $this->assertSession()
            ->pageTextContains('The field test text value');
    }
    
    /**
     * Tests extra fields.
     */
    public function testExtraFields() {
        entity_test_create_bundle('bundle_with_extra_fields');
        $this->drupalGet('entity_test/structure/bundle_with_extra_fields/display');
        $this->assertSession()
            ->waitForElement('css', '.tabledrag-handle');
        $id = $this->getSession()
            ->getPage()
            ->find('css', '[name="form_build_id"]')
            ->getValue();
        $extra_field_row = $this->getSession()
            ->getPage()
            ->find('css', '#display-extra-field');
        $disabled_region_row = $this->getSession()
            ->getPage()
            ->find('css', '.region-hidden-title');
        $extra_field_row->find('css', '.handle')
            ->dragTo($disabled_region_row);
        $this->assertSession()
            ->assertWaitOnAjaxRequest();
        $this->assertSession()
            ->waitForElement('css', "[name='form_build_id']:not([value='{$id}'])");
        $this->submitForm([], 'Save');
        $this->assertSession()
            ->pageTextContains('Your settings have been saved.');
    }

}

Classes

Title Deprecated Summary
EntityDisplayTest Tests the UI for entity displays.

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