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 * Tests Exception handler for LTI services 19 * 20 * @package mod_lti 21 * @copyright Copyright (c) 2015 Moodlerooms Inc. (http://www.moodlerooms.com) 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 use mod_lti\service_exception_handler; 26 27 defined('MOODLE_INTERNAL') || die(); 28 29 /** 30 * Tests Exception handler for LTI services 31 * 32 * @package mod_lti 33 * @copyright Copyright (c) 2015 Moodlerooms Inc. (http://www.moodlerooms.com) 34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 35 */ 36 class mod_lti_service_exception_handler_testcase extends advanced_testcase { 37 /** 38 * Testing service error handling. 39 */ 40 public function test_handle() { 41 $handler = new service_exception_handler(false); 42 $handler->set_message_id('123'); 43 $handler->set_message_type('testRequest'); 44 $handler->handle(new Exception('Error happened')); 45 46 $this->expectOutputRegex('/imsx_codeMajor>failure/'); 47 $this->expectOutputRegex('/imsx_description>Error happened/'); 48 $this->expectOutputRegex('/imsx_messageRefIdentifier>123/'); 49 $this->expectOutputRegex('/imsx_operationRefIdentifier>testRequest/'); 50 $this->expectOutputRegex('/imsx_POXBody><testResponse/'); 51 } 52 53 /** 54 * Testing service error handling when message ID and type are not known yet. 55 */ 56 public function test_handle_early_error() { 57 $handler = new service_exception_handler(false); 58 $handler->handle(new Exception('Error happened')); 59 60 $this->expectOutputRegex('/imsx_codeMajor>failure/'); 61 $this->expectOutputRegex('/imsx_description>Error happened/'); 62 $this->expectOutputRegex('/imsx_messageRefIdentifier\/>/'); 63 $this->expectOutputRegex('/imsx_operationRefIdentifier>unknownRequest/'); 64 $this->expectOutputRegex('/imsx_POXBody><unknownResponse/'); 65 } 66 67 /** 68 * Testing that a log file is generated when logging is turned on. 69 */ 70 public function test_handle_log() { 71 global $CFG; 72 73 $this->resetAfterTest(); 74 75 $handler = new service_exception_handler(true); 76 77 ob_start(); 78 $handler->handle(new Exception('Error happened')); 79 ob_end_clean(); 80 81 $this->assertTrue(is_dir($CFG->dataroot.'/temp/mod_lti')); 82 $files = glob($CFG->dataroot.'/temp/mod_lti/mod*'); 83 $this->assertEquals(1, count($files)); 84 } 85 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body