libdir . '/questionlib.php'); class questionlib_test extends UnitTestCase { public static $includecoverage = array('lib/questionlib.php'); function test_question_reorder_qtypes() { $this->assertEqual(question_reorder_qtypes(array('t1' => '', 't2' => '', 't3' => ''), 't1', +1), array(0 => 't2', 1 => 't1', 2 => 't3')); $this->assertEqual(question_reorder_qtypes(array('t1' => '', 't2' => '', 't3' => ''), 't1', -1), array(0 => 't1', 1 => 't2', 2 => 't3')); $this->assertEqual(question_reorder_qtypes(array('t1' => '', 't2' => '', 't3' => ''), 't2', -1), array(0 => 't2', 1 => 't1', 2 => 't3')); $this->assertEqual(question_reorder_qtypes(array('t1' => '', 't2' => '', 't3' => ''), 't3', +1), array(0 => 't1', 1 => 't2', 2 => 't3')); $this->assertEqual(question_reorder_qtypes(array('t1' => '', 't2' => '', 't3' => ''), 'missing', +1), array(0 => 't1', 1 => 't2', 2 => 't3')); } function test_question_state_is_closed() { $state = new stdClass(); $state->event = QUESTION_EVENTOPEN; $this->assertFalse(question_state_is_closed($state)); $state->event = QUESTION_EVENTNAVIGATE; $this->assertFalse(question_state_is_closed($state)); $state->event = QUESTION_EVENTSAVE; $this->assertFalse(question_state_is_closed($state)); $state->event = QUESTION_EVENTGRADE; $this->assertFalse(question_state_is_closed($state)); $state->event = QUESTION_EVENTDUPLICATE; $this->assertFalse(question_state_is_closed($state)); $state->event = QUESTION_EVENTVALIDATE; $this->assertFalse(question_state_is_closed($state)); $state->event = QUESTION_EVENTSUBMIT; $this->assertFalse(question_state_is_closed($state)); $state->event = QUESTION_EVENTCLOSEANDGRADE; $this->assertTrue(question_state_is_closed($state)); $state->event = QUESTION_EVENTCLOSE; $this->assertTrue(question_state_is_closed($state)); $state->event = QUESTION_EVENTMANUALGRADE; $this->assertTrue(question_state_is_closed($state)); } function test_question_state_is_graded() { $state = new stdClass(); $state->event = QUESTION_EVENTOPEN; $this->assertFalse(question_state_is_graded($state)); $state->event = QUESTION_EVENTNAVIGATE; $this->assertFalse(question_state_is_graded($state)); $state->event = QUESTION_EVENTSAVE; $this->assertFalse(question_state_is_graded($state)); $state->event = QUESTION_EVENTDUPLICATE; $this->assertFalse(question_state_is_graded($state)); $state->event = QUESTION_EVENTVALIDATE; $this->assertFalse(question_state_is_graded($state)); $state->event = QUESTION_EVENTSUBMIT; $this->assertFalse(question_state_is_graded($state)); $state->event = QUESTION_EVENTCLOSE; $this->assertFalse(question_state_is_graded($state)); $state->event = QUESTION_EVENTCLOSEANDGRADE; $this->assertTrue(question_state_is_graded($state)); $state->event = QUESTION_EVENTMANUALGRADE; $this->assertTrue(question_state_is_graded($state)); $state->event = QUESTION_EVENTGRADE; $this->assertTrue(question_state_is_graded($state)); } }