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