3 namespace Drupal\diff\Tests;
4 use Drupal\workflows\Entity\Workflow;
7 * Tests the revision overview with content moderation enabled.
11 class DiffRevisionContentModerationTest extends DiffRevisionTest {
16 public static $modules = ['content_moderation'];
21 protected function setUp() {
24 // Enable moderation on articles.
25 /** @var \Drupal\workflows\WorkflowInterface $workflow */
26 $workflow = Workflow::load('editorial');
27 /** @var \Drupal\content_moderation\Plugin\WorkflowType\ContentModeration $plugin */
28 $plugin = $workflow->getTypePlugin();
29 $plugin->addEntityTypeAndBundle('node', 'article');
32 // Add necessary admin permissions for moderated content.
33 $this->adminPermissions = array_merge([
34 'use editorial transition create_new_draft',
35 'use editorial transition publish',
36 'use editorial transition archive',
37 'use editorial transition archived_draft',
38 'use editorial transition archived_published',
39 'view latest version',
40 'view any unpublished content',
41 ], $this->adminPermissions);
47 * Override form submission to work with content moderation.
49 protected function drupalPostNodeForm($path, array $edit, $submit) {
50 // New revisions are automatically enabled, so remove the manual value.
51 unset($edit['revision']);
52 parent::drupalPostNodeForm($path, $edit, $submit);
58 public function testAll() {
59 // Ensure revision tab still works as expected.
62 // Specifically test for content moderation functionality.
63 $this->doTestContentModeration();
67 * Test content moderation integration.
69 protected function doTestContentModeration() {
70 $title = $this->randomString();
71 $node = $this->createNode([
74 'revision_log' => 'First revision',
78 $node->title = $title . ' change 1';
79 $node->revision_log = 'Second revision';
83 $node->moderation_state = 'published';
84 $node->revision_log = 'Third revision';
88 $node->title = $title . ' change 2';
89 $node->moderation_state = 'draft';
90 $node->revision_log = 'Fourth revision';
93 // Verify moderation state information appears on revision overview.
94 $this->drupalGet($node->toUrl('version-history'));
96 // Verify proper moderation states are displayed.
97 $diff_rows = $this->xpath('//tbody/tr/td[1]/p');
98 $this->assertEqual('Fourth revision (Draft)', (string) $diff_rows[0]);
99 $this->assertEqual('Third revision (Published)', (string) $diff_rows[1]);
100 $this->assertEqual('Second revision (Draft)', (string) $diff_rows[2]);
101 $this->assertEqual('First revision (Draft)', (string) $diff_rows[3]);