ElementsVerticalTabsTest.php in Drupal 8
File
core/modules/system/tests/src/Functional/Form/ElementsVerticalTabsTest.php
View source
<?php
namespace Drupal\Tests\system\Functional\Form;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Component\Serialization\Json;
use Drupal\Tests\BrowserTestBase;
class ElementsVerticalTabsTest extends BrowserTestBase {
public static $modules = [
'form_test',
];
protected $defaultTheme = 'stark';
protected $adminUser;
protected $webUser;
protected function setUp() {
parent::setUp();
$this->adminUser = $this
->drupalCreateUser([
'access vertical_tab_test tabs',
]);
$this->webUser = $this
->drupalCreateUser();
$this
->drupalLogin($this->adminUser);
}
public function testJavaScriptOrdering() {
$this
->drupalGet('form_test/vertical-tabs');
$content = $this
->getSession()
->getPage()
->getContent();
$position1 = strpos($content, 'core/misc/vertical-tabs.js');
$position2 = strpos($content, 'core/misc/collapse.js');
$this
->assertTrue($position1 !== FALSE && $position2 !== FALSE && $position1 < $position2, 'vertical-tabs.js is included before collapse.js');
}
public function testWrapperNotShownWhenEmpty() {
$this
->drupalGet('form_test/vertical-tabs');
$wrapper = $this
->xpath("//div[@data-vertical-tabs-panes]");
$this
->assertTrue(isset($wrapper[0]), 'Vertical tab panes found.');
$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.');
}
public function testDefaultTab() {
$this
->drupalGet('form_test/vertical-tabs');
$value = $this
->assertSession()
->elementExists('css', 'input[name="vertical_tabs__active_tab"]')
->getValue();
$this
->assertSame('edit-tab3', $value, t('The default vertical tab is correctly selected.'));
}
public function testDefaultTabCleaned() {
$values = Json::decode($this
->drupalPostForm('form_test/form-state-values-clean', [], t('Submit')));
$this
->assertFalse(isset($values['vertical_tabs__active_tab']), new FormattableMarkup('%element was removed.', [
'%element' => 'vertical_tabs__active_tab',
]));
}
}