View source
<?php
namespace Drupal\Tests\block_form_alter\Functional;
use Drupal\block_content\Entity\BlockContentType;
use Drupal\Tests\BrowserTestBase;
class BlockFormAlterTest extends BrowserTestBase {
protected $defaultTheme = 'stark';
protected static $modules = [
'block_content',
'block_form_alter',
'block_form_alter_test',
'layout_builder',
'node',
'contextual',
];
protected function setUp() : void {
parent::setUp();
$this
->drupalPlaceBlock('system_menu_block:account');
$this
->drupalPlaceBlock('local_tasks_block');
$this
->drupalPlaceBlock('system_branding_block', [
'label' => 'Branding Block',
'id' => 'systembrandingblock',
]);
$bundle = BlockContentType::create([
'id' => 'test_block',
'label' => 'Test Block',
'revision' => FALSE,
]);
$bundle
->save();
block_content_add_body_field('test_block');
$this
->createContentType([
'type' => 'bundle_with_section_field',
'name' => 'Bundle with section field',
]);
$this
->createNode([
'type' => 'bundle_with_section_field',
'title' => 'The first node title',
'body' => [
[
'value' => 'The first node body',
],
],
]);
$this->adminUser = $this
->drupalCreateUser([
'access administration pages',
'administer blocks',
'bypass node access',
'administer node display',
'access contextual links',
]);
}
public function testBlockFormAlter() {
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('/admin/structure/block/manage/systembrandingblock');
$assert_session
->checkboxNotChecked('settings[block_branding][use_site_logo]');
$this
->drupalGet('/block/add/test_block');
$assert_session
->fieldValueEquals('body[0][value]', 'test body string');
$page
->fillField('info[0][value]', 'Test Block');
$page
->fillField('body[0][value]', 'Some other text');
$page
->pressButton('Save');
$this
->drupalGet('/block/1');
$assert_session
->fieldValueEquals('body[0][value]', 'test body string');
$this
->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default');
$this
->submitForm([
'layout[enabled]' => TRUE,
], 'Save');
$this
->submitForm([
'layout[allow_custom]' => TRUE,
], 'Save');
$this->container
->get('entity_field.manager')
->clearCachedFieldDefinitions();
$this->adminUser = $this
->drupalCreateUser([
'access administration pages',
'administer blocks',
'bypass node access',
'administer node display',
'access contextual links',
'configure editable bundle_with_section_field node layout overrides',
'create and edit custom blocks',
]);
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('node/1');
$page
->clickLink('Layout');
$page
->pressButton('Save layout');
$this
->drupalGet('/layout_builder/add/block/overrides/node.1/0/content/system_branding_block');
$assert_session
->checkboxNotChecked('settings[block_branding][use_site_logo]');
$page
->pressButton('Add block');
$page
->pressButton('Save layout');
$this
->drupalGet('node/1/layout');
$element = $page
->find('xpath', '//div[contains(@class,"block-system-branding-block")]');
$this
->drupalGet('/layout_builder/update/block/overrides/node.1/0/content/' . $element
->getAttribute('data-layout-block-uuid'));
$assert_session
->checkboxNotChecked('settings[block_branding][use_site_logo]');
$this
->drupalGet('/layout_builder/add/block/overrides/node.1/0/content/inline_block:test_block');
$assert_session
->fieldValueEquals('settings[block_form][body][0][value]', 'test body string');
}
}