ElementsVerticalTabsTest.php in Zircon Profile 8
File
core/modules/system/src/Tests/Form/ElementsVerticalTabsTest.php
View source
<?php
namespace Drupal\system\Tests\Form;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\simpletest\WebTestBase;
use Drupal\Component\Serialization\Json;
class ElementsVerticalTabsTest extends WebTestBase {
public static $modules = array(
'form_test',
);
protected $adminUser;
protected $webUser;
protected function setUp() {
parent::setUp();
$this->adminUser = $this
->drupalCreateUser(array(
'access vertical_tab_test tabs',
));
$this->webUser = $this
->drupalCreateUser();
$this
->drupalLogin($this->adminUser);
}
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');
}
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.');
}
function testDefaultTab() {
$this
->drupalGet('form_test/vertical-tabs');
$this
->assertFieldByName('vertical_tabs__active_tab', 'edit-tab3', t('The default vertical tab is correctly selected.'));
}
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',
]));
}
}