View source
<?php
namespace Drupal\Tests\layout_builder_restrictions\FunctionalJavascript;
class LanguageCategoriesTest extends LayoutBuilderRestrictionsTestBase {
protected static $modules = [
'language',
'locale',
'block',
'help',
'layout_builder',
'layout_builder_restrictions',
'node',
'field_ui',
'block_content',
];
protected function setUp() : void {
parent::setUp();
$this
->drupalLogin($this
->drupalCreateUser([
'administer languages',
'access administration pages',
'administer blocks',
'administer node display',
'administer node fields',
'configure any layout',
'create and edit custom blocks',
]));
$edit = [];
$edit['predefined_langcode'] = 'nb';
$this
->drupalGet('admin/config/regional/language/add');
$this
->submitForm($edit, t('Add language'));
$edit = [
'site_default_language' => 'nb',
];
$this
->drupalGet('admin/config/regional/language');
$this
->submitForm($edit, t('Save configuration'));
$edit = [
'language_interface[enabled][language-url]' => 1,
];
$this
->drupalGet('admin/config/regional/language/detection');
$this
->submitForm($edit, t('Save settings'));
$edit = [
'prefix[en]' => 'en',
'prefix[nb]' => '',
];
$this
->drupalGet('admin/config/regional/language/detection/url');
$this
->submitForm($edit, t('Save configuration'));
$locale_storage = $this->container
->get('locale.storage');
$string = NULL;
$strings = $locale_storage
->getStrings([
'source' => '@entity fields',
]);
if (!empty($strings)) {
$string = reset($strings);
}
else {
$string = $locale_storage
->createString([
'source' => '@entity fields',
])
->save();
}
$locale_storage
->createTranslation([
'lid' => $string
->getId(),
'language' => 'nb',
'translation' => '@entity felter',
])
->save();
$strings = $locale_storage
->getStrings([
'source' => 'Help',
]);
if (!empty($strings)) {
$string = reset($strings);
}
else {
$string = $locale_storage
->createString([
'source' => 'Help',
])
->save();
}
$locale_storage
->createTranslation([
'lid' => $string
->getId(),
'language' => 'nb',
'translation' => 'Hjelp',
])
->save();
}
public function testBlockRestriction() {
$blocks = $this
->generateTestBlocks();
$node_id = $this
->generateTestNode();
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$this
->navigateToNodeSettingsTray($node_id);
$assert_session
->linkExists('Body');
$assert_session
->linkExists('Hjelp');
$this
->navigateToManageDisplay();
$element = $page
->find('xpath', '//*[@id="edit-layout-layout-builder-restrictions-allowed-blocks"]/summary');
$element
->click();
$element = $page
->find('xpath', '//*[@id="edit-layout-builder-restrictions-allowed-blocks-content-fields-restriction-all"]');
$assert_session
->checkboxChecked('edit-layout-builder-restrictions-allowed-blocks-content-fields-restriction-all');
$assert_session
->checkboxNotChecked('edit-layout-builder-restrictions-allowed-blocks-content-fields-restriction-whitelisted');
$assert_session
->checkboxChecked('edit-layout-builder-restrictions-allowed-blocks-inline-blocks-restriction-all');
$assert_session
->checkboxNotChecked('edit-layout-builder-restrictions-allowed-blocks-inline-blocks-restriction-whitelisted');
$element = $page
->find('xpath', '//*[@id="edit-layout-builder-restrictions-allowed-blocks-content-fields-restriction-whitelisted"]');
$element
->click();
$element = $page
->find('xpath', '//*[@id="edit-layout-builder-restrictions-allowed-blocks-help-restriction-whitelisted"]');
$element
->click();
$element = $page
->find('xpath', '//*[@id="edit-layout-builder-restrictions-allowed-blocks-help-available-blocks-help-block"]');
$element
->click();
$page
->pressButton('Save');
$this
->navigateToNodeSettingsTray($node_id);
$assert_session
->linkNotExists('Body');
$assert_session
->linkExists('Hjelp');
}
}