function BlockContentCreationTest::testBlockContentFormSubmitHandlers
Same name in other branches
- 10 core/modules/block_content/tests/src/Functional/BlockContentCreationTest.php \Drupal\Tests\block_content\Functional\BlockContentCreationTest::testBlockContentFormSubmitHandlers()
Tests the redirect workflow of creating a block_content and block.
File
-
core/
modules/ block_content/ tests/ src/ Functional/ BlockContentCreationTest.php, line 152
Class
- BlockContentCreationTest
- Create a block and test saving it.
Namespace
Drupal\Tests\block_content\FunctionalCode
public function testBlockContentFormSubmitHandlers() : void {
$this->drupalLogin($this->adminUser);
// Create a block and place in block layout.
$this->drupalGet('/admin/content/block');
$this->clickLink('Add content block');
// Verify destination URL, when clicking "Save and configure" this
// destination will be ignored.
$base = base_path();
$url = 'block/add?destination=' . $base . 'admin/content/block';
$this->assertSession()
->addressEquals($url);
$edit = [];
$edit['info[0][value]'] = 'Test Block';
$edit['body[0][value]'] = $this->randomMachineName(16);
$this->submitForm($edit, 'Save and configure');
$this->assertSession()
->pageTextContains('basic ' . $edit['info[0][value]'] . ' has been created.');
$this->assertSession()
->pageTextContains('Configure block');
// Verify when editing a block "Save and configure" does not appear.
$this->drupalGet('/admin/content/block/1');
$this->assertSession()
->buttonNotExists('Save and configure');
// Create a block but go back to block library.
$edit = [];
$edit['info[0][value]'] = 'Test Block';
$edit['body[0][value]'] = $this->randomMachineName(16);
$this->drupalGet('block/add/basic');
$this->submitForm($edit, 'Save');
// Check that the Basic block has been created.
$this->assertSession()
->pageTextContains('basic ' . $edit['info[0][value]'] . ' has been created.');
$this->assertSession()
->addressEquals('/admin/content/block');
// Check that the user is redirected to the block library on edit.
$block = $this->getBlockByLabel($edit['info[0][value]']);
$this->drupalGet($block->toUrl('edit-form'));
$this->submitForm([
'info[0][value]' => 'Test Block Updated',
], 'Save');
$this->assertSession()
->addressEquals('admin/content/block');
// Test with user who doesn't have permission to place a block.
$this->drupalLogin($this->drupalCreateUser([
'administer block content',
]));
$this->drupalGet('block/add/basic');
$this->assertSession()
->buttonNotExists('Save and configure');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.