class SystemMenuBlockUiTest
Test the #states on the system menu block form.
Attributes
#[Group('Block')]
#[RunTestsInSeparateProcesses]
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\PhpUnitCompatibilityTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\FunctionalJavascriptTests\WebDriverTestBase extends \Drupal\Tests\BrowserTestBase
- class \Drupal\Tests\system\FunctionalJavascript\Block\SystemMenuBlockUiTest extends \Drupal\FunctionalJavascriptTests\WebDriverTestBase
- class \Drupal\FunctionalJavascriptTests\WebDriverTestBase extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of SystemMenuBlockUiTest
File
-
core/
modules/ system/ tests/ src/ FunctionalJavascript/ Block/ SystemMenuBlockUiTest.php, line 15
Namespace
Drupal\Tests\system\FunctionalJavascript\BlockView source
class SystemMenuBlockUiTest extends WebDriverTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'block',
'system',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
// Create and log in an administrative user.
$user = $this->drupalCreateUser([
'administer blocks',
'access administration pages',
]);
$this->drupalLogin($user);
}
/**
* Tests that add_active_trail_class field states based on other form values.
*/
public function testSystemMenuBlockForm() : void {
$this->drupalGet(Url::fromRoute('block.admin_add', [
'plugin_id' => 'system_menu_block:admin',
'theme' => 'stark',
]));
$page = $this->getSession()
->getPage();
$page->findById('edit-settings-menu-levels')
->click();
$levelField = $page->findField('settings[level]');
$depthField = $page->findField('settings[depth]');
// On first form when adding the menu block, the level should be set to 1,
// "expand_all_items" unchecked, and "add_active_trail_class" checkbox is
// required.
$this->assertEquals('1', $levelField->getValue());
$this->assertEquals('0', $depthField->getValue());
$expandField = $page->findField('settings[expand_all_items]');
$this->assertFalse($expandField->isChecked());
$addActiveTrailField = $page->findField('settings[add_active_trail_class]');
$this->assertTrue($addActiveTrailField->hasAttribute('required'));
// Setting the depth value to '1' should mean the checkbox is no longer
// required.
$depthField->setValue('1');
$this->assertFalse($addActiveTrailField->hasAttribute('required'));
// Clicking on "expand_all_items" makes "add_active_trail_class" not required
// when level is 1.
$depthField->setValue('0');
$this->assertTrue($addActiveTrailField->hasAttribute('required'));
$expandField->click();
$this->assertFalse($addActiveTrailField->hasAttribute('required'));
// Setting level to a value greater than one makes "add_active_trail_class"
// required.
$levelField->setValue('2');
$this->assertTrue($addActiveTrailField->hasAttribute('required'));
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.