You are here

function BookTestCase::testBookDelete in Drupal 7

Tests the access for deleting top-level book nodes.

File

modules/book/book.test, line 377
Tests for book.module.

Class

BookTestCase
Tests the functionality of the Book module.

Code

function testBookDelete() {
  $nodes = $this
    ->createBook();
  $this
    ->drupalLogin($this->admin_user);
  $edit = array();

  // Test access to delete top-level and child book nodes.
  $this
    ->drupalGet('node/' . $this->book->nid . '/outline/remove');
  $this
    ->assertResponse('403', 'Deleting top-level book node properly forbidden.');
  $this
    ->drupalPost('node/' . $nodes[4]->nid . '/outline/remove', $edit, t('Remove'));
  $node4 = node_load($nodes[4]->nid, NULL, TRUE);
  $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->nid;
  }
  node_delete_multiple($nids);
  $this
    ->drupalPost('node/' . $this->book->nid . '/outline/remove', $edit, t('Remove'));
  $node = node_load($this->book->nid, NULL, TRUE);
  $this
    ->assertTrue(empty($node->book), 'Deleting childless top-level book node properly allowed.');
}