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 mod_bigbluebuttonbn\local\helpers;
  18  
  19  use context_course;
  20  use mod_bigbluebuttonbn\test\testcase_helper_trait;
  21  
  22  /**
  23   * BBB Library tests class.
  24   *
  25   * @package   mod_bigbluebuttonbn
  26   * @copyright 2018 - present, Blindside Networks Inc
  27   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  28   * @author    Laurent David (laurent@call-learning.fr)
  29   * @covers \mod_bigbluebuttonbn\local\helpers\roles
  30   * @coversDefaultClass \mod_bigbluebuttonbn\local\helpers\roles
  31   */
  32  class roles_test extends \advanced_testcase {
  33      use testcase_helper_trait;
  34  
  35      /**
  36       * Test select separate group prevent all
  37       *
  38       */
  39      public function test_get_users_select_separate_groups_prevent_all() {
  40          $this->resetAfterTest();
  41          $numstudents = 12;
  42          $numteachers = 3;
  43          $groupsnum = 3;
  44          list($course, $groups, $students, $teachers, $bbactivity, $roleids) =
  45              $this->setup_course_students_teachers(
  46                  (object) ['enablecompletion' => true, 'groupmode' => strval(SEPARATEGROUPS), 'groupmodeforce' => 1],
  47                  $numstudents, $numteachers, $groupsnum);
  48          $context = context_course::instance($course->id);
  49          // Prevent access all groups.
  50          role_change_permission($roleids['teacher'], $context, 'moodle/site:accessallgroups', CAP_PREVENT);
  51          $this->setUser($teachers[0]);
  52          $users = roles::get_users_array($context, $bbactivity);
  53          $this->assertCount(($numstudents + $numteachers) / $groupsnum, $users);
  54          $this->setUser($teachers[1]);
  55          $users = roles::get_users_array($context, $bbactivity);
  56          $this->assertCount(($numstudents + $numteachers) / $groupsnum, $users);
  57          $this->setUser($teachers[2]);
  58          $users = roles::get_users_array($context, $bbactivity);
  59          $this->assertCount(($numstudents + $numteachers) / $groupsnum, $users);
  60          $course->groupmode = strval(SEPARATEGROUPS);
  61          $course->groupmodeforce = "0";
  62          update_course($course);
  63          $this->setUser($teachers[2]);
  64          $users = roles::get_users_array($context, $bbactivity);
  65          $this->assertCount($numstudents + $numteachers, $users);
  66  
  67      }
  68  
  69      /**
  70       * Test select separate groups
  71       *
  72       */
  73      public function test_get_users_select_separate_groups() {
  74          $this->resetAfterTest();
  75          $numstudents = 12;
  76          $numteachers = 3;
  77          $groupsnum = 3;
  78          list($course, $groups, $students, $teachers, $bbactivity, $roleids) =
  79              $this->setup_course_students_teachers(
  80                  (object) ['enablecompletion' => true, 'groupmode' => strval(VISIBLEGROUPS), 'groupmodeforce' => 1],
  81                  $numstudents, $numteachers, $groupsnum);
  82  
  83          $context = context_course::instance($course->id);
  84          $this->setUser($teachers[0]);
  85          $users = roles::get_users_array($context, $bbactivity);
  86          $this->assertCount($numstudents + $numteachers, $users);
  87          $this->setUser($teachers[1]);
  88          $users = roles::get_users_array($context, $bbactivity);
  89          $this->assertCount($numstudents + $numteachers, $users);
  90          $this->setUser($teachers[1]);
  91          $users = roles::get_users_array($context, $bbactivity);
  92          $this->assertCount($numstudents + $numteachers, $users);
  93      }
  94  }