
| Current Path : /var/www/html/12park/web/core/modules/system/tests/src/Functional/Form/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : /var/www/html/12park/web/core/modules/system/tests/src/Functional/Form/ElementsVerticalTabsTest.php |
<?php
declare(strict_types=1);
namespace Drupal\Tests\system\Functional\Form;
use Drupal\Component\Serialization\Json;
use Drupal\Tests\BrowserTestBase;
/**
* Tests the vertical_tabs form element for expected behavior.
*
* @group Form
*/
class ElementsVerticalTabsTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = ['form_test'];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* A user with permission to access vertical_tab_test_tabs.
*
* @var \Drupal\user\UserInterface
*/
protected $adminUser;
/**
* A normal user.
*
* @var \Drupal\user\UserInterface
*/
protected $webUser;
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$this->adminUser = $this->drupalCreateUser([
'access vertical_tab_test tabs',
]);
$this->webUser = $this->drupalCreateUser();
$this->drupalLogin($this->adminUser);
}
/**
* Ensures that vertical tab markup is not shown if user has no tab access.
*/
public function testWrapperNotShownWhenEmpty(): void {
// Test admin user can see vertical tabs and wrapper.
$this->drupalGet('form_test/vertical-tabs');
$this->assertSession()->elementExists('xpath', "//div[@data-vertical-tabs-panes]");
// Test wrapper markup not present for non-privileged web user.
$this->drupalLogin($this->webUser);
$this->drupalGet('form_test/vertical-tabs');
$this->assertSession()->elementNotExists('xpath', "//div[@data-vertical-tabs-panes]");
}
/**
* Ensures that default vertical tab is correctly selected.
*/
public function testDefaultTab(): void {
$this->drupalGet('form_test/vertical-tabs');
$this->assertSession()->elementAttributeContains('css', 'input[name="vertical_tabs__active_tab"]', 'value', 'edit-tab3');
}
/**
* Ensures that vertical tab form values are cleaned.
*/
public function testDefaultTabCleaned(): void {
$this->drupalGet('form_test/form-state-values-clean');
$this->submitForm([], 'Submit');
$values = Json::decode($this->getSession()->getPage()->getContent());
$this->assertFalse(isset($values['vertical_tabs__active_tab']), 'vertical_tabs__active_tab was removed.');
}
}