Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / tests / Drupal / FunctionalJavascriptTests / Core / Form / FormGroupingElementsTest.php
1 <?php
2
3 namespace Drupal\FunctionalJavascriptTests\Core\Form;
4
5 use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
6
7 /**
8  * Tests for form grouping elements.
9  *
10  * @group form
11  */
12 class FormGroupingElementsTest extends WebDriverTestBase {
13
14   /**
15    * Required modules.
16    *
17    * @var array
18    */
19   public static $modules = ['form_test'];
20
21   /**
22    * {@inheritdoc}
23    */
24   protected function setUp() {
25     parent::setUp();
26
27     $account = $this->drupalCreateUser();
28     $this->drupalLogin($account);
29   }
30
31   /**
32    * Tests that vertical tab children become visible.
33    *
34    * Makes sure that a child element of a vertical tab that is not visible,
35    * becomes visible when the tab is clicked, a fragment link to the child is
36    * clicked or when the URI fragment pointing to that child changes.
37    */
38   public function testVerticalTabChildVisibility() {
39     $session = $this->getSession();
40     $web_assert = $this->assertSession();
41
42     // Request the group vertical tabs testing page with a fragment identifier
43     // to the second element.
44     $this->drupalGet('form-test/group-vertical-tabs', ['fragment' => 'edit-element-2']);
45
46     $page = $session->getPage();
47
48     $tab_link_1 = $page->find('css', '.vertical-tabs__menu-item > a');
49
50     $child_1_selector = '#edit-element';
51     $child_1 = $page->find('css', $child_1_selector);
52
53     $child_2_selector = '#edit-element-2';
54     $child_2 = $page->find('css', $child_2_selector);
55
56     // Assert that the child in the second vertical tab becomes visible.
57     // It should be visible after initial load due to the fragment in the URI.
58     $this->assertTrue($child_2->isVisible(), 'Child 2 is visible due to a URI fragment');
59
60     // Click on a fragment link pointing to an invisible child inside an
61     // inactive vertical tab.
62     $session->executeScript("jQuery('<a href=\"$child_1_selector\"></a>').insertAfter('h1')[0].click()");
63
64     // Assert that the child in the first vertical tab becomes visible.
65     $web_assert->waitForElementVisible('css', $child_1_selector, 50);
66
67     // Trigger a URI fragment change (hashchange) to show the second vertical
68     // tab again.
69     $session->executeScript("location.replace('$child_2_selector')");
70
71     // Assert that the child in the second vertical tab becomes visible again.
72     $web_assert->waitForElementVisible('css', $child_2_selector, 50);
73
74     $tab_link_1->click();
75
76     // Assert that the child in the first vertical tab is visible again after
77     // a click on the first tab.
78     $this->assertTrue($child_1->isVisible(), 'Child 1 is visible after clicking the parent tab');
79   }
80
81   /**
82    * Tests that details element children become visible.
83    *
84    * Makes sure that a child element of a details element that is not visible,
85    * becomes visible when a fragment link to the child is clicked or when the
86    * URI fragment pointing to that child changes.
87    */
88   public function testDetailsChildVisibility() {
89     $session = $this->getSession();
90     $web_assert = $this->assertSession();
91
92     // Store reusable JavaScript code to remove the current URI fragment and
93     // close all details.
94     $reset_js = "location.replace('#'); jQuery('details').removeAttr('open')";
95
96     // Request the group details testing page.
97     $this->drupalGet('form-test/group-details');
98
99     $page = $session->getPage();
100
101     $session->executeScript($reset_js);
102
103     $child_selector = '#edit-element';
104     $child = $page->find('css', $child_selector);
105
106     // Assert that the child is not visible.
107     $this->assertFalse($child->isVisible(), 'Child is not visible');
108
109     // Trigger a URI fragment change (hashchange) to open all parent details
110     // elements of the child.
111     $session->executeScript("location.replace('$child_selector')");
112
113     // Assert that the child becomes visible again after a hash change.
114     $web_assert->waitForElementVisible('css', $child_selector, 50);
115
116     $session->executeScript($reset_js);
117
118     // Click on a fragment link pointing to an invisible child inside a closed
119     // details element.
120     $session->executeScript("jQuery('<a href=\"$child_selector\"></a>').insertAfter('h1')[0].click()");
121
122     // Assert that the child is visible again after a fragment link click.
123     $web_assert->waitForElementVisible('css', $child_selector, 50);
124
125     // Find the summary belonging to the closest details element.
126     $summary = $page->find('css', '#edit-meta > summary');
127
128     // Assert that both aria-expanded and aria-pressed are true.
129     $this->assertTrue($summary->getAttribute('aria-expanded'));
130     $this->assertTrue($summary->getAttribute('aria-pressed'));
131   }
132
133 }