3 namespace Drupal\Tests\field_layout\Functional;
5 use Drupal\Tests\BrowserTestBase;
8 * Tests using field layout for entity displays.
12 class FieldLayoutTest extends BrowserTestBase {
17 public static $modules = ['field_layout', 'field_ui', 'node', 'field_layout_test'];
22 protected function setUp() {
25 $this->createContentType([
30 'title' => 'The node title',
32 ['value' => 'The node body'],
35 $this->drupalLogin($this->drupalCreateUser([
36 'access administration pages',
37 'administer content types',
39 'administer node fields',
40 'administer node display',
41 'administer node form display',
42 'view the administration theme',
47 * Tests an entity type that has fields shown by default.
49 public function testNodeView() {
50 // By default, the one-column layout is used.
51 $this->drupalGet('node/1');
52 $this->assertSession()->elementExists('css', '.layout--onecol');
53 $this->assertSession()->elementExists('css', '.layout__region--content .field--name-body');
55 $this->drupalGet('admin/structure/types/manage/article/display');
56 $this->assertEquals(['Content', 'Disabled'], $this->getRegionTitles());
57 $this->assertSession()->optionExists('fields[body][region]', 'content');
61 * Tests that changes to the regions still leave the fields visible.
63 public function testRegionChanges() {
64 $this->drupalGet('admin/structure/types/manage/article/display');
65 $this->assertEquals(['Content', 'Disabled'], $this->getRegionTitles());
66 $this->assertSession()->optionExists('fields[body][region]', 'content');
68 \Drupal::state()->set('field_layout_test.alter_regions', TRUE);
69 \Drupal::service('plugin.cache_clearer')->clearCachedDefinitions();
71 $this->drupalGet('admin/structure/types/manage/article/display');
72 $this->assertEquals(['Foo', 'Disabled'], $this->getRegionTitles());
73 $this->assertSession()->optionExists('fields[body][region]', 'hidden');
77 * Gets the region titles on the page.
80 * An array of region titles.
82 protected function getRegionTitles() {
84 $region_title_elements = $this->getSession()->getPage()->findAll('css', '.region-title td');
85 /** @var \Behat\Mink\Element\NodeElement[] $region_title_elements */
86 foreach ($region_title_elements as $region_title_element) {
87 $region_titles[] = $region_title_element->getText();
89 return $region_titles;