public function BookContentModerationTest::testBookWithPendingRevisions in Drupal 9
Same name and namespace in other branches
- 8 core/modules/book/tests/src/Functional/BookContentModerationTest.php \Drupal\Tests\book\Functional\BookContentModerationTest::testBookWithPendingRevisions()
Tests that book drafts can not modify the book outline.
File
- core/
modules/ book/ tests/ src/ Functional/ BookContentModerationTest.php, line 64
Class
- BookContentModerationTest
- Tests Book and Content Moderation integration.
Namespace
Drupal\Tests\book\FunctionalCode
public function testBookWithPendingRevisions() {
// Create two books.
$book_1_nodes = $this
->createBook([
'moderation_state[0][state]' => 'published',
]);
$book_1 = $this->book;
$this
->createBook([
'moderation_state[0][state]' => 'published',
]);
$book_2 = $this->book;
$this
->drupalLogin($this->bookAuthor);
// Check that book pages display along with the correct outlines.
$this->book = $book_1;
$this
->checkBookNode($book_1, [
$book_1_nodes[0],
$book_1_nodes[3],
$book_1_nodes[4],
], FALSE, FALSE, $book_1_nodes[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,
]);
// Create a new book page without actually attaching it to a book and create
// a draft.
$edit = [
'title[0][value]' => $this
->randomString(),
'moderation_state[0][state]' => 'published',
];
$this
->drupalGet('node/add/book');
$this
->submitForm($edit, 'Save');
$node = $this
->drupalGetNodeByTitle($edit['title[0][value]']);
$this
->assertNotEmpty($node);
$edit = [
'moderation_state[0][state]' => 'draft',
];
$this
->drupalGet('node/' . $node
->id() . '/edit');
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextNotContains('You can only change the book outline for the published version of this content.');
// Create a book draft with no changes, then publish it.
$edit = [
'moderation_state[0][state]' => 'draft',
];
$this
->drupalGet('node/' . $book_1
->id() . '/edit');
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextNotContains('You can only change the book outline for the published version of this content.');
$edit = [
'moderation_state[0][state]' => 'published',
];
$this
->drupalGet('node/' . $book_1
->id() . '/edit');
$this
->submitForm($edit, 'Save');
// Try to move Node 2 to a different parent.
$edit = [
'book[pid]' => $book_1_nodes[3]
->id(),
'moderation_state[0][state]' => 'draft',
];
$this
->drupalGet('node/' . $book_1_nodes[1]
->id() . '/edit');
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains('You can only change the book outline for the published version of this content.');
// Check that the book outline did not change.
$this->book = $book_1;
$this
->checkBookNode($book_1, [
$book_1_nodes[0],
$book_1_nodes[3],
$book_1_nodes[4],
], FALSE, FALSE, $book_1_nodes[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,
]);
// Try to move Node 2 to a different book.
$edit = [
'book[bid]' => $book_2
->id(),
'moderation_state[0][state]' => 'draft',
];
$this
->drupalGet('node/' . $book_1_nodes[1]
->id() . '/edit');
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains('You can only change the book outline for the published version of this content.');
// Check that the book outline did not change.
$this->book = $book_1;
$this
->checkBookNode($book_1, [
$book_1_nodes[0],
$book_1_nodes[3],
$book_1_nodes[4],
], FALSE, FALSE, $book_1_nodes[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,
]);
// Try to change the weight of Node 2.
$edit = [
'book[weight]' => 2,
'moderation_state[0][state]' => 'draft',
];
$this
->drupalGet('node/' . $book_1_nodes[1]
->id() . '/edit');
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains('You can only change the book outline for the published version of this content.');
// Check that the book outline did not change.
$this->book = $book_1;
$this
->checkBookNode($book_1, [
$book_1_nodes[0],
$book_1_nodes[3],
$book_1_nodes[4],
], FALSE, FALSE, $book_1_nodes[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,
]);
// Save a new draft revision for the node without any changes and check that
// the error message is not displayed.
$edit = [
'moderation_state[0][state]' => 'draft',
];
$this
->drupalGet('node/' . $book_1_nodes[1]
->id() . '/edit');
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextNotContains('You can only change the book outline for the published version of this content.');
}