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 * Unit tests for page types classes 19 * 20 * @package mod_lesson 21 * @category test 22 * @copyright 2015 Jean-Michel Vedrine 23 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License 24 */ 25 26 27 defined('MOODLE_INTERNAL') || die(); 28 29 global $CFG; 30 require_once($CFG->dirroot . '/mod/lesson/locallib.php'); 31 require_once($CFG->dirroot . '/mod/lesson/pagetypes/essay.php'); 32 33 34 /** 35 * This class contains the test cases for some of the functions in the lesson essay page type class. 36 * 37 * @copyright 2015 Jean-Michel Vedrine 38 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License 39 */ 40 class mod_lesson_essay_page_type_test extends advanced_testcase { 41 public function test_lesson_essay_extract_useranswer() { 42 // Test that reponseformat is added when not present. 43 $answer = 'O:8:"stdClass":6:{s:4:"sent";i:1;s:6:"graded";i:1;s:5:"score";s:1:"1";' 44 . 's:6:"answer";s:64:"<p>This is my answer <b>with bold</b> and <i>italics</i><br></p>";' 45 . 's:12:"answerformat";s:1:"1";s:8:"response";s:10:"Well done!";}'; 46 $userresponse = new stdClass; 47 $userresponse->sent = 1; 48 $userresponse->graded = 1; 49 $userresponse->score = 1; 50 $userresponse->answer = "<p>This is my answer <b>with bold</b> and <i>italics</i><br></p>"; 51 $userresponse->answerformat = FORMAT_HTML; 52 $userresponse->response = "Well done!"; 53 $userresponse->responseformat = FORMAT_HTML; 54 $this->assertEquals($userresponse, lesson_page_type_essay::extract_useranswer($answer)); 55 56 // Test that reponseformat is not modified when present. 57 $answer = 'O:8:"stdClass":7:{s:4:"sent";i:0;s:6:"graded";i:1;s:5:"score";s:1:"0";' 58 . 's:6:"answer";s:64:"<p>This is my answer <b>with bold</b> and <i>italics</i><br></p>";' 59 . 's:12:"answerformat";s:1:"1";s:8:"response";s:10:"Well done!";s:14:"responseformat";s:1:"2";}'; 60 $userresponse = new stdClass; 61 $userresponse->sent = 0; 62 $userresponse->graded = 1; 63 $userresponse->score = 0; 64 $userresponse->answer = "<p>This is my answer <b>with bold</b> and <i>italics</i><br></p>"; 65 $userresponse->answerformat = FORMAT_HTML; 66 $userresponse->response = "Well done!"; 67 $userresponse->responseformat = FORMAT_PLAIN; 68 $this->assertEquals($userresponse, lesson_page_type_essay::extract_useranswer($answer)); 69 } 70 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body