ModerationRevisionRevertTest.php in Drupal 9
File
core/modules/content_moderation/tests/src/Functional/ModerationRevisionRevertTest.php
View source
<?php
namespace Drupal\Tests\content_moderation\Functional;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait;
use Drupal\Tests\node\Traits\ContentTypeCreationTrait;
class ModerationRevisionRevertTest extends BrowserTestBase {
use ContentTypeCreationTrait;
use ContentModerationTestTrait;
protected static $modules = [
'content_moderation',
'node',
];
protected $defaultTheme = 'stark';
public function setUp() : void {
parent::setUp();
$moderated_bundle = $this
->createContentType([
'type' => 'moderated_bundle',
]);
$moderated_bundle
->save();
$workflow = $this
->createEditorialWorkflow();
$workflow
->getTypePlugin()
->addEntityTypeAndBundle('node', 'moderated_bundle');
$workflow
->save();
$router_builder = $this->container
->get('router.builder');
$router_builder
->rebuildIfNeeded();
$admin = $this
->drupalCreateUser([
'access content overview',
'administer nodes',
'bypass node access',
'view all revisions',
'use editorial transition create_new_draft',
'use editorial transition publish',
]);
$this
->drupalLogin($admin);
}
public function testEditingAfterRevertRevision() {
$this
->drupalGet('node/add/moderated_bundle');
$this
->submitForm([
'title[0][value]' => 'First draft node',
'moderation_state[0][state]' => 'draft',
], 'Save');
$this
->drupalGet('node/1/edit');
$this
->submitForm([
'title[0][value]' => 'Published node',
'moderation_state[0][state]' => 'published',
], 'Save');
$this
->drupalGet('node/1/edit');
$this
->assertSession()
->pageTextContains('Published node');
$revision_url = 'node/1/revisions/1/revert';
$this
->drupalGet($revision_url);
$this
->assertSession()
->elementExists('css', '.form-submit');
$this
->click('.form-submit');
$this
->drupalGet('node/1/edit');
$this
->assertSession()
->pageTextContains('First draft node');
$this
->drupalGet('node/1/edit');
$this
->submitForm([
'moderation_state[0][state]' => 'draft',
], 'Save');
$this
->assertSession()
->pageTextNotContains('The content has either been modified by another user, or you have already submitted modifications. As a result, your changes cannot be saved.');
$this
->assertSession()
->pageTextContains('moderated_bundle First draft node has been updated');
}
}