PageEditTest.php in Drupal 10
File
core/modules/block_content/tests/src/Functional/PageEditTest.php
View source
<?php
namespace Drupal\Tests\block_content\Functional;
use Drupal\block_content\Entity\BlockContent;
class PageEditTest extends BlockContentTestBase {
protected $defaultTheme = 'stark';
protected function setUp() : void {
parent::setUp();
$this
->drupalPlaceBlock('page_title_block');
}
public function testPageEdit() {
$this
->drupalLogin($this->adminUser);
$title_key = 'info[0][value]';
$body_key = 'body[0][value]';
$edit = [];
$edit['info[0][value]'] = mb_strtolower($this
->randomMachineName(8));
$edit[$body_key] = $this
->randomMachineName(16);
$this
->drupalGet('block/add/basic');
$this
->submitForm($edit, 'Save');
$blocks = \Drupal::entityQuery('block_content')
->accessCheck(FALSE)
->condition('info', $edit['info[0][value]'])
->execute();
$block = BlockContent::load(reset($blocks));
$this
->assertNotEmpty($block, 'Custom block found in database.');
$this
->drupalGet('block/' . $block
->id());
$this
->assertSession()
->fieldValueEquals($title_key, $edit[$title_key]);
$this
->assertSession()
->fieldValueEquals($body_key, $edit[$body_key]);
$edit = [];
$edit[$title_key] = $this
->randomMachineName(8);
$edit[$body_key] = $this
->randomMachineName(16);
$this
->submitForm($edit, 'Save');
$this
->drupalGet("block/" . $block
->id());
$edit = [];
$edit['info[0][value]'] = $this
->randomMachineName(8);
$edit[$body_key] = $this
->randomMachineName(16);
$edit['revision'] = TRUE;
$this
->submitForm($edit, 'Save');
\Drupal::entityTypeManager()
->getStorage('block_content')
->resetCache([
$block
->id(),
]);
$revised_block = BlockContent::load($block
->id());
$this
->assertNotSame($block
->getRevisionId(), $revised_block
->getRevisionId(), 'A new revision has been created.');
$this
->drupalGet("block/" . $revised_block
->id());
$this
->clickLink('Delete');
$this
->assertSession()
->pageTextContains('Are you sure you want to delete the custom block ' . $revised_block
->label() . '?');
}
}