Index: modules/book/book.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/book/book.test,v
retrieving revision 1.3
diff -u -p -r1.3 book.test
--- modules/book/book.test	15 May 2008 21:19:24 -0000	1.3
+++ modules/book/book.test	10 Sep 2008 03:55:12 -0000
@@ -27,12 +27,12 @@ class BookTestCase extends DrupalWebTest
    */
   function testBook() {
     // Create users.
-    $book_author = $this->drupalCreateUser(array('create new books', 'create book content', 'add content to books'));
+    $book_author = $this->drupalCreateUser(array('create new books', 'create book content', 'add content to books', 'edit any book content', 'administer book outlines', 'access administration pages', 'administer site configuration', 'administer nodes', 'administer content types'));
+   
     $web_user = $this->drupalCreateUser(array('access printer-friendly version'));
 
     // Create new book.
     $this->drupalLogin($book_author);
-
     $this->book = $this->createBookNode('new');
     $book = $this->book;
 
@@ -44,6 +44,7 @@ class BookTestCase extends DrupalWebTest
      *   |- Node 2
      *  |- Node 3
      *  |- Node 4
+     *  |- Node 5
      */
     $nodes = array();
     $nodes[] = $this->createBookNode($book->nid); // Node 0.
@@ -51,18 +52,75 @@ class BookTestCase extends DrupalWebTest
     $nodes[] = $this->createBookNode($book->nid, $nodes[0]->book['mlid']); // Node 2.
     $nodes[] = $this->createBookNode($book->nid); // Node 3.
     $nodes[] = $this->createBookNode($book->nid); // Node 4.
-
+    $nodes[] = $this->createBookNode($book->nid); // Node 5
     $this->drupalLogout();
 
     // Check that book pages display.
     $this->drupalLogin($web_user);
-
-    $this->checkBookNode($book, array($nodes[0], $nodes[3], $nodes[4]), false, false, $nodes[0]);
+    $this->checkBookNode($book, array($nodes[0], $nodes[3], $nodes[4]), FALSE, FALSE, $nodes[0]);
     $this->checkBookNode($nodes[0], array($nodes[1], $nodes[2]), $book, $book, $nodes[1]);
     $this->checkBookNode($nodes[1], NULL, $nodes[0], $nodes[0], $nodes[2]);
     $this->checkBookNode($nodes[2], NULL, $nodes[1], $nodes[0], $nodes[3]);
     $this->checkBookNode($nodes[3], NULL, $nodes[2], $book, $nodes[4]);
-    $this->checkBookNode($nodes[4], NULL, $nodes[3], $book, false);
+    $this->checkBookNode($nodes[4], NULL, $nodes[3], $book, FALSE);
+
+    // Update checks, move the book structure to this.
+    // Book
+    // |- Node 0
+    //  |- Node 1
+    //    | - Node 2
+    //      | - Node 3
+    // | - Node 4
+    // | - Node 5
+    $this->drupalLogin($book_author);
+    $nodes[2] = $this->updateBookNode($book->nid, $nodes[2]->nid, $nodes[1]->book['mlid']);
+    $nodes[3] = $this->updateBookNode($book->nid, $nodes[3]->nid, $nodes[2]->book['mlid']);
+    $this->drupalLogout();
+
+    // Check to ensure the updates worked.
+    $this->drupalLogin($web_user);
+    $this->checkBookNode($nodes[1], array($nodes[2]), FALSE, $nodes[0], FALSE);
+    $this->checkBookNode($nodes[2], array($nodes[3]), FALSE, $nodes[1], FALSE);
+    $this->checkBookNode($nodes[3], NULL, FALSE, $nodes[2], FALSE);
+    $this->drupalLogout();
+
+
+    // Set another content type as a book page.
+    $this->drupalLogin($book_author);
+    $type = $this->drupalCreateContentType();
+    $edit = array(
+      'book_allowed_types[' . $type->type . ']' => $type->type,
+    );
+    $this->drupalPost('admin/content/book/settings', $edit, t('Save configuration'));
+    $nodes[] = $this->createBookNode($book->nid, $book_node, $type->type); // Node 6
+    $this->drupalLogout();
+
+    // Check to see that the new content type was added as a book page.
+    $this->drupalLogin($web_user);
+    $this->checkBookNode($nodes[6], NULL, FALSE, $book, FALSE);
+    $this->drupalLogout();
+
+    // Make articles the default book type.
+    $this->drupalLogin($book_author);
+    $edit = array('book_child_type' => $type->type);
+    $this->drupalPost('admin/content/book/settings', $edit, t('Save configuration'));
+    $this->drupalGet('node/' . $nodes[6]->nid);
+    $this->clickLink(t('Add child page'));
+    $this->assertText(t("Create !title", array('!title' => $type->name)), t("Default child page type correctly set"));
+
+    // Try to delete a book page from a book.
+    node_delete($nodes[0]->nid);
+    $this->drupalLogout();
+
+    // Check that the structure got reorganized.
+    $this->drupalLogin($web_user);
+    $this->drupalGet('node/'. $node[0]->nid);
+    $this->checkBookNode($nodes[1], array($nodes[2]), $book, FALSE, FALSE);
+    $this->checkBookNode($nodes[2], array($nodes[3]), FALSE, $nodes[1], FALSE);
+    $this->checkBookNode($nodes[3], NULL, FALSE, $nodes[2], FALSE);
+    $this->checkBookNode($nodes[4], NULL, FALSE, $book, $nodes[5]);
+    $this->checkBookNode($nodes[5], NULL, $nodes[4], $book, $nodes[6]);
+    $this->checkBooknode($nodes[6], NULL, $nodes[5], $book, FALSE);
   }
 
   /**
@@ -79,10 +137,9 @@ class BookTestCase extends DrupalWebTest
    * @param Node $next
    *   Next link node.
    */
