You are here

function CourseObjectBookTestCase::testBookCourseObject in Course 6

Same name and namespace in other branches
  1. 7.2 modules/course_book/course_book.test \CourseObjectBookTestCase::testBookCourseObject()
  2. 7 modules/course_book/course_book.test \CourseObjectBookTestCase::testBookCourseObject()

File

modules/course_book/course_book.test, line 32

Class

CourseObjectBookTestCase
Tests for Book support in Course

Code

function testBookCourseObject() {
  $this
    ->drupalLogin($this->book_admin);

  // Create a course with 1 book.
  $courseNode = $this
    ->createCourseNode();
  $co1 = course_get_course_object('course_book', 'book');
  $co1
    ->setOption('book_tracking', 'all');
  $co1
    ->setCourse($courseNode->nid);
  $co1
    ->setUser($this->book_admin);
  $co1
    ->save();
  $this
    ->assertTrue($co1
    ->getInstanceId() > 0, 'book node created on course object save.');
  $bookNode = node_load($co1
    ->getInstanceId());
  $this
    ->assertTrue($bookNode->type == 'book', 'book node is a book.');

  // Add some more book pages.
  $bp1 = $this
    ->drupalCreateNode(array(
    'type' => 'book',
    'book' => array(
      'bid' => $co1
        ->getInstanceId(),
    ),
  ));
  $bp2 = $this
    ->drupalCreateNode(array(
    'type' => 'book',
    'book' => array(
      'bid' => $co1
        ->getInstanceId(),
    ),
  ));

  // Test fulfillment tracking, set to view all pages before complete.
  $this
    ->assertFalse($co1
    ->getFulfillment()
    ->isComplete(), 'Check that book object is not complete.');

  // Visit the book parent
  $this
    ->drupalGet("node/" . $co1
    ->getInstanceId());

  // Visit the first book page
  $this
    ->drupalGet("node/{$bp1->nid}");

  // Test that course object is not yet complete.
  $co1 = course_get_course_object_by_id($co1
    ->getId(), $this->book_admin);
  $this
    ->assertFalse($co1
    ->getFulfillment()
    ->isComplete(), 'Check that book object is not complete after visiting 2/3 pages.');
  $this
    ->drupalGet("node/{$bp2->nid}");

  // Reload course object
  $co1 = course_get_course_object_by_id($co1
    ->getId(), $this->book_admin);
  $this
    ->assertTrue($co1
    ->getFulfillment()
    ->isComplete(), 'Check that book object is now complete after visiting 3/3 pages.');
}