Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.
   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 enrol_lti\local\ltiadvantage\utility;
  18  
  19  /**
  20   * Test cases for the enrol_lti\local\ltiadvantage\utility\message_helper utility class.
  21   *
  22   * @package    enrol_lti
  23   * @copyright  2021 Jake Dallimore <jrhdallimore@gmail.com>
  24   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  25   * @coversDefaultClass \enrol_lti\local\ltiadvantage\utility\message_helper
  26   */
  27  class message_helper_test extends \base_testcase {
  28  
  29      /**
  30       * Test the static helper is_instructor_launch.
  31       *
  32       * @dataProvider message_roles_provider
  33       * @param array $jwtdata the mock JWT data from a launch.
  34       * @param bool $expected the expected return of is_instructor_launch() given the JWT data.
  35       * @covers ::is_instructor_launch
  36       */
  37      public function test_is_instructor_launch(array $jwtdata, bool $expected) {
  38          $this->assertEquals($expected, message_helper::is_instructor_launch($jwtdata));
  39      }
  40  
  41      /**
  42       * Data provider for testing role helpers.
  43       *
  44       * @return array the array of test JWT data.
  45       */
  46      public function message_roles_provider(): array {
  47          return [
  48              'Roles claim present, includes learner role only' => [
  49                  'jwtdata' => [
  50                      'https://purl.imsglobal.org/spec/lti/claim/roles' => [
  51                          'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
  52                      ]
  53                  ],
  54                  'expected' => false
  55              ],
  56              'Roles claim present, includes teacher role only' => [
  57                  'jwtdata' => [
  58                      'https://purl.imsglobal.org/spec/lti/claim/roles' => [
  59                          'http://purl.imsglobal.org/vocab/lis/v2/membership#Instructor'
  60                      ]
  61                  ],
  62                  'expected' => true
  63              ],
  64              'Roles claim present, includes admin role only' => [
  65                  'jwtdata' => [
  66                      'https://purl.imsglobal.org/spec/lti/claim/roles' => [
  67                          'http://purl.imsglobal.org/vocab/lis/v2/institution/person#Administrator'
  68                      ]
  69                  ],
  70                  'expected' => true
  71              ],
  72              'Roles claim present, includes learner and teacher roles' => [
  73                  'jwtdata' => [
  74                      'https://purl.imsglobal.org/spec/lti/claim/roles' => [
  75                          'http://purl.imsglobal.org/vocab/lis/v2/membership#Instructor',
  76                          'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
  77                      ]
  78                  ],
  79                  'expected' => true
  80              ],
  81              'Roles claim present, includes instructor role using legacy short name and learner role' => [
  82                  'jwtdata' => [
  83                      'https://purl.imsglobal.org/spec/lti/claim/roles' => [
  84                          'Instructor',
  85                          'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'
  86                      ]
  87                  ],
  88                  'expected' => true
  89              ],
  90              'Roles claim empty' => [
  91                  'jwtdata' => [
  92                      'https://purl.imsglobal.org/spec/lti/claim/roles' => [],
  93                  ],
  94                  'expected' => false
  95              ],
  96              'Roles claim not present' => [
  97                  'jwtdata' => [],
  98                  'expected' => false
  99              ],
 100          ];
 101      }
 102  }