Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / field_ui / tests / src / FunctionalJavascript / EntityDisplayTest.php
1 <?php
2
3 namespace Drupal\Tests\field_ui\FunctionalJavascript;
4
5 use Drupal\entity_test\Entity\EntityTest;
6 use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
7
8 /**
9  * Tests the UI for entity displays.
10  *
11  * @group field_ui
12  */
13 class EntityDisplayTest extends JavascriptTestBase {
14
15   /**
16    * {@inheritdoc}
17    */
18   public static $modules = ['field_ui', 'entity_test'];
19
20   /**
21    * {@inheritdoc}
22    */
23   protected function setUp() {
24     parent::setUp();
25
26     $entity = EntityTest::create([
27       'name' => 'The name for this entity',
28       'field_test_text' => [
29         ['value' => 'The field test text value'],
30       ],
31     ]);
32     $entity->save();
33     $this->drupalLogin($this->drupalCreateUser([
34       'access administration pages',
35       'view test entity',
36       'administer entity_test content',
37       'administer entity_test fields',
38       'administer entity_test display',
39       'administer entity_test form display',
40       'view the administration theme',
41     ]));
42   }
43
44   /**
45    * Tests the use of regions for entity form displays.
46    */
47   public function testEntityForm() {
48     $this->drupalGet('entity_test/manage/1/edit');
49     $this->assertSession()->fieldExists('field_test_text[0][value]');
50
51     $this->drupalGet('entity_test/structure/entity_test/form-display');
52     $this->assertTrue($this->assertSession()->optionExists('fields[field_test_text][region]', 'content')->isSelected());
53
54     $this->getSession()->getPage()->selectFieldOption('fields[field_test_text][region]', 'hidden');
55     $this->assertSession()->assertWaitOnAjaxRequest();
56     $this->assertTrue($this->assertSession()->optionExists('fields[field_test_text][region]', 'hidden')->isSelected());
57
58     $this->submitForm([], 'Save');
59     $this->assertSession()->pageTextContains('Your settings have been saved.');
60     $this->assertTrue($this->assertSession()->optionExists('fields[field_test_text][region]', 'hidden')->isSelected());
61
62     $this->drupalGet('entity_test/manage/1/edit');
63     $this->assertSession()->fieldNotExists('field_test_text[0][value]');
64   }
65
66   /**
67    * Tests the use of regions for entity view displays.
68    */
69   public function testEntityView() {
70     $this->drupalGet('entity_test/1');
71     $this->assertSession()->elementNotExists('css', '.field--name-field-test-text');
72
73     $this->drupalGet('entity_test/structure/entity_test/display');
74     $this->assertSession()->elementExists('css', '.region-content-message.region-empty');
75     $this->assertTrue($this->assertSession()->optionExists('fields[field_test_text][region]', 'hidden')->isSelected());
76
77     $this->getSession()->getPage()->selectFieldOption('fields[field_test_text][region]', 'content');
78     $this->assertSession()->assertWaitOnAjaxRequest();
79     $this->assertTrue($this->assertSession()->optionExists('fields[field_test_text][region]', 'content')->isSelected());
80
81     $this->submitForm([], 'Save');
82     $this->assertSession()->pageTextContains('Your settings have been saved.');
83     $this->assertTrue($this->assertSession()->optionExists('fields[field_test_text][region]', 'content')->isSelected());
84
85     $this->drupalGet('entity_test/1');
86     $this->assertSession()->elementExists('css', '.field--name-field-test-text');
87   }
88
89   /**
90    * Tests extra fields.
91    */
92   public function testExtraFields() {
93     entity_test_create_bundle('bundle_with_extra_fields');
94     $this->drupalGet('entity_test/structure/bundle_with_extra_fields/display');
95
96     $extra_field_row = $this->getSession()->getPage()->find('css', '#display-extra-field');
97     $disabled_region_row = $this->getSession()->getPage()->find('css', '.region-hidden-title');
98
99     $extra_field_row->find('css', '.handle')->dragTo($disabled_region_row);
100     $this->assertSession()->assertWaitOnAjaxRequest();
101
102     $this->submitForm([], 'Save');
103     $this->assertSession()->pageTextContains('Your settings have been saved.');
104   }
105
106 }