X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fsystem%2Fsrc%2FTests%2FForm%2FElementsVerticalTabsTest.php;fp=web%2Fcore%2Fmodules%2Fsystem%2Fsrc%2FTests%2FForm%2FElementsVerticalTabsTest.php;h=3ef90e13a190d86bd491232d518b7f732bf6f498;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/core/modules/system/src/Tests/Form/ElementsVerticalTabsTest.php b/web/core/modules/system/src/Tests/Form/ElementsVerticalTabsTest.php new file mode 100644 index 000000000..3ef90e13a --- /dev/null +++ b/web/core/modules/system/src/Tests/Form/ElementsVerticalTabsTest.php @@ -0,0 +1,89 @@ +adminUser = $this->drupalCreateUser(['access vertical_tab_test tabs']); + $this->webUser = $this->drupalCreateUser(); + $this->drupalLogin($this->adminUser); + } + + /** + * Ensures that vertical-tabs.js is included before collapse.js. + * + * Otherwise, collapse.js adds "SHOW" or "HIDE" labels to the tabs. + */ + public function testJavaScriptOrdering() { + $this->drupalGet('form_test/vertical-tabs'); + $position1 = strpos($this->content, 'core/misc/vertical-tabs.js'); + $position2 = strpos($this->content, 'core/misc/collapse.js'); + $this->assertTrue($position1 !== FALSE && $position2 !== FALSE && $position1 < $position2, 'vertical-tabs.js is included before collapse.js'); + } + + /** + * Ensures that vertical tab markup is not shown if user has no tab access. + */ + public function testWrapperNotShownWhenEmpty() { + // Test admin user can see vertical tabs and wrapper. + $this->drupalGet('form_test/vertical-tabs'); + $wrapper = $this->xpath("//div[@data-vertical-tabs-panes]"); + $this->assertTrue(isset($wrapper[0]), 'Vertical tab panes found.'); + + // Test wrapper markup not present for non-privileged web user. + $this->drupalLogin($this->webUser); + $this->drupalGet('form_test/vertical-tabs'); + $wrapper = $this->xpath("//div[@data-vertical-tabs-panes]"); + $this->assertFalse(isset($wrapper[0]), 'Vertical tab wrappers are not displayed to unprivileged users.'); + } + + /** + * Ensures that default vertical tab is correctly selected. + */ + public function testDefaultTab() { + $this->drupalGet('form_test/vertical-tabs'); + $this->assertFieldByName('vertical_tabs__active_tab', 'edit-tab3', t('The default vertical tab is correctly selected.')); + } + + /** + * Ensures that vertical tab form values are cleaned. + */ + public function testDefaultTabCleaned() { + $values = Json::decode($this->drupalPostForm('form_test/form-state-values-clean', [], t('Submit'))); + $this->assertFalse(isset($values['vertical_tabs__active_tab']), SafeMarkup::format('%element was removed.', ['%element' => 'vertical_tabs__active_tab'])); + } + +}