annotate core/modules/book/tests/src/Functional/BookContentModerationTest.php @ 0:4c8ae668cc8c

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