Updated Drupal to 8.6. This goes with the following updates because it's possible...
[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\WebDriverTestBase;
7
8 /**
9  * Tests the UI for entity displays.
10  *
11  * @group field_ui
12  */
13 class EntityDisplayTest extends WebDriverTestBase {
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     $this->getSession()->getPage()->pressButton('Show row weights');
54     $this->assertSession()->waitForElementVisible('css', '[name="fields[field_test_text][region]"]');
55     $this->getSession()->getPage()->selectFieldOption('fields[field_test_text][region]', 'hidden');
56     $this->assertSession()->assertWaitOnAjaxRequest();
57     $this->assertTrue($this->assertSession()->optionExists('fields[field_test_text][region]', 'hidden')->isSelected());
58
59     $this->submitForm([], 'Save');
60     $this->assertSession()->pageTextContains('Your settings have been saved.');
61     $this->assertTrue($this->assertSession()->optionExists('fields[field_test_text][region]', 'hidden')->isSelected());
62
63     $this->drupalGet('entity_test/manage/1/edit');
64     $this->assertSession()->fieldNotExists('field_test_text[0][value]');
65   }
66
67   /**
68    * Tests the use of regions for entity view displays.
69    */
70   public function testEntityView() {
71     $this->drupalGet('entity_test/1');
72     $this->assertSession()->elementNotExists('css', '.field--name-field-test-text');
73
74     $this->drupalGet('entity_test/structure/entity_test/display');
75     $this->assertSession()->elementExists('css', '.region-content-message.region-empty');
76     $this->getSession()->getPage()->pressButton('Show row weights');
77     $this->assertSession()->waitForElementVisible('css', '[name="fields[field_test_text][region]"]');
78     $this->assertTrue($this->assertSession()->optionExists('fields[field_test_text][region]', 'hidden')->isSelected());
79
80     $this->getSession()->getPage()->selectFieldOption('fields[field_test_text][region]', 'content');
81     $this->assertSession()->assertWaitOnAjaxRequest();
82     $this->assertTrue($this->assertSession()->optionExists('fields[field_test_text][region]', 'content')->isSelected());
83
84     $this->submitForm([], 'Save');
85     $this->assertSession()->pageTextContains('Your settings have been saved.');
86     $this->assertTrue($this->assertSession()->optionExists('fields[field_test_text][region]', 'content')->isSelected());
87
88     $this->drupalGet('entity_test/1');
89     $this->assertSession()->elementExists('css', '.field--name-field-test-text');
90   }
91
92   /**
93    * Tests extra fields.
94    */
95   public function testExtraFields() {
96     entity_test_create_bundle('bundle_with_extra_fields');
97     $this->drupalGet('entity_test/structure/bundle_with_extra_fields/display');
98     $this->assertSession()->waitForElement('css', '.tabledrag-handle');
99     $id = $this->getSession()->getPage()->find('css', '[name="form_build_id"]')->getValue();
100
101     $extra_field_row = $this->getSession()->getPage()->find('css', '#display-extra-field');
102     $disabled_region_row = $this->getSession()->getPage()->find('css', '.region-hidden-title');
103
104     $extra_field_row->find('css', '.handle')->dragTo($disabled_region_row);
105     $this->assertSession()->assertWaitOnAjaxRequest();
106     $this->assertSession()
107       ->waitForElement('css', "[name='form_build_id']:not([value='$id'])");
108
109     $this->submitForm([], 'Save');
110     $this->assertSession()->pageTextContains('Your settings have been saved.');
111   }
112
113 }