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: // For uninstall to work. Chris@0: $this->installSchema('user', ['users_data']); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests the book_system_info_alter() method. Chris@0: */ Chris@0: public function testBookUninstall() { Chris@0: // No nodes exist. Chris@0: $validation_reasons = \Drupal::service('module_installer')->validateUninstall(['book']); Chris@0: $this->assertEqual([], $validation_reasons, 'The book module is not required.'); Chris@0: 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: $node = Node::create(['title' => $this->randomString(), 'type' => $content_type->id()]); Chris@0: $node->book['bid'] = 'new'; Chris@0: $node->save(); Chris@0: Chris@0: // One node in a book but not of type book. Chris@0: $validation_reasons = \Drupal::service('module_installer')->validateUninstall(['book']); Chris@0: $this->assertEqual(['To uninstall Book, delete all content that is part of a book'], $validation_reasons['book']); Chris@0: Chris@0: $book_node = Node::create(['title' => $this->randomString(), 'type' => 'book']); Chris@0: $book_node->book['bid'] = FALSE; Chris@0: $book_node->save(); Chris@0: Chris@0: // Two nodes, one in a book but not of type book and one book node (which is Chris@0: // not in a book). Chris@0: $validation_reasons = \Drupal::service('module_installer')->validateUninstall(['book']); Chris@0: $this->assertEqual(['To uninstall Book, delete all content that is part of a book'], $validation_reasons['book']); Chris@0: Chris@0: $node->delete(); Chris@0: // One node of type book but not actually part of a book. Chris@0: $validation_reasons = \Drupal::service('module_installer')->validateUninstall(['book']); Chris@0: $this->assertEqual(['To uninstall Book, delete all content that has the Book content type'], $validation_reasons['book']); Chris@0: Chris@0: $book_node->delete(); Chris@0: // No nodes exist therefore the book module is not required. Chris@17: $module_data = \Drupal::service('extension.list.module')->reset()->getList(); Chris@0: $this->assertFalse(isset($module_data['book']->info['required']), 'The book module is not required.'); Chris@0: Chris@0: $node = Node::create(['title' => $this->randomString(), 'type' => $content_type->id()]); Chris@0: $node->save(); Chris@0: // One node exists but is not part of a book therefore the book module is Chris@0: // not required. Chris@0: $validation_reasons = \Drupal::service('module_installer')->validateUninstall(['book']); Chris@0: $this->assertEqual([], $validation_reasons, 'The book module is not required.'); Chris@0: Chris@0: // Uninstall the Book module and check the node type is deleted. Chris@0: \Drupal::service('module_installer')->uninstall(['book']); Chris@0: $this->assertNull(NodeType::load('book'), "The book node type does not exist."); Chris@0: } Chris@0: Chris@0: }