SimpleBlockLayoutBuilderTest.php in Simple Block 8
File
modules/simple_block_layout_builder/tests/scr/FunctionalJavascript/SimpleBlockLayoutBuilderTest.php
View source
<?php
namespace Drupal\Tests\simple_block_layout_builder\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\Tests\contextual\FunctionalJavascript\ContextualLinkClickTrait;
use Drupal\node\Entity\NodeType;
class SimpleBlockLayoutBuilderTest extends WebDriverTestBase {
use ContextualLinkClickTrait;
protected static $modules = [
'block',
'contextual',
'field_ui',
'node',
'simple_block_layout_builder',
];
protected $defaultTheme = 'classy';
public function testIntegration() : void {
NodeType::create([
'type' => 'page',
])
->save();
$this
->drupalLogin($this
->createUser([
'access contextual links',
'administer blocks',
'administer content types',
'administer node display',
'administer node fields',
'configure any layout',
]));
$this
->drupalGet('/admin/structure/types/manage/page/display');
$page = $this
->getSession()
->getPage();
$assert = $this
->assertSession();
$this
->submitForm([
'layout[enabled]' => TRUE,
], 'Save');
$this
->clickLink('Manage layout');
$this
->clickLink('Add block');
$assert
->assertWaitOnAjaxRequest();
$assert
->linkExists('Create simple block');
$page
->clickLink('Create simple block');
$assert
->assertWaitOnAjaxRequest();
$page
->findField('Title')
->setValue('Just a simple block');
$this
->assertJsCondition('jQuery("html:contains(\'just_a_simple_block\')")');
$this
->createScreenshot('/tmp/a.png');
$page
->findField('Content')
->setValue('Lorem ipsum dolor sit amet');
$page
->pressButton('Save');
$assert
->assertWaitOnAjaxRequest();
$this
->drupalGet('/admin/structure/types/manage/page/display/default/layout');
$assert
->pageTextContains('Lorem ipsum dolor sit amet');
$this
->clickContextualLink('#layout-builder .block-simple-block', 'Configure', TRUE);
$assert
->assertWaitOnAjaxRequest();
$page
->findField('Content')
->setValue('You know... the brown fox');
$page
->pressButton('Save');
$assert
->assertWaitOnAjaxRequest();
$this
->drupalGet('/admin/structure/types/manage/page/display/default/layout');
$assert
->pageTextContains('You know... the brown fox');
$page
->pressButton('Save layout');
$page
->pressButton('Save');
$this
->drupalGet('/node/add/page');
$this
->submitForm([
'title[0][value]' => 'Whatever',
], 'Save');
$assert
->pageTextContains('Whatever has been created.');
$assert
->pageTextContains('You know... the brown fox');
$node_url = $this
->getSession()
->getCurrentUrl();
$this
->drupalGet('/admin/structure/types/manage/page/display/default/layout');
$this
->clickContextualLink('#layout-builder .block-simple-block', 'Remove block', TRUE);
$assert
->assertWaitOnAjaxRequest();
$assert
->pageTextContains('Are you sure you want to remove the Just a simple block block?');
$assert
->pageTextContains('This action cannot be undone.');
$page
->pressButton('Remove');
$assert
->assertWaitOnAjaxRequest();
$this
->drupalGet('/admin/structure/types/manage/page/display/default/layout');
$assert
->pageTextNotContains('You know... the brown fox');
$page
->pressButton('Save layout');
$page
->pressButton('Save');
$this
->drupalGet($node_url);
$assert
->pageTextNotContains('You know... the brown fox');
}
}