3 namespace Drupal\Tests\content_moderation\Functional;
5 use Drupal\Tests\BrowserTestBase;
6 use Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait;
9 * Tests moderated content administration page functionality.
11 * @group content_moderation
13 class ModeratedContentViewTest extends BrowserTestBase {
15 use ContentModerationTestTrait;
18 * A user with permission to bypass access content.
20 * @var \Drupal\Core\Session\AccountInterface
27 public static $modules = ['content_moderation', 'node', 'views'];
32 public function setUp() {
35 $this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page'])->save();
36 $this->drupalCreateContentType(['type' => 'article', 'name' => 'Article'])->save();
37 $this->drupalCreateContentType(['type' => 'unmoderated_type', 'name' => 'Unmoderated type'])->save();
39 $workflow = $this->createEditorialWorkflow();
40 $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'page');
41 $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'article');
44 $this->adminUser = $this->drupalCreateUser(['access administration pages', 'view any unpublished content', 'administer nodes', 'bypass node access']);
48 * Tests the moderated content page.
50 public function testModeratedContentPage() {
51 $assert_sesison = $this->assertSession();
52 $this->drupalLogin($this->adminUser);
54 // Use an explicit changed time to ensure the expected order in the content
55 // admin listing. We want these to appear in the table in the same order as
56 // they appear in the following code, and the 'moderated_content' view has a
57 // table style configuration with a default sort on the 'changed' field
59 $time = \Drupal::time()->getRequestTime();
60 $excluded_nodes['published_page'] = $this->drupalCreateNode(['type' => 'page', 'changed' => $time--, 'moderation_state' => 'published']);
61 $excluded_nodes['published_article'] = $this->drupalCreateNode(['type' => 'article', 'changed' => $time--, 'moderation_state' => 'published']);
63 $excluded_nodes['unmoderated_type'] = $this->drupalCreateNode(['type' => 'unmoderated_type', 'changed' => $time--]);
64 $excluded_nodes['unmoderated_type']->setNewRevision(TRUE);
65 $excluded_nodes['unmoderated_type']->isDefaultRevision(FALSE);
66 $excluded_nodes['unmoderated_type']->changed->value = $time--;
67 $excluded_nodes['unmoderated_type']->save();
69 $nodes['published_then_draft_article'] = $this->drupalCreateNode(['type' => 'article', 'changed' => $time--, 'moderation_state' => 'published', 'title' => 'first article - published']);
70 $nodes['published_then_draft_article']->setNewRevision(TRUE);
71 $nodes['published_then_draft_article']->setTitle('first article - draft');
72 $nodes['published_then_draft_article']->moderation_state->value = 'draft';
73 $nodes['published_then_draft_article']->changed->value = $time--;
74 $nodes['published_then_draft_article']->save();
76 $nodes['published_then_archived_article'] = $this->drupalCreateNode(['type' => 'article', 'changed' => $time--, 'moderation_state' => 'published']);
77 $nodes['published_then_archived_article']->setNewRevision(TRUE);
78 $nodes['published_then_archived_article']->moderation_state->value = 'archived';
79 $nodes['published_then_archived_article']->changed->value = $time--;
80 $nodes['published_then_archived_article']->save();
82 $nodes['draft_article'] = $this->drupalCreateNode(['type' => 'article', 'changed' => $time--, 'moderation_state' => 'draft']);
83 $nodes['draft_page_1'] = $this->drupalCreateNode(['type' => 'page', 'changed' => $time--, 'moderation_state' => 'draft']);
84 $nodes['draft_page_2'] = $this->drupalCreateNode(['type' => 'page', 'changed' => $time, 'moderation_state' => 'draft']);
86 // Verify view, edit, and delete links for any content.
87 $this->drupalGet('admin/content/moderated');
88 $assert_sesison->statusCodeEquals(200);
90 // Check that nodes with pending revisions appear in the view.
91 $node_type_labels = $this->xpath('//td[contains(@class, "views-field-type")]');
93 foreach ($nodes as $node) {
94 $assert_sesison->linkByHrefExists('node/' . $node->id());
95 $assert_sesison->linkByHrefExists('node/' . $node->id() . '/edit');
96 $assert_sesison->linkByHrefExists('node/' . $node->id() . '/delete');
97 // Verify that we can see the content type label.
98 $this->assertEquals($node->type->entity->label(), trim($node_type_labels[$delta]->getText()));
102 // Check that nodes that are not moderated or do not have a pending revision
103 // do not appear in the view.
104 foreach ($excluded_nodes as $node) {
105 $assert_sesison->linkByHrefNotExists('node/' . $node->id());
108 // Check that the latest revision is displayed.
109 $assert_sesison->pageTextContains('first article - draft');
110 $assert_sesison->pageTextNotContains('first article - published');
112 // Verify filtering by moderation state.
113 $this->drupalGet('admin/content/moderated', ['query' => ['moderation_state' => 'editorial-draft']]);
115 $assert_sesison->linkByHrefExists('node/' . $nodes['published_then_draft_article']->id() . '/edit');
116 $assert_sesison->linkByHrefExists('node/' . $nodes['draft_article']->id() . '/edit');
117 $assert_sesison->linkByHrefExists('node/' . $nodes['draft_page_1']->id() . '/edit');
118 $assert_sesison->linkByHrefExists('node/' . $nodes['draft_page_1']->id() . '/edit');
119 $assert_sesison->linkByHrefNotExists('node/' . $nodes['published_then_archived_article']->id() . '/edit');
121 // Verify filtering by moderation state and content type.
122 $this->drupalGet('admin/content/moderated', ['query' => ['moderation_state' => 'editorial-draft', 'type' => 'page']]);
124 $assert_sesison->linkByHrefExists('node/' . $nodes['draft_page_1']->id() . '/edit');
125 $assert_sesison->linkByHrefExists('node/' . $nodes['draft_page_2']->id() . '/edit');
126 $assert_sesison->linkByHrefNotExists('node/' . $nodes['published_then_draft_article']->id() . '/edit');
127 $assert_sesison->linkByHrefNotExists('node/' . $nodes['published_then_archived_article']->id() . '/edit');
128 $assert_sesison->linkByHrefNotExists('node/' . $nodes['draft_article']->id() . '/edit');