You are here

function BookTest::testBookDelete in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/book/src/Tests/BookTest.php \Drupal\book\Tests\BookTest::testBookDelete()

Tests the access for deleting top-level book nodes.

File

core/modules/book/src/Tests/BookTest.php, line 475
Contains \Drupal\book\Tests\BookTest.

Class

BookTest
Create a book, add pages, and test book interface.

Namespace

Drupal\book\Tests

Code

function testBookDelete() {
  $node_storage = $this->container
    ->get('entity.manager')
    ->getStorage('node');
  $nodes = $this
    ->createBook();
  $this
    ->drupalLogin($this->adminUser);
  $edit = array();

  // Test access to delete top-level and child book nodes.
  $this
    ->drupalGet('node/' . $this->book
    ->id() . '/outline/remove');
  $this
    ->assertResponse('403', 'Deleting top-level book node properly forbidden.');
  $this
    ->drupalPostForm('node/' . $nodes[4]
    ->id() . '/outline/remove', $edit, t('Remove'));
  $node_storage
    ->resetCache(array(
    $nodes[4]
      ->id(),
  ));
  $node4 = $node_storage
    ->load($nodes[4]
    ->id());
  $this
    ->assertTrue(empty($node4->book), 'Deleting child book node properly allowed.');

  // Delete all child book nodes and retest top-level node deletion.
  foreach ($nodes as $node) {
    $nids[] = $node
      ->id();
  }
  entity_delete_multiple('node', $nids);
  $this
    ->drupalPostForm('node/' . $this->book
    ->id() . '/outline/remove', $edit, t('Remove'));
  $node_storage
    ->resetCache(array(
    $this->book
      ->id(),
  ));
  $node = $node_storage
    ->load($this->book
    ->id());
  $this
    ->assertTrue(empty($node->book), 'Deleting childless top-level book node properly allowed.');
}