You are here

function CourseObjectQuizTestCase::testQuizCourseObject in Course 6

Same name and namespace in other branches
  1. 7.2 modules/course_quiz/course_quiz.test \CourseObjectQuizTestCase::testQuizCourseObject()
  2. 7 modules/course_quiz/course_quiz.test \CourseObjectQuizTestCase::testQuizCourseObject()

File

modules/course_quiz/course_quiz.test, line 34

Class

CourseObjectQuizTestCase
Tests for quiz Course objects.

Code

function testQuizCourseObject() {
  $this
    ->drupalLogin($this->quiz_admin);

  // Create a course with 1 quiz.
  $courseNode = $this
    ->createCourseNode();
  $co1 = course_get_course_object('course_quiz', 'quiz');
  $co1
    ->setCourse($courseNode->nid);
  $co1
    ->setOption('passing_grade', 100);
  $co1
    ->save();
  $this
    ->assertTrue($co1
    ->getInstanceId() > 0, 'Quiz node created on course object save.');
  $quizNode = node_load($co1
    ->getInstanceId());
  $this
    ->assertTrue($quizNode->type == 'quiz', 'Quiz node is a quiz.');

  // Add a question.
  $this
    ->drupalGet('node/add/truefalse', array(
    'query' => 'quiz_nid=2&quiz_vid=2',
  ));
  $this
    ->drupalPost(NULL, array(
    'body' => 'Test question',
    'correct_answer' => 1,
  ), 'Save');

  // Fail the quiz.
  $this
    ->drupalGet("node/{$quizNode->nid}/take");
  $this
    ->assertFalse($co1
    ->getFulfillment()
    ->isComplete(), 'Check that quiz fulfillment is not complete after fail.');
  $this
    ->drupalPost(NULL, array(
    'tries' => 0,
  ), 'Finish');

  // Reload because something happened in the DB.
  $co1 = course_get_course_object_by_id($co1
    ->getId(), $this->quiz_admin);
  $this
    ->assertFalse($co1
    ->getFulfillment()
    ->isComplete(), 'Check that quiz fulfillment is not complete.');

  // Pass the quiz.
  $this
    ->drupalGet("node/{$quizNode->nid}/take");
  $this
    ->drupalPost(NULL, array(
    'tries' => 1,
  ), 'Finish');

  // Reload because something happened in the DB.
  $co1 = course_get_course_object_by_id($co1
    ->getId(), $this->quiz_admin);
  $this
    ->assertTrue($co1
    ->getFulfillment()
    ->isComplete(), 'Check that quiz fulfillment is complete.');
}