Chris@0: installEntitySchema('user'); Chris@0: $this->installEntitySchema('node'); Chris@0: $this->installSchema('book', ['book']); Chris@0: $this->installSchema('node', ['node_access']); Chris@0: $this->installConfig(['node', 'book', 'field']); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests pending revision handling for books. Chris@0: */ Chris@0: public function testBookWithPendingRevisions() { Chris@0: $content_type = NodeType::create([ Chris@0: 'type' => $this->randomMachineName(), Chris@0: 'name' => $this->randomString(), Chris@0: ]); Chris@0: $content_type->save(); Chris@0: $book_config = $this->config('book.settings'); Chris@0: $allowed_types = $book_config->get('allowed_types'); Chris@0: $allowed_types[] = $content_type->id(); Chris@0: $book_config->set('allowed_types', $allowed_types)->save(); Chris@0: Chris@0: // Create two top-level books a child. Chris@0: $book_1 = Node::create(['title' => $this->randomString(), 'type' => $content_type->id()]); Chris@0: $book_1->book['bid'] = 'new'; Chris@0: $book_1->save(); Chris@0: $book_1_child = Node::create(['title' => $this->randomString(), 'type' => $content_type->id()]); Chris@0: $book_1_child->book['bid'] = $book_1->id(); Chris@0: $book_1_child->book['pid'] = $book_1->id(); Chris@0: $book_1_child->save(); Chris@0: Chris@0: $book_2 = Node::create(['title' => $this->randomString(), 'type' => $content_type->id()]); Chris@0: $book_2->book['bid'] = 'new'; Chris@0: $book_2->save(); Chris@0: Chris@0: $child = Node::create(['title' => $this->randomString(), 'type' => $content_type->id()]); Chris@0: $child->book['bid'] = $book_1->id(); Chris@0: $child->book['pid'] = $book_1->id(); Chris@0: $child->save(); Chris@0: Chris@0: // Try to move the child to a different book while saving it as a pending Chris@0: // revision. Chris@0: /** @var \Drupal\book\BookManagerInterface $book_manager */ Chris@0: $book_manager = $this->container->get('book.manager'); Chris@0: Chris@0: // Check that the API doesn't allow us to change the book outline for Chris@0: // pending revisions. Chris@0: $child->book['bid'] = $book_2->id(); Chris@0: $child->setNewRevision(TRUE); Chris@0: $child->isDefaultRevision(FALSE); Chris@0: Chris@0: $this->assertFalse($book_manager->updateOutline($child), 'A pending revision can not change the book outline.'); Chris@0: Chris@0: // Check that the API doesn't allow us to change the book parent for Chris@0: // pending revisions. Chris@0: $child = \Drupal::entityTypeManager()->getStorage('node')->loadUnchanged($child->id()); Chris@0: $child->book['pid'] = $book_1_child->id(); Chris@0: $child->setNewRevision(TRUE); Chris@0: $child->isDefaultRevision(FALSE); Chris@0: Chris@0: $this->assertFalse($book_manager->updateOutline($child), 'A pending revision can not change the book outline.'); Chris@0: Chris@0: // Check that the API doesn't allow us to change the book weight for Chris@0: // pending revisions. Chris@0: $child = \Drupal::entityTypeManager()->getStorage('node')->loadUnchanged($child->id()); Chris@0: $child->book['weight'] = 2; Chris@0: $child->setNewRevision(TRUE); Chris@0: $child->isDefaultRevision(FALSE); Chris@0: Chris@0: $this->assertFalse($book_manager->updateOutline($child), 'A pending revision can not change the book outline.'); Chris@0: } Chris@0: Chris@0: }