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