Updated all the contrib modules to their latest versions.
[yaffs-website] / web / modules / contrib / diff / src / Tests / DiffRevisionContentModerationTest.php
1 <?php
2
3 namespace Drupal\diff\Tests;
4 use Drupal\workflows\Entity\Workflow;
5
6 /**
7  * Tests the revision overview with content moderation enabled.
8  *
9  * @group diff
10  */
11 class DiffRevisionContentModerationTest extends DiffRevisionTest {
12
13   /**
14    * {@inheritdoc}
15    */
16   public static $modules = ['content_moderation'];
17
18   /**
19    * {@inheritdoc}
20    */
21   protected function setUp() {
22     parent::setUp();
23
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');
30     $workflow->save();
31
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);
42   }
43
44   /**
45    * {@inheritdoc}
46    *
47    * Override form submission to work with content moderation.
48    */
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);
53   }
54
55   /**
56    * {@inheritdoc}
57    */
58   public function testAll() {
59     // Ensure revision tab still works as expected.
60     parent::testAll();
61
62     // Specifically test for content moderation functionality.
63     $this->doTestContentModeration();
64   }
65
66   /**
67    * Test content moderation integration.
68    */
69   protected function doTestContentModeration() {
70     $title = $this->randomString();
71     $node = $this->createNode([
72       'type' => 'article',
73       'title' => $title,
74       'revision_log' => 'First revision',
75     ]);
76
77     // Add another draft.
78     $node->title = $title . ' change 1';
79     $node->revision_log = 'Second revision';
80     $node->save();
81
82     // Publish.
83     $node->moderation_state = 'published';
84     $node->revision_log = 'Third revision';
85     $node->save();
86
87     // Another draft.
88     $node->title = $title . ' change 2';
89     $node->moderation_state = 'draft';
90     $node->revision_log = 'Fourth revision';
91     $node->save();
92
93     // Verify moderation state information appears on revision overview.
94     $this->drupalGet($node->toUrl('version-history'));
95
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]);
102   }
103
104 }