Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 39 and 311] [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 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 for servicelib.php
  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  defined('MOODLE_INTERNAL') || die();
  26  
  27  global $CFG;
  28  
  29  require_once($CFG->dirroot.'/mod/lti/servicelib.php');
  30  
  31  /**
  32   * Tests for servicelib.php
  33   *
  34   * @package   mod_lti
  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
  37   */
  38  class mod_lti_servicelib_testcase extends basic_testcase {
  39      /**
  40       * Test that lti_parse_message_id never fails with good and bad XML.
  41       *
  42       * @dataProvider message_id_provider
  43       * @param mixed $expected Expected message ID.
  44       * @param string $xml XML to parse.
  45       */
  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));
  49      }
  50  
  51      /**
  52       * Test data provider for testing lti_parse_message_id
  53       *
  54       * @return array
  55       */
  56      public function message_id_provider() {
  57          $valid = <<<XML
  58  <?xml version="1.0" encoding="UTF-8"?>
  59  <imsx_POXEnvelopeRequest xmlns="http://www.imsglobal.org/services/ltiv1p1/xsd/imsoms_v1p0">
  60      <imsx_POXHeader>
  61          <imsx_POXRequestHeaderInfo>
  62              <imsx_version>V1.0</imsx_version>
  63              <imsx_messageIdentifier>9999</imsx_messageIdentifier>
  64          </imsx_POXRequestHeaderInfo>
  65      </imsx_POXHeader>
  66      <imsx_POXBody/>
  67  </imsx_POXEnvelopeRequest>
  68  XML;
  69  
  70          $noheader = <<<XML
  71  <?xml version="1.0" encoding="UTF-8"?>
  72  <imsx_POXEnvelopeRequest xmlns="http://www.imsglobal.org/services/ltiv1p1/xsd/imsoms_v1p0">
  73      <badXmlHere>
  74          <imsx_POXRequestHeaderInfo>
  75              <imsx_version>V1.0</imsx_version>
  76              <imsx_messageIdentifier>9999</imsx_messageIdentifier>
  77          </imsx_POXRequestHeaderInfo>
  78      </badXmlHere>
  79      <imsx_POXBody/>
  80  </imsx_POXEnvelopeRequest>
  81  XML;
  82  
  83          $noinfo = <<<XML
  84  <?xml version="1.0" encoding="UTF-8"?>
  85  <imsx_POXEnvelopeRequest xmlns="http://www.imsglobal.org/services/ltiv1p1/xsd/imsoms_v1p0">
  86      <imsx_POXHeader>
  87          <badXmlHere>
  88              <imsx_version>V1.0</imsx_version>
  89              <imsx_messageIdentifier>9999</imsx_messageIdentifier>
  90          </badXmlHere>
  91      </imsx_POXHeader>
  92      <imsx_POXBody/>
  93  </imsx_POXEnvelopeRequest>
  94  XML;
  95  
  96          $noidentifier = <<<XML
  97  <?xml version="1.0" encoding="UTF-8"?>
  98  <imsx_POXEnvelopeRequest xmlns="http://www.imsglobal.org/services/ltiv1p1/xsd/imsoms_v1p0">
  99      <imsx_POXHeader>
 100          <imsx_POXRequestHeaderInfo>
 101              <imsx_version>V1.0</imsx_version>
 102          </imsx_POXRequestHeaderInfo>
 103      </imsx_POXHeader>
 104      <imsx_POXBody/>
 105  </imsx_POXEnvelopeRequest>
 106  XML;
 107  
 108          return array(
 109              array(9999, $valid),
 110              array('', $noheader),
 111              array('', $noinfo),
 112              array('', $noidentifier),
 113          );
 114      }
 115  }