-  function checkBookNode($node, $nodes, $previous = false, $up = false, $next = false) {
+  function checkBookNode($node, $nodes, $previous = FALSE, $up = FALSE, $next = FALSE) {
     static $number = 0;
     $this->drupalGet('node/' . $node->nid);
-
     // Check outline structure.
     if ($nodes !== NULL) {
       $this->assertPattern($this->generateOutlinePattern($nodes), t('Node ' . $number . ' outline confirmed.'));
@@ -93,7 +150,7 @@ class BookTestCase extends DrupalWebTest
 
     // Check previous, up, and next links.
     if ($previous) {
-      $this->assertRaw(l('‹ ' . $previous->title, 'node/' . $previous->nid, array('attributes' => array('class' => 'page-previous', 'title' => t('Go to previous page')))), t('Prevoius page link found.'));
+      $this->assertRaw(l('‹ ' . $previous->title, 'node/' . $previous->nid, array('attributes' => array('class' => 'page-previous', 'title' => t('Go to previous page')))), t('Previous page link found.'));
     }
 
     if ($up) {
@@ -112,7 +169,7 @@ class BookTestCase extends DrupalWebTest
 
     $number++;
   }
-
+  
   /**
    * Create a regular expression to check for the sub-nodes in the outline.
    *
@@ -133,22 +190,23 @@ class BookTestCase extends DrupalWebTest
    * @param integer $book_nid Book node id or set to 'new' to create new book.
    * @param integer $parent Parent book reference id.
    */
-  function createBookNode($book_nid, $parent = NULL) {
+  function createBookNode($book_nid, $parent = NULL, $type = 'book') {
     static $number = 0; // Used to ensure that when sorted nodes stay in same order.
-
+    // Replace the underscores for the correct node/add path.
+    $type = str_replace('_', '-', $type);
     $edit = array();
     $edit['title'] = $number . ' - SimpleTest test node ' . $this->randomName(10);
     $edit['body'] = 'SimpleTest test body ' . $this->randomName(32) . ' ' . $this->randomName(32);
     $edit['book[bid]'] = $book_nid;
 
     if ($parent !== NULL) {
-      $this->drupalPost('node/add/book', $edit, t('Change book (update list of parents)'));
+      $this->drupalPost('node/add/' . $type, $edit, t('Change book (update list of parents)'));
 
       $edit['book[plid]'] = $parent;
       $this->drupalPost(NULL, $edit, t('Save'));
     }
     else {
-      $this->drupalPost('node/add/book', $edit, t('Save'));
+      $this->drupalPost('node/add/'. $type, $edit, t('Save'));
     }
 
     // Check to make sure the book node was created.
@@ -158,4 +216,29 @@ class BookTestCase extends DrupalWebTest
 
     return $node;
   }
+
+  /**
+   * Update a book node.
+   *
+   * @param integer $book_nid Book node id.
+   * @param integer $nid Book page nid.
+   * @param integer $parent Parent book reference id.
+   */
+  function updateBookNode($book_nid, $nid, $parent = NULL) {
+    // Set update parameters.
+    $edit = array();
+    $edit['book[bid]'] = $book_nid;
+
+    if ($parent !== NULL) {
+      $edit['book[plid]'] = $parent;
+    }
+
+    $this->drupalPost('node/' . $nid . '/edit', $edit, t('Save'));
+
+    // Check to make sure the book node was updated.
+    $node = node_load($nid);
+    $this->assertNotNull(($node === FALSE ? NULL : $node), t('Book node found in database.'));
+
+    return $node;
+  }
 }
