See Release Notes
Long Term Support Release
Differences Between: [Versions 310 and 401] [Versions 39 and 401]
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 namespace core_question; 18 19 use question_attempt_step; 20 use question_state; 21 use question_test_recordset; 22 23 defined('MOODLE_INTERNAL') || die(); 24 25 global $CFG; 26 require_once (__DIR__ . '/../lib.php'); 27 require_once (__DIR__ . '/helpers.php'); 28 29 /** 30 * Unit tests for the loading data into the {@link question_attempt_step} class. 31 * 32 * @package core_question 33 * @category test 34 * @copyright 2009 The Open University 35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 36 */ 37 class questionattemptstep_db_test extends \data_loading_method_test_base { 38 public function test_load_with_data() { 39 $records = new question_test_recordset(array( 40 array('attemptstepid', 'questionattemptid', 'sequencenumber', 'state', 'fraction', 'timecreated', 'userid', 'name', 'value', 'qtype', 'contextid'), 41 array( 1, 1, 0, 'todo', null, 1256228502, 13, null, null, 'description', 1), 42 array( 2, 1, 1, 'complete', null, 1256228505, 13, 'x', 'a', 'description', 1), 43 array( 2, 1, 1, 'complete', null, 1256228505, 13, '_y', '_b', 'description', 1), 44 array( 2, 1, 1, 'complete', null, 1256228505, 13, '-z', '!c', 'description', 1), 45 array( 2, 1, 1, 'complete', null, 1256228505, 13, '-_t', '!_d', 'description', 1), 46 array( 3, 1, 2, 'gradedright', 1.0, 1256228515, 13, '-finish', '1', 'description', 1), 47 )); 48 49 $step = question_attempt_step::load_from_records($records, 2); 50 $this->assertEquals(question_state::$complete, $step->get_state()); 51 $this->assertNull($step->get_fraction()); 52 $this->assertEquals(1256228505, $step->get_timecreated()); 53 $this->assertEquals(13, $step->get_user_id()); 54 $this->assertEquals(array('x' => 'a', '_y' => '_b', '-z' => '!c', '-_t' => '!_d'), $step->get_all_data()); 55 } 56 57 public function test_load_without_data() { 58 $records = new question_test_recordset(array( 59 array('attemptstepid', 'questionattemptid', 'sequencenumber', 'state', 'fraction', 'timecreated', 'userid', 'name', 'value', 'contextid'), 60 array( 2, 1, 1, 'complete', null, 1256228505, 13, null, null, 1), 61 )); 62 63 $step = question_attempt_step::load_from_records($records, 2, 'description'); 64 $this->assertEquals(question_state::$complete, $step->get_state()); 65 $this->assertNull($step->get_fraction()); 66 $this->assertEquals(1256228505, $step->get_timecreated()); 67 $this->assertEquals(13, $step->get_user_id()); 68 $this->assertEquals(array(), $step->get_all_data()); 69 } 70 71 public function test_load_dont_be_too_greedy() { 72 $records = new question_test_recordset(array( 73 array('attemptstepid', 'questionattemptid', 'sequencenumber', 'state', 'fraction', 'timecreated', 'userid', 'name', 'value', 'contextid'), 74 array( 1, 1, 0, 'todo', null, 1256228502, 13, 'x', 'right', 1), 75 array( 2, 2, 0, 'complete', null, 1256228505, 13, 'x', 'wrong', 1), 76 )); 77 78 $step = question_attempt_step::load_from_records($records, 1, 'description'); 79 $this->assertEquals(array('x' => 'right'), $step->get_all_data()); 80 } 81 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body