Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / book / tests / src / Functional / BookContentModerationTest.php
1 <?php
2
3 namespace Drupal\Tests\book\Functional;
4
5 use Drupal\Tests\BrowserTestBase;
6 use Drupal\workflows\Entity\Workflow;
7
8 /**
9  * Tests Book and Content Moderation integration.
10  *
11  * @group book
12  */
13 class BookContentModerationTest extends BrowserTestBase {
14
15   use BookTestTrait;
16
17   /**
18    * Modules to install.
19    *
20    * @var array
21    */
22   public static $modules = ['book', 'block', 'book_test', 'content_moderation'];
23
24   /**
25    * {@inheritdoc}
26    */
27   protected function setUp() {
28     parent::setUp();
29
30     $this->drupalPlaceBlock('system_breadcrumb_block');
31     $this->drupalPlaceBlock('page_title_block');
32
33     $workflow = Workflow::load('editorial');
34     $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'book');
35     $workflow->save();
36
37     // We need a user with additional content moderation permissions.
38     $this->bookAuthor = $this->drupalCreateUser(['create new books', 'create book content', 'edit own book content', 'add content to books', 'access printer-friendly version', 'view any unpublished content', 'use editorial transition create_new_draft', 'use editorial transition publish']);
39   }
40
41   /**
42    * Tests that book drafts can not modify the book outline.
43    */
44   public function testBookWithPendingRevisions() {
45     // Create two books.
46     $book_1_nodes = $this->createBook(['moderation_state[0][state]' => 'published']);
47     $book_1 = $this->book;
48
49     $this->createBook(['moderation_state[0][state]' => 'published']);
50     $book_2 = $this->book;
51
52     $this->drupalLogin($this->bookAuthor);
53
54     // Check that book pages display along with the correct outlines.
55     $this->book = $book_1;
56     $this->checkBookNode($book_1, [$book_1_nodes[0], $book_1_nodes[3], $book_1_nodes[4]], FALSE, FALSE, $book_1_nodes[0], []);
57     $this->checkBookNode($book_1_nodes[0], [$book_1_nodes[1], $book_1_nodes[2]], $book_1, $book_1, $book_1_nodes[1], [$book_1]);
58
59     // Create a new book page without actually attaching it to a book and create
60     // a draft.
61     $edit = [
62       'title[0][value]' => $this->randomString(),
63       'moderation_state[0][state]' => 'published',
64     ];
65     $this->drupalPostForm('node/add/book', $edit, t('Save'));
66     $node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
67     $this->assertTrue($node);
68
69     $edit = [
70       'moderation_state[0][state]' => 'draft',
71     ];
72     $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
73     $this->assertSession()->pageTextNotContains('You can only change the book outline for the published version of this content.');
74
75     // Create a book draft with no changes, then publish it.
76     $edit = [
77       'moderation_state[0][state]' => 'draft',
78     ];
79     $this->drupalPostForm('node/' . $book_1->id() . '/edit', $edit, t('Save'));
80     $this->assertSession()->pageTextNotContains('You can only change the book outline for the published version of this content.');
81     $edit = [
82       'moderation_state[0][state]' => 'published',
83     ];
84     $this->drupalPostForm('node/' . $book_1->id() . '/edit', $edit, t('Save'));
85
86     // Try to move Node 2 to a different parent.
87     $edit = [
88       'book[pid]' => $book_1_nodes[3]->id(),
89       'moderation_state[0][state]' => 'draft',
90     ];
91     $this->drupalPostForm('node/' . $book_1_nodes[1]->id() . '/edit', $edit, t('Save'));
92
93     $this->assertSession()->pageTextContains('You can only change the book outline for the published version of this content.');
94
95     // Check that the book outline did not change.
96     $this->book = $book_1;
97     $this->checkBookNode($book_1, [$book_1_nodes[0], $book_1_nodes[3], $book_1_nodes[4]], FALSE, FALSE, $book_1_nodes[0], []);
98     $this->checkBookNode($book_1_nodes[0], [$book_1_nodes[1], $book_1_nodes[2]], $book_1, $book_1, $book_1_nodes[1], [$book_1]);
99
100     // Try to move Node 2 to a different book.
101     $edit = [
102       'book[bid]' => $book_2->id(),
103       'moderation_state[0][state]' => 'draft',
104     ];
105     $this->drupalPostForm('node/' . $book_1_nodes[1]->id() . '/edit', $edit, t('Save'));
106
107     $this->assertSession()->pageTextContains('You can only change the book outline for the published version of this content.');
108
109     // Check that the book outline did not change.
110     $this->book = $book_1;
111     $this->checkBookNode($book_1, [$book_1_nodes[0], $book_1_nodes[3], $book_1_nodes[4]], FALSE, FALSE, $book_1_nodes[0], []);
112     $this->checkBookNode($book_1_nodes[0], [$book_1_nodes[1], $book_1_nodes[2]], $book_1, $book_1, $book_1_nodes[1], [$book_1]);
113
114     // Try to change the weight of Node 2.
115     $edit = [
116       'book[weight]' => 2,
117       'moderation_state[0][state]' => 'draft',
118     ];
119     $this->drupalPostForm('node/' . $book_1_nodes[1]->id() . '/edit', $edit, t('Save'));
120
121     $this->assertSession()->pageTextContains('You can only change the book outline for the published version of this content.');
122
123     // Check that the book outline did not change.
124     $this->book = $book_1;
125     $this->checkBookNode($book_1, [$book_1_nodes[0], $book_1_nodes[3], $book_1_nodes[4]], FALSE, FALSE, $book_1_nodes[0], []);
126     $this->checkBookNode($book_1_nodes[0], [$book_1_nodes[1], $book_1_nodes[2]], $book_1, $book_1, $book_1_nodes[1], [$book_1]);
127
128     // Save a new draft revision for the node without any changes and check that
129     // the error message is not displayed.
130     $edit = [
131       'moderation_state[0][state]' => 'draft',
132     ];
133     $this->drupalPostForm('node/' . $book_1_nodes[1]->id() . '/edit', $edit, t('Save'));
134
135     $this->assertSession()->pageTextNotContains('You can only change the book outline for the published version of this content.');
136   }
137
138 }