Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 310 and 311] [Versions 39 and 311]

   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_lti;
  18  
  19  defined('MOODLE_INTERNAL') || die();
  20  
  21  global $CFG;
  22  
  23  require_once($CFG->dirroot.'/mod/lti/servicelib.php');
  24  
  25  /**
  26   * Tests for servicelib.php
  27   *
  28   * @package   mod_lti
  29   * @copyright Copyright (c) 2015 Moodlerooms Inc. (http://www.moodlerooms.com)
  30   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  31   */
  32  class servicelib_test extends \basic_testcase {
  33      /**
  34       * Test that lti_parse_message_id never fails with good and bad XML.
  35       *
  36       * @dataProvider message_id_provider
  37       * @param mixed $expected Expected message ID.
  38       * @param string $xml XML to parse.
  39       */
  40      public function test_lti_parse_message_id($expected, $xml) {
  41          $xml = simplexml_load_string($xml);
  42          $this->assertEquals($expected, lti_parse_message_id($xml));
  43      }
  44  
  45      /**
  46       * Test data provider for testing lti_parse_message_id
  47       *
  48       * @return array
  49       */
  50      public function message_id_provider() {
  51          $valid = <<<XML
  52  <?xml version="1.0" encoding="UTF-8"?>
  53  <imsx_POXEnvelopeRequest xmlns="http://www.imsglobal.org/services/ltiv1p1/xsd/imsoms_v1p0">
  54      <imsx_POXHeader>
  55          <imsx_POXRequestHeaderInfo>
  56              <imsx_version>V1.0</imsx_version>
  57              <imsx_messageIdentifier>9999</imsx_messageIdentifier>
  58          </imsx_POXRequestHeaderInfo>
  59      </imsx_POXHeader>
  60      <imsx_POXBody/>
  61  </imsx_POXEnvelopeRequest>
  62  XML;
  63  
  64          $noheader = <<<XML
  65  <?xml version="1.0" encoding="UTF-8"?>
  66  <imsx_POXEnvelopeRequest xmlns="http://www.imsglobal.org/services/ltiv1p1/xsd/imsoms_v1p0">
  67      <badXmlHere>
  68          <imsx_POXRequestHeaderInfo>
  69              <imsx_version>V1.0</imsx_version>
  70              <imsx_messageIdentifier>9999</imsx_messageIdentifier>
  71          </imsx_POXRequestHeaderInfo>
  72      </badXmlHere>
  73      <imsx_POXBody/>
  74  </imsx_POXEnvelopeRequest>
  75  XML;
  76  
  77          $noinfo = <<<XML
  78  <?xml version="1.0" encoding="UTF-8"?>
  79  <imsx_POXEnvelopeRequest xmlns="http://www.imsglobal.org/services/ltiv1p1/xsd/imsoms_v1p0">
  80      <imsx_POXHeader>
  81          <badXmlHere>
  82              <imsx_version>V1.0</imsx_version>
  83              <imsx_messageIdentifier>9999</imsx_messageIdentifier>
  84          </badXmlHere>
  85      </imsx_POXHeader>
  86      <imsx_POXBody/>
  87  </imsx_POXEnvelopeRequest>
  88  XML;
  89  
  90          $noidentifier = <<<XML
  91  <?xml version="1.0" encoding="UTF-8"?>
  92  <imsx_POXEnvelopeRequest xmlns="http://www.imsglobal.org/services/ltiv1p1/xsd/imsoms_v1p0">
  93      <imsx_POXHeader>
  94          <imsx_POXRequestHeaderInfo>
  95              <imsx_version>V1.0</imsx_version>
  96          </imsx_POXRequestHeaderInfo>
  97      </imsx_POXHeader>
  98      <imsx_POXBody/>
  99  </imsx_POXEnvelopeRequest>
 100  XML;
 101  
 102          return array(
 103              array(9999, $valid),
 104              array('', $noheader),
 105              array('', $noinfo),
 106              array('', $noidentifier),
 107          );
 108      }
 109  }