Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.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 factor_cohort;
  18  
  19  /**
  20   * Tests for cohort factor.
  21   *
  22   * @covers      \factor_cohort\factor
  23   * @package     factor_cohort
  24   * @copyright   2023 Stevani Andolo <stevani@hotmail.com.au>
  25   * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  26   */
  27  class factor_test extends \advanced_testcase {
  28  
  29      /**
  30       * Tests getting the summary condition
  31       *
  32       * @covers ::get_summary_condition
  33       * @covers ::get_cohorts
  34       */
  35      public function test_get_summary_condition() {
  36          $this->resetAfterTest();
  37  
  38          set_config('enabled', 1, 'factor_cohort');
  39          $cohortfactor = \tool_mfa\plugininfo\factor::get_factor('cohort');
  40  
  41          $cohort = $this->getDataGenerator()->create_cohort();
  42          $userassignover = $this->getDataGenerator()->create_user();
  43          cohort_add_member($cohort->id, $userassignover->id);
  44  
  45          // Add the created cohortid into factor_cohort plugin.
  46          set_config('cohorts', $cohort->id, 'factor_cohort');
  47  
  48          $selectedcohorts = get_config('factor_cohort', 'cohorts');
  49          $selectedcohorts = $cohortfactor->get_cohorts(explode(',', $selectedcohorts));
  50          $this->assertArrayHasKey($cohort->id, $selectedcohorts);
  51          $this->assertStringContainsString(
  52              implode(', ', $selectedcohorts),
  53              $cohortfactor->get_summary_condition()
  54          );
  55      }
  56  }