2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * Tests for servicelib.php
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
25 defined('MOODLE_INTERNAL') ||
die();
29 require_once($CFG->dirroot
.'/mod/lti/servicelib.php');
32 * Tests for servicelib.php
35 * @copyright Copyright (c) 2015 Moodlerooms Inc. (http://www.moodlerooms.com)
36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38 class mod_lti_servicelib_testcase
extends basic_testcase
{
40 * Test that lti_parse_message_id never fails with good and bad XML.
42 * @dataProvider message_id_provider
43 * @param mixed $expected Expected message ID.
44 * @param string $xml XML to parse.
46 public function test_lti_parse_message_id($expected, $xml) {
47 $xml = simplexml_load_string($xml);
48 $this->assertEquals($expected, lti_parse_message_id($xml));
52 * Test data provider for testing lti_parse_message_id
56 public function message_id_provider() {
58 <?xml version="1.0" encoding="UTF-8"?>
59 <imsx_POXEnvelopeRequest xmlns="http://www.imsglobal.org/services/ltiv1p1/xsd/imsoms_v1p0">
61 <imsx_POXRequestHeaderInfo>
62 <imsx_version>V1.0</imsx_version>
63 <imsx_messageIdentifier>9999</imsx_messageIdentifier>
64 </imsx_POXRequestHeaderInfo>
67 </imsx_POXEnvelopeRequest>
71 <?xml version="1.0" encoding="UTF-8"?>
72 <imsx_POXEnvelopeRequest xmlns="http://www.imsglobal.org/services/ltiv1p1/xsd/imsoms_v1p0">
74 <imsx_POXRequestHeaderInfo>
75 <imsx_version>V1.0</imsx_version>
76 <imsx_messageIdentifier>9999</imsx_messageIdentifier>
77 </imsx_POXRequestHeaderInfo>
80 </imsx_POXEnvelopeRequest>
84 <?xml version="1.0" encoding="UTF-8"?>
85 <imsx_POXEnvelopeRequest xmlns="http://www.imsglobal.org/services/ltiv1p1/xsd/imsoms_v1p0">
88 <imsx_version>V1.0</imsx_version>
89 <imsx_messageIdentifier>9999</imsx_messageIdentifier>
93 </imsx_POXEnvelopeRequest>
96 $noidentifier = <<<XML
97 <?xml version="1.0" encoding="UTF-8"?>
98 <imsx_POXEnvelopeRequest xmlns="http://www.imsglobal.org/services/ltiv1p1/xsd/imsoms_v1p0">
100 <imsx_POXRequestHeaderInfo>
101 <imsx_version>V1.0</imsx_version>
102 </imsx_POXRequestHeaderInfo>
105 </imsx_POXEnvelopeRequest>
110 array('', $noheader),
112 array('', $noidentifier),