ModerationStateBlockTest.php in Drupal 10
File
core/modules/content_moderation/tests/src/Functional/ModerationStateBlockTest.php
View source
<?php
namespace Drupal\Tests\content_moderation\Functional;
use Drupal\block_content\Entity\BlockContent;
use Drupal\block_content\Entity\BlockContentType;
class ModerationStateBlockTest extends ModerationStateTestBase {
protected $defaultTheme = 'stark';
protected function setUp() : void {
parent::setUp();
$bundle = BlockContentType::create([
'id' => 'basic',
'label' => 'basic',
'revision' => FALSE,
]);
$bundle
->save();
block_content_add_body_field($bundle
->id());
}
public function testCustomBlockModeration() {
$this
->drupalLogin($this->rootUser);
$edit['bundles[basic]'] = TRUE;
$this
->drupalGet('admin/config/workflow/workflows/manage/editorial/type/block_content');
$this
->submitForm($edit, 'Save');
$body = 'Body of moderated block';
$edit = [
'info[0][value]' => 'Moderated block',
'moderation_state[0][state]' => 'draft',
'body[0][value]' => $body,
];
$this
->drupalGet('block/add');
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains('basic Moderated block has been created.');
$instance = [
'id' => 'moderated_block',
'settings[label]' => $edit['info[0][value]'],
'region' => 'sidebar_first',
];
$block = BlockContent::load(1);
$url = 'admin/structure/block/add/block_content:' . $block
->uuid() . '/' . $this
->config('system.theme')
->get('default');
$this
->drupalGet($url);
$this
->submitForm($instance, 'Save block');
$this
->drupalGet('');
$this
->assertSession()
->pageTextContains($body);
$updated_body = 'This is the new body value';
$edit = [
'body[0][value]' => $updated_body,
'moderation_state[0][state]' => 'draft',
];
$this
->drupalGet('block/' . $block
->id());
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains('basic Moderated block has been updated.');
$this
->drupalGet('');
$this
->assertSession()
->pageTextContains($updated_body);
$this
->drupalGet('block/' . $block
->id());
$this
->submitForm([
'moderation_state[0][state]' => 'published',
], 'Save');
$pending_revision_body = 'This is the pending revision body value';
$edit = [
'body[0][value]' => $pending_revision_body,
'moderation_state[0][state]' => 'draft',
];
$this
->drupalGet('block/' . $block
->id());
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains('basic Moderated block has been updated.');
$this
->drupalGet('');
$this
->assertSession()
->pageTextContains($updated_body);
$edit = [
'new_state' => 'published',
];
$this
->drupalGet('block/' . $block
->id() . '/latest');
$this
->submitForm($edit, 'Apply');
$this
->assertSession()
->pageTextContains('The moderation state has been updated.');
$this
->drupalGet('');
$this
->assertSession()
->pageTextContains($pending_revision_body);
$this
->drupalGet('/block/' . $block
->id());
$this
->assertSession()
->checkboxChecked('revision');
$this
->assertSession()
->pageTextContains('Revisions must be required when moderation is enabled.');
$this
->assertSession()
->fieldDisabled('revision');
}
}