LayoutBuilderTestTrait.php in Layout Builder Symmetric Translations 8
File
tests/src/FunctionalJavascript/LayoutBuilderTestTrait.php
View source
<?php
namespace Drupal\Tests\layout_builder_st\FunctionalJavascript;
trait LayoutBuilderTestTrait {
protected function addBlock($block_link_text, $rendered_locator, $label_display = FALSE, $label = NULL) {
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$add_block_text = 'Add block';
if (version_compare(\Drupal::VERSION, '8.8.0', '<')) {
$add_block_text = ucwords($add_block_text);
}
$this
->assertNotEmpty($assert_session
->waitForElementVisible('css', "#layout-builder a:contains('{$add_block_text}')"));
$this
->clickLink($add_block_text);
$this
->assertNotEmpty($assert_session
->waitForElementVisible('css', '#drupal-off-canvas'));
$assert_session
->assertWaitOnAjaxRequest();
$assert_session
->linkExists($block_link_text);
$this
->clickLink($block_link_text);
$this
->assertNotEmpty($assert_session
->waitForElementVisible('css', ".layout-builder-add-block"));
$assert_session
->assertWaitOnAjaxRequest();
if ($label_display) {
$page
->checkField('settings[label_display]');
}
if ($label !== NULL) {
$page
->fillField('settings[label]', $label);
}
$page
->pressButton($add_block_text);
$this
->assertNotEmpty($assert_session
->waitForElement('css', $rendered_locator));
}
public function assertNoElementAfterWait($selector, $timeout = 10000, $message = '') {
$page = $this
->getSession()
->getPage();
if ($message === '') {
$message = "Element '{$selector}' was not on the page after wait.";
}
$this
->assertTrue($page
->waitFor($timeout / 1000, function () use ($page, $selector) {
return empty($page
->find('css', $selector));
}), $message);
}
}