Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 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 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   * This file contains unit test related to xAPI library.
  19   *
  20   * @package    core_xapi
  21   * @copyright  2020 Ferran Recio
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace core_xapi\local\statement;
  26  
  27  use advanced_testcase;
  28  use core_xapi\xapi_exception;
  29  use core_xapi\iri;
  30  
  31  defined('MOODLE_INTERNAL') || die();
  32  
  33  /**
  34   * Contains test cases for testing statement definition class.
  35   *
  36   * @package    core_xapi
  37   * @since      Moodle 3.9
  38   * @copyright  2020 Ferran Recio
  39   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  40   */
  41  class item_definition_testcase extends advanced_testcase {
  42  
  43      /**
  44       * Test item_definition creation.
  45       *
  46       * @dataProvider creation_provider
  47       * @param string  $interactiontype
  48       */
  49      public function test_creation(string  $interactiontype): void {
  50  
  51          // Activity without interactionType.
  52          $data = (object) [
  53              'type' => iri::generate('example', 'id'),
  54          ];
  55  
  56          // Add interactionType.
  57          if (!empty($interactiontype)) {
  58              $data->interactionType = $interactiontype;
  59          }
  60          $item = item_definition::create_from_data($data);
  61  
  62          $this->assertEquals(json_encode($item), json_encode($data));
  63          if (empty($interactiontype)) {
  64              $this->assertNull($item->get_interactiontype());
  65          } else {
  66              $this->assertEquals($interactiontype, $item->get_interactiontype());
  67          }
  68      }
  69  
  70      /**
  71       * Data provider for the test_creation tests.
  72       *
  73       * @return  array
  74       */
  75      public function creation_provider() : array {
  76          return [
  77              'No interactionType' => [''],
  78              'Choice' => ['choice'],
  79              'fill-in' => ['fill-in'],
  80              'long-fill-in' => ['long-fill-in'],
  81              'true-false' => ['true-false'],
  82              'matching' => ['matching'],
  83              'performance' => ['performance'],
  84              'sequencing' => ['sequencing'],
  85              'likert' => ['likert'],
  86              'numeric' => ['numeric'],
  87              'other' => ['other'],
  88              'compound' => ['compound'],
  89          ];
  90      }
  91  
  92      /**
  93       * Test for invalid structures.
  94       */
  95      public function test_invalid_data(): void {
  96          // Activity without interactionType.
  97          $data = (object) [
  98              'interactionType' => 'Invalid value!',
  99          ];
 100  
 101          $this->expectException(xapi_exception::class);
 102          $item = item_definition::create_from_data($data);
 103      }
 104  }