3 namespace Drupal\Tests\book\Functional;
5 use Drupal\Tests\BrowserTestBase;
6 use Drupal\workflows\Entity\Workflow;
9 * Tests Book and Content Moderation integration.
13 class BookContentModerationTest extends BrowserTestBase {
22 public static $modules = ['book', 'block', 'book_test', 'content_moderation'];
27 protected function setUp() {
30 $this->drupalPlaceBlock('system_breadcrumb_block');
31 $this->drupalPlaceBlock('page_title_block');
33 $workflow = Workflow::load('editorial');
34 $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'book');
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']);
42 * Tests that book drafts can not modify the book outline.
44 public function testBookWithPendingRevisions() {
46 $book_1_nodes = $this->createBook(['moderation_state[0][state]' => 'published']);
47 $book_1 = $this->book;
49 $this->createBook(['moderation_state[0][state]' => 'published']);
50 $book_2 = $this->book;
52 $this->drupalLogin($this->bookAuthor);
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]);
59 // Create a new book page without actually attaching it to a book and create
62 'title[0][value]' => $this->randomString(),
63 'moderation_state[0][state]' => 'published',
65 $this->drupalPostForm('node/add/book', $edit, t('Save'));
66 $node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
67 $this->assertTrue($node);
70 'moderation_state[0][state]' => 'draft',
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.');
75 // Create a book draft with no changes, then publish it.
77 'moderation_state[0][state]' => 'draft',
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.');
82 'moderation_state[0][state]' => 'published',
84 $this->drupalPostForm('node/' . $book_1->id() . '/edit', $edit, t('Save'));
86 // Try to move Node 2 to a different parent.
88 'book[pid]' => $book_1_nodes[3]->id(),
89 'moderation_state[0][state]' => 'draft',
91 $this->drupalPostForm('node/' . $book_1_nodes[1]->id() . '/edit', $edit, t('Save'));
93 $this->assertSession()->pageTextContains('You can only change the book outline for the published version of this content.');
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]);
100 // Try to move Node 2 to a different book.
102 'book[bid]' => $book_2->id(),
103 'moderation_state[0][state]' => 'draft',
105 $this->drupalPostForm('node/' . $book_1_nodes[1]->id() . '/edit', $edit, t('Save'));
107 $this->assertSession()->pageTextContains('You can only change the book outline for the published version of this content.');
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]);
114 // Try to change the weight of Node 2.
117 'moderation_state[0][state]' => 'draft',
119 $this->drupalPostForm('node/' . $book_1_nodes[1]->id() . '/edit', $edit, t('Save'));
121 $this->assertSession()->pageTextContains('You can only change the book outline for the published version of this content.');
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]);
128 // Save a new draft revision for the node without any changes and check that
129 // the error message is not displayed.
131 'moderation_state[0][state]' => 'draft',
133 $this->drupalPostForm('node/' . $book_1_nodes[1]->id() . '/edit', $edit, t('Save'));
135 $this->assertSession()->pageTextNotContains('You can only change the book outline for the published version of this content.');