protected function LayoutBuilderLockTest::checkContextualLinks in Layout Builder Lock 8
Check contextual links.
Parameters
\Drupal\Tests\WebAssert $assert_session:
bool $locked:
Throws
\Behat\Mink\Exception\ElementNotFoundException
1 call to LayoutBuilderLockTest::checkContextualLinks()
- LayoutBuilderLockTest::checkLinksAndAccess in tests/
src/ Functional/ LayoutBuilderLockTest.php - Checks links and access.
File
- tests/
src/ Functional/ LayoutBuilderLockTest.php, line 501
Class
- LayoutBuilderLockTest
- Tests Layout Builder Lock.
Namespace
Drupal\Tests\layout_builder_lock\FunctionalCode
protected function checkContextualLinks(WebAssert $assert_session, $locked = FALSE) {
// Parse contextual links - target body field.
$id = $assert_session
->elementExists('css', '.layout-builder__region > div:nth-child(3) > div');
$value = $id
->getAttribute('data-contextual-id');
$has_layout_builder_lock_element = FALSE;
$layout_builder_lock_elements = $layout_builder_block_elements = [];
$elements = explode('&', $value);
foreach ($elements as $element) {
// Layout Builder Lock element.
if (strpos($element, 'layout_builder_lock') !== FALSE) {
$has_layout_builder_lock_element = TRUE;
$layout_builder_lock_elements = explode(':', str_replace([
'%3A',
'layout_builder_lock=',
], [
':',
'',
], $element));
}
// Layout Builder Block elements.
if (strpos($element, 'operations') !== FALSE) {
$ex = explode(':', $element, 2);
$layout_builder_block_elements = explode(':', str_replace([
'%3A',
'operations=',
], [
':',
'',
], $ex[1]));
}
}
if ($locked) {
if ($has_layout_builder_lock_element) {
self::assertTrue(in_array('layout_builder_block_move', $layout_builder_lock_elements));
self::assertTrue(!in_array('move', $layout_builder_block_elements));
self::assertTrue(in_array('layout_builder_block_update', $layout_builder_lock_elements));
self::assertTrue(!in_array('update', $layout_builder_block_elements));
self::assertTrue(in_array('layout_builder_block_remove', $layout_builder_lock_elements));
self::assertTrue(!in_array('remove', $layout_builder_block_elements));
}
else {
// Trigger an explicit fail.
self::assertTrue($has_layout_builder_lock_element);
}
}
else {
self::assertTrue(empty($has_layout_builder_lock_element));
self::assertTrue(in_array('move', $layout_builder_block_elements));
self::assertTrue(in_array('update', $layout_builder_block_elements));
self::assertTrue(in_array('remove', $layout_builder_block_elements));
}
}