class ModerationRevisionRevertTest
Same name and namespace in other branches
- 11.x core/modules/content_moderation/tests/src/Functional/ModerationRevisionRevertTest.php \Drupal\Tests\content_moderation\Functional\ModerationRevisionRevertTest
- 10 core/modules/content_moderation/tests/src/Functional/ModerationRevisionRevertTest.php \Drupal\Tests\content_moderation\Functional\ModerationRevisionRevertTest
- 8.9.x core/modules/content_moderation/tests/src/Functional/ModerationRevisionRevertTest.php \Drupal\Tests\content_moderation\Functional\ModerationRevisionRevertTest
Test revision revert.
@group content_moderation
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait implements \PHPUnit\Framework\TestCase
- class \Drupal\Tests\content_moderation\Functional\ModerationRevisionRevertTest uses \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait implements \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of ModerationRevisionRevertTest
File
-
core/
modules/ content_moderation/ tests/ src/ Functional/ ModerationRevisionRevertTest.php, line 14
Namespace
Drupal\Tests\content_moderation\FunctionalView source
class ModerationRevisionRevertTest extends BrowserTestBase {
use ContentTypeCreationTrait;
use ContentModerationTestTrait;
/**
* Modules to enable.
*
* @var array
*/
protected static $modules = [
'content_moderation',
'node',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
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();
/** @var \Drupal\Core\Routing\RouteBuilderInterface $router_builder */
$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);
}
/**
* Tests that reverting a revision works.
*/
public function testEditingAfterRevertRevision() {
// Create a draft.
$this->drupalGet('node/add/moderated_bundle');
$this->submitForm([
'title[0][value]' => 'First draft node',
'moderation_state[0][state]' => 'draft',
], 'Save');
// Now make it published.
$this->drupalGet('node/1/edit');
$this->submitForm([
'title[0][value]' => 'Published node',
'moderation_state[0][state]' => 'published',
], 'Save');
// Check the editing form that show the published title.
$this->drupalGet('node/1/edit');
$this->assertSession()
->pageTextContains('Published node');
// Revert the first revision.
$revision_url = 'node/1/revisions/1/revert';
$this->drupalGet($revision_url);
$this->assertSession()
->elementExists('css', '.form-submit');
$this->click('.form-submit');
// Check that it reverted.
$this->drupalGet('node/1/edit');
$this->assertSession()
->pageTextContains('First draft node');
// Try to save the node.
$this->drupalGet('node/1/edit');
$this->submitForm([
'moderation_state[0][state]' => 'draft',
], 'Save');
// Check if the submission passed the EntityChangedConstraintValidator.
$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.');
// Check the node has been saved.
$this->assertSession()
->pageTextContains('moderated_bundle First draft node has been updated');
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.