public function GlobalConfigTest::testGlobalConfigForm in Layout Builder Component Attributes 1.1.x
Same name and namespace in other branches
- 1.2.x tests/src/Functional/GlobalConfigTest.php \Drupal\Tests\layout_builder_component_attributes\Functional\GlobalConfigTest::testGlobalConfigForm()
- 1.0.x tests/src/Functional/GlobalConfigTest.php \Drupal\Tests\layout_builder_component_attributes\Functional\GlobalConfigTest::testGlobalConfigForm()
Tests the global config form.
File
- tests/
src/ Functional/ GlobalConfigTest.php, line 50
Class
- GlobalConfigTest
- Test global configuration form and storage.
Namespace
Drupal\Tests\layout_builder_component_attributes\FunctionalCode
public function testGlobalConfigForm() {
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$this
->drupalLogin($this->authUser);
$this
->drupalGet('/admin/config/content/layout-builder-component-attributes');
$assert_session
->statusCodeEquals(403);
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('/admin/config/content/layout-builder-component-attributes');
$assert_session
->pageTextContains('Layout Builder Component Attributes Settings');
// On install, all attributes are enabled.
$assert_session
->checkboxChecked('allowed_block_attributes[id]');
$assert_session
->checkboxChecked('allowed_block_attributes[class]');
$assert_session
->checkboxChecked('allowed_block_attributes[style]');
$assert_session
->checkboxChecked('allowed_block_attributes[data]');
$assert_session
->checkboxChecked('allowed_block_title_attributes[id]');
$assert_session
->checkboxChecked('allowed_block_title_attributes[class]');
$assert_session
->checkboxChecked('allowed_block_title_attributes[style]');
$assert_session
->checkboxChecked('allowed_block_title_attributes[data]');
$assert_session
->checkboxChecked('allowed_block_content_attributes[id]');
$assert_session
->checkboxChecked('allowed_block_content_attributes[class]');
$assert_session
->checkboxChecked('allowed_block_content_attributes[style]');
$assert_session
->checkboxChecked('allowed_block_content_attributes[data]');
// Disallow some attributes.
$page
->findField('allowed_block_attributes[id]')
->uncheck();
$page
->findField('allowed_block_title_attributes[class]')
->uncheck();
$page
->findField('allowed_block_content_attributes[style]')
->uncheck();
$page
->findField('allowed_block_content_attributes[data]')
->uncheck();
$page
->pressButton('Save configuration');
$assert_session
->pageTextContains('The configuration options have been saved.');
// Check updated config values.
$this
->drupalGet('/admin/config/content/layout-builder-component-attributes');
$assert_session
->checkboxNotChecked('allowed_block_attributes[id]');
$assert_session
->checkboxChecked('allowed_block_attributes[class]');
$assert_session
->checkboxChecked('allowed_block_attributes[style]');
$assert_session
->checkboxChecked('allowed_block_attributes[data]');
$assert_session
->checkboxChecked('allowed_block_title_attributes[id]');
$assert_session
->checkboxNotChecked('allowed_block_title_attributes[class]');
$assert_session
->checkboxChecked('allowed_block_title_attributes[style]');
$assert_session
->checkboxChecked('allowed_block_title_attributes[data]');
$assert_session
->checkboxChecked('allowed_block_content_attributes[id]');
$assert_session
->checkboxChecked('allowed_block_content_attributes[class]');
$assert_session
->checkboxNotChecked('allowed_block_content_attributes[style]');
$assert_session
->checkboxNotChecked('allowed_block_content_attributes[data]');
// Verify storage in config.
$config = \Drupal::service('config.factory')
->getEditable('layout_builder_component_attributes.settings');
$allowed_block_attributes = $config
->get('allowed_block_attributes');
$expected_value = [
'class' => TRUE,
'style' => TRUE,
'data' => TRUE,
'id' => FALSE,
];
$this
->assertIdentical($allowed_block_attributes, $expected_value);
$allowed_block_title_attributes = $config
->get('allowed_block_title_attributes');
$expected_value = [
'id' => TRUE,
'style' => TRUE,
'data' => TRUE,
'class' => FALSE,
];
$this
->assertIdentical($allowed_block_title_attributes, $expected_value);
$allowed_block_content_attributes = $config
->get('allowed_block_content_attributes');
$expected_value = [
'id' => TRUE,
'class' => TRUE,
'style' => FALSE,
'data' => FALSE,
];
$this
->assertIdentical($allowed_block_content_attributes, $expected_value);
}