annotate core/modules/book/tests/src/Kernel/BookPendingRevisionTest.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 4c8ae668cc8c
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\Tests\book\Kernel;
Chris@0 4
Chris@0 5 use Drupal\node\Entity\Node;
Chris@0 6 use Drupal\node\Entity\NodeType;
Chris@0 7 use Drupal\KernelTests\KernelTestBase;
Chris@0 8
Chris@0 9 /**
Chris@0 10 * Tests that the Book module handles pending revisions correctly.
Chris@0 11 *
Chris@0 12 * @group book
Chris@0 13 */
Chris@0 14 class BookPendingRevisionTest extends KernelTestBase {
Chris@0 15
Chris@0 16 /**
Chris@0 17 * Modules to enable.
Chris@0 18 *
Chris@0 19 * @var array
Chris@0 20 */
Chris@0 21 public static $modules = ['system', 'user', 'field', 'filter', 'text', 'node', 'book'];
Chris@0 22
Chris@0 23 /**
Chris@0 24 * {@inheritdoc}
Chris@0 25 */
Chris@0 26 protected function setUp() {
Chris@0 27 parent::setUp();
Chris@0 28
Chris@0 29 $this->installEntitySchema('user');
Chris@0 30 $this->installEntitySchema('node');
Chris@0 31 $this->installSchema('book', ['book']);
Chris@0 32 $this->installSchema('node', ['node_access']);
Chris@0 33 $this->installConfig(['node', 'book', 'field']);
Chris@0 34 }
Chris@0 35
Chris@0 36 /**
Chris@0 37 * Tests pending revision handling for books.
Chris@0 38 */
Chris@0 39 public function testBookWithPendingRevisions() {
Chris@0 40 $content_type = NodeType::create([
Chris@0 41 'type' => $this->randomMachineName(),
Chris@0 42 'name' => $this->randomString(),
Chris@0 43 ]);
Chris@0 44 $content_type->save();
Chris@0 45 $book_config = $this->config('book.settings');
Chris@0 46 $allowed_types = $book_config->get('allowed_types');
Chris@0 47 $allowed_types[] = $content_type->id();
Chris@0 48 $book_config->set('allowed_types', $allowed_types)->save();
Chris@0 49
Chris@0 50 // Create two top-level books a child.
Chris@0 51 $book_1 = Node::create(['title' => $this->randomString(), 'type' => $content_type->id()]);
Chris@0 52 $book_1->book['bid'] = 'new';
Chris@0 53 $book_1->save();
Chris@0 54 $book_1_child = Node::create(['title' => $this->randomString(), 'type' => $content_type->id()]);
Chris@0 55 $book_1_child->book['bid'] = $book_1->id();
Chris@0 56 $book_1_child->book['pid'] = $book_1->id();
Chris@0 57 $book_1_child->save();
Chris@0 58
Chris@0 59 $book_2 = Node::create(['title' => $this->randomString(), 'type' => $content_type->id()]);
Chris@0 60 $book_2->book['bid'] = 'new';
Chris@0 61 $book_2->save();
Chris@0 62
Chris@0 63 $child = Node::create(['title' => $this->randomString(), 'type' => $content_type->id()]);
Chris@0 64 $child->book['bid'] = $book_1->id();
Chris@0 65 $child->book['pid'] = $book_1->id();
Chris@0 66 $child->save();
Chris@0 67
Chris@0 68 // Try to move the child to a different book while saving it as a pending
Chris@0 69 // revision.
Chris@0 70 /** @var \Drupal\book\BookManagerInterface $book_manager */
Chris@0 71 $book_manager = $this->container->get('book.manager');
Chris@0 72
Chris@0 73 // Check that the API doesn't allow us to change the book outline for
Chris@0 74 // pending revisions.
Chris@0 75 $child->book['bid'] = $book_2->id();
Chris@0 76 $child->setNewRevision(TRUE);
Chris@0 77 $child->isDefaultRevision(FALSE);
Chris@0 78
Chris@0 79 $this->assertFalse($book_manager->updateOutline($child), 'A pending revision can not change the book outline.');
Chris@0 80
Chris@0 81 // Check that the API doesn't allow us to change the book parent for
Chris@0 82 // pending revisions.
Chris@0 83 $child = \Drupal::entityTypeManager()->getStorage('node')->loadUnchanged($child->id());
Chris@0 84 $child->book['pid'] = $book_1_child->id();
Chris@0 85 $child->setNewRevision(TRUE);
Chris@0 86 $child->isDefaultRevision(FALSE);
Chris@0 87
Chris@0 88 $this->assertFalse($book_manager->updateOutline($child), 'A pending revision can not change the book outline.');
Chris@0 89
Chris@0 90 // Check that the API doesn't allow us to change the book weight for
Chris@0 91 // pending revisions.
Chris@0 92 $child = \Drupal::entityTypeManager()->getStorage('node')->loadUnchanged($child->id());
Chris@0 93 $child->book['weight'] = 2;
Chris@0 94 $child->setNewRevision(TRUE);
Chris@0 95 $child->isDefaultRevision(FALSE);
Chris@0 96
Chris@0 97 $this->assertFalse($book_manager->updateOutline($child), 'A pending revision can not change the book outline.');
Chris@0 98 }
Chris@0 99
Chris@0 100 }