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 core\output;
  18  use ReflectionMethod;
  19  
  20  /**
  21   * Participants tertiary navigation renderable test
  22   *
  23   * @package     core
  24   * @category    output
  25   * @copyright   2021 onwards Peter Dias
  26   * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  27   */
  28  class participants_action_bar_test extends \advanced_testcase {
  29  
  30      /**
  31       * Test the get_content_for_select function
  32       *
  33       * @dataProvider get_content_for_select_provider
  34       * @param string $type Whether we are checking content in the course/module
  35       * @param int    $expectedcount Expected number of 1st level tertiary items
  36       * @param array  $expecteditems Expected keys of the 1st level tertiary items.
  37       */
  38      public function test_get_content_for_select($type, $expectedcount, $expecteditems) {
  39          global $PAGE;
  40          $this->resetAfterTest();
  41          $course = $this->getDataGenerator()->create_course();
  42          $module = $this->getDataGenerator()->create_module('assign', [
  43              'course' => $course->id
  44          ]);
  45          if ($type == 'course') {
  46              $context = \context_course::instance($course->id);
  47              $url = new \moodle_url('/course/view.php', ['id' => $course->id]);
  48          } else {
  49              $url = new \moodle_url('/mod/assign/view.php', ['id' => $module->id]);
  50              $context = \context_module::instance($module->cmid);
  51              $cm = get_coursemodule_from_instance('assign', $module->id, $course->id);
  52              $PAGE->set_cm($cm);
  53          }
  54  
  55          $this->setAdminUser();
  56          $PAGE->set_url($url);
  57          $PAGE->set_context($context);
  58          $output = new participants_action_bar($course, $PAGE, null);
  59          $method = new ReflectionMethod('\core\output\participants_action_bar', 'get_content_for_select');
  60          $method->setAccessible(true);
  61          $renderer = $PAGE->get_renderer('core');
  62  
  63          $response = $method->invoke($output, $renderer);
  64          $this->assertCount($expectedcount, $response);
  65          $this->assertSame($expecteditems, array_keys(array_merge(...$response)));
  66      }
  67  
  68      /**
  69       * Provider for test_get_content_for_select
  70       * @return array[]
  71       */
  72      public function get_content_for_select_provider() {
  73          return [
  74              'Get dropdown content when in a course context' => [
  75                  'course', 3, ['Enrolments', 'Groups', 'Permissions']
  76              ],
  77              'Get dropdown content when in a module context' => [
  78                  'module', 1, ['Permissions']
  79              ]
  80          ];
  81      }
  82  }