Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * This file contains tests for the question_attempt_step class. 19 * 20 * @package moodlecore 21 * @subpackage questionengine 22 * @copyright 2009 The Open University 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 27 defined('MOODLE_INTERNAL') || die(); 28 29 global $CFG; 30 require_once (__DIR__ . '/../lib.php'); 31 require_once (__DIR__ . '/helpers.php'); 32 33 34 /** 35 * Unit tests for the loading data into the {@link question_attempt_step} class. 36 * 37 * @copyright 2009 The Open University 38 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 39 */ 40 class question_attempt_step_db_test extends data_loading_method_test_base { 41 public function test_load_with_data() { 42 $records = new question_test_recordset(array( 43 array('attemptstepid', 'questionattemptid', 'sequencenumber', 'state', 'fraction', 'timecreated', 'userid', 'name', 'value', 'qtype', 'contextid'), 44 array( 1, 1, 0, 'todo', null, 1256228502, 13, null, null, 'description', 1), 45 array( 2, 1, 1, 'complete', null, 1256228505, 13, 'x', 'a', 'description', 1), 46 array( 2, 1, 1, 'complete', null, 1256228505, 13, '_y', '_b', 'description', 1), 47 array( 2, 1, 1, 'complete', null, 1256228505, 13, '-z', '!c', 'description', 1), 48 array( 2, 1, 1, 'complete', null, 1256228505, 13, '-_t', '!_d', 'description', 1), 49 array( 3, 1, 2, 'gradedright', 1.0, 1256228515, 13, '-finish', '1', 'description', 1), 50 )); 51 52 $step = question_attempt_step::load_from_records($records, 2); 53 $this->assertEquals(question_state::$complete, $step->get_state()); 54 $this->assertNull($step->get_fraction()); 55 $this->assertEquals(1256228505, $step->get_timecreated()); 56 $this->assertEquals(13, $step->get_user_id()); 57 $this->assertEquals(array('x' => 'a', '_y' => '_b', '-z' => '!c', '-_t' => '!_d'), $step->get_all_data()); 58 } 59 60 public function test_load_without_data() { 61 $records = new question_test_recordset(array( 62 array('attemptstepid', 'questionattemptid', 'sequencenumber', 'state', 'fraction', 'timecreated', 'userid', 'name', 'value', 'contextid'), 63 array( 2, 1, 1, 'complete', null, 1256228505, 13, null, null, 1), 64 )); 65 66 $step = question_attempt_step::load_from_records($records, 2, 'description'); 67 $this->assertEquals(question_state::$complete, $step->get_state()); 68 $this->assertNull($step->get_fraction()); 69 $this->assertEquals(1256228505, $step->get_timecreated()); 70 $this->assertEquals(13, $step->get_user_id()); 71 $this->assertEquals(array(), $step->get_all_data()); 72 } 73 74 public function test_load_dont_be_too_greedy() { 75 $records = new question_test_recordset(array( 76 array('attemptstepid', 'questionattemptid', 'sequencenumber', 'state', 'fraction', 'timecreated', 'userid', 'name', 'value', 'contextid'), 77 array( 1, 1, 0, 'todo', null, 1256228502, 13, 'x', 'right', 1), 78 array( 2, 2, 0, 'complete', null, 1256228505, 13, 'x', 'wrong', 1), 79 )); 80 81 $step = question_attempt_step::load_from_records($records, 1, 'description'); 82 $this->assertEquals(array('x' => 'right'), $step->get_all_data()); 83 } 84 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body