Chris@0: drupalPlaceBlock('system_breadcrumb_block'); Chris@0: $this->drupalPlaceBlock('page_title_block'); Chris@0: Chris@17: $workflow = $this->createEditorialWorkflow(); Chris@0: $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'book'); Chris@0: $workflow->save(); Chris@0: Chris@0: // We need a user with additional content moderation permissions. Chris@0: $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']); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests that book drafts can not modify the book outline. Chris@0: */ Chris@0: public function testBookWithPendingRevisions() { Chris@0: // Create two books. Chris@0: $book_1_nodes = $this->createBook(['moderation_state[0][state]' => 'published']); Chris@0: $book_1 = $this->book; Chris@0: Chris@0: $this->createBook(['moderation_state[0][state]' => 'published']); Chris@0: $book_2 = $this->book; Chris@0: Chris@0: $this->drupalLogin($this->bookAuthor); Chris@0: Chris@0: // Check that book pages display along with the correct outlines. Chris@0: $this->book = $book_1; Chris@0: $this->checkBookNode($book_1, [$book_1_nodes[0], $book_1_nodes[3], $book_1_nodes[4]], FALSE, FALSE, $book_1_nodes[0], []); Chris@0: $this->checkBookNode($book_1_nodes[0], [$book_1_nodes[1], $book_1_nodes[2]], $book_1, $book_1, $book_1_nodes[1], [$book_1]); Chris@0: Chris@0: // Create a new book page without actually attaching it to a book and create Chris@0: // a draft. Chris@0: $edit = [ Chris@0: 'title[0][value]' => $this->randomString(), Chris@0: 'moderation_state[0][state]' => 'published', Chris@0: ]; Chris@0: $this->drupalPostForm('node/add/book', $edit, t('Save')); Chris@0: $node = $this->drupalGetNodeByTitle($edit['title[0][value]']); Chris@0: $this->assertTrue($node); Chris@0: Chris@0: $edit = [ Chris@0: 'moderation_state[0][state]' => 'draft', Chris@0: ]; Chris@0: $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save')); Chris@0: $this->assertSession()->pageTextNotContains('You can only change the book outline for the published version of this content.'); Chris@0: Chris@0: // Create a book draft with no changes, then publish it. Chris@0: $edit = [ Chris@0: 'moderation_state[0][state]' => 'draft', Chris@0: ]; Chris@0: $this->drupalPostForm('node/' . $book_1->id() . '/edit', $edit, t('Save')); Chris@0: $this->assertSession()->pageTextNotContains('You can only change the book outline for the published version of this content.'); Chris@0: $edit = [ Chris@0: 'moderation_state[0][state]' => 'published', Chris@0: ]; Chris@0: $this->drupalPostForm('node/' . $book_1->id() . '/edit', $edit, t('Save')); Chris@0: Chris@0: // Try to move Node 2 to a different parent. Chris@0: $edit = [ Chris@0: 'book[pid]' => $book_1_nodes[3]->id(), Chris@0: 'moderation_state[0][state]' => 'draft', Chris@0: ]; Chris@0: $this->drupalPostForm('node/' . $book_1_nodes[1]->id() . '/edit', $edit, t('Save')); Chris@0: Chris@0: $this->assertSession()->pageTextContains('You can only change the book outline for the published version of this content.'); Chris@0: Chris@0: // Check that the book outline did not change. Chris@0: $this->book = $book_1; Chris@0: $this->checkBookNode($book_1, [$book_1_nodes[0], $book_1_nodes[3], $book_1_nodes[4]], FALSE, FALSE, $book_1_nodes[0], []); Chris@0: $this->checkBookNode($book_1_nodes[0], [$book_1_nodes[1], $book_1_nodes[2]], $book_1, $book_1, $book_1_nodes[1], [$book_1]); Chris@0: Chris@0: // Try to move Node 2 to a different book. Chris@0: $edit = [ Chris@0: 'book[bid]' => $book_2->id(), Chris@0: 'moderation_state[0][state]' => 'draft', Chris@0: ]; Chris@0: $this->drupalPostForm('node/' . $book_1_nodes[1]->id() . '/edit', $edit, t('Save')); Chris@0: Chris@0: $this->assertSession()->pageTextContains('You can only change the book outline for the published version of this content.'); Chris@0: Chris@0: // Check that the book outline did not change. Chris@0: $this->book = $book_1; Chris@0: $this->checkBookNode($book_1, [$book_1_nodes[0], $book_1_nodes[3], $book_1_nodes[4]], FALSE, FALSE, $book_1_nodes[0], []); Chris@0: $this->checkBookNode($book_1_nodes[0], [$book_1_nodes[1], $book_1_nodes[2]], $book_1, $book_1, $book_1_nodes[1], [$book_1]); Chris@0: Chris@0: // Try to change the weight of Node 2. Chris@0: $edit = [ Chris@0: 'book[weight]' => 2, Chris@0: 'moderation_state[0][state]' => 'draft', Chris@0: ]; Chris@0: $this->drupalPostForm('node/' . $book_1_nodes[1]->id() . '/edit', $edit, t('Save')); Chris@0: Chris@0: $this->assertSession()->pageTextContains('You can only change the book outline for the published version of this content.'); Chris@0: Chris@0: // Check that the book outline did not change. Chris@0: $this->book = $book_1; Chris@0: $this->checkBookNode($book_1, [$book_1_nodes[0], $book_1_nodes[3], $book_1_nodes[4]], FALSE, FALSE, $book_1_nodes[0], []); Chris@0: $this->checkBookNode($book_1_nodes[0], [$book_1_nodes[1], $book_1_nodes[2]], $book_1, $book_1, $book_1_nodes[1], [$book_1]); Chris@0: Chris@0: // Save a new draft revision for the node without any changes and check that Chris@0: // the error message is not displayed. Chris@0: $edit = [ Chris@0: 'moderation_state[0][state]' => 'draft', Chris@0: ]; Chris@0: $this->drupalPostForm('node/' . $book_1_nodes[1]->id() . '/edit', $edit, t('Save')); Chris@0: Chris@0: $this->assertSession()->pageTextNotContains('You can only change the book outline for the published version of this content.'); Chris@0: } Chris@0: Chris@0: }