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 39 and 310]

   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   * Tool analytics external functions tests.
  19   *
  20   * @package    tool_analytics
  21   * @category   external
  22   * @copyright  2019 David MonllaĆ³ {@link http://www.davidmonllao.com}
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   * @since      Moodle 3.8
  25   */
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  global $CFG;
  30  
  31  require_once($CFG->dirroot . '/webservice/tests/helpers.php');
  32  require_once (__DIR__ . '/../../../../analytics/tests/fixtures/test_indicator_max.php');
  33  require_once (__DIR__ . '/../../../../analytics/tests/fixtures/test_target_course_level_shortname.php');
  34  
  35  /**
  36   * Tool analytics external functions tests
  37   *
  38   * @package    tool_analytics
  39   * @category   external
  40   * @copyright  2019 David MonllaĆ³ {@link http://www.davidmonllao.com}
  41   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  42   * @since      Moodle 3.8
  43   */
  44  class tool_analytics_external_testcase extends externallib_advanced_testcase {
  45  
  46      /**
  47       * test_potential_contexts description
  48       */
  49      public function test_potential_contexts() {
  50          $this->resetAfterTest();
  51  
  52          $this->setAdminUser();
  53  
  54          // Include the all context levels so the misc. category get included.
  55          $this->assertCount(1, \tool_analytics\external::potential_contexts());
  56  
  57          // The frontpage is not included.
  58          $this->assertCount(0, \tool_analytics\external::potential_contexts('PHPUnit'));
  59  
  60          $target = \core_analytics\manager::get_target('test_target_course_level_shortname');
  61          $indicators = ['test_indicator_max' => \core_analytics\manager::get_indicator('test_indicator_max')];
  62          $model = \core_analytics\model::create($target, $indicators);
  63  
  64          $this->assertCount(1, \tool_analytics\external::potential_contexts(null, $model->get_id()));
  65      }
  66  
  67      /**
  68       * test_potential_contexts description
  69       */
  70      public function test_potential_contexts_no_manager() {
  71          $this->resetAfterTest();
  72  
  73          $user = $this->getDataGenerator()->create_user();
  74          $this->setUser($user);
  75  
  76          $this->expectException(required_capability_exception::class);
  77          $this->assertCount(2, \tool_analytics\external::potential_contexts());
  78      }
  79  }