Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 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   * Unit tests for mod_forum\grades\gradeitems.
  19   *
  20   * @package   mod_forum
  21   * @category  test
  22   * @copyright 2019 Andrew Nicols <andrew@nicols.co.uk>
  23   * @license   http://www.gnu.org/copyleft/gpl.html GNU Public License
  24   */
  25  
  26  declare(strict_types = 1);
  27  
  28  namespace tests\mod_forum\grades;
  29  
  30  use advanced_testcase;
  31  use core_grades\component_gradeitems;
  32  use coding_exception;
  33  
  34  /**
  35   * Unit tests for mod_forum\grades\gradeitems.
  36   *
  37   * @package   mod_forum
  38   * @category  test
  39   * @copyright 2019 Andrew Nicols <andrew@nicols.co.uk>
  40   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  41   */
  42  class gradeitems_test extends advanced_testcase {
  43  
  44      /**
  45       * Ensure that the mappings are present and correct.
  46       */
  47      public function test_get_itemname_mapping_for_component(): void {
  48          $mappings = component_gradeitems::get_itemname_mapping_for_component('mod_forum');
  49          $this->assertIsArray($mappings);
  50          $this->assertCount(2, $mappings);
  51          $this->assertArraySubset([0 => 'rating'], $mappings);
  52          $this->assertArraySubset([1 => 'forum'], $mappings);
  53      }
  54  
  55      /**
  56       * Ensure that the advanced grading only applies to the relevant items.
  57       */
  58      public function test_get_advancedgrading_itemnames_for_component(): void {
  59          $mappings = component_gradeitems::get_advancedgrading_itemnames_for_component('mod_forum');
  60          $this->assertIsArray($mappings);
  61          $this->assertCount(1, $mappings);
  62          $this->assertContains('forum', $mappings);
  63          $this->assertNotContains('rating', $mappings);
  64      }
  65  
  66      /**
  67       * Ensure that the correct items are identified by is_advancedgrading_itemname.
  68       *
  69       * @dataProvider is_advancedgrading_itemname_provider
  70       * @param string $itemname
  71       * @param bool $expected
  72       */
  73      public function test_is_advancedgrading_itemname(string $itemname, bool $expected): void {
  74          $this->assertEquals(
  75              $expected,
  76              component_gradeitems::is_advancedgrading_itemname('mod_forum', $itemname)
  77          );
  78      }
  79  
  80      /**
  81       * Data provider for tests of is_advancedgrading_itemname.
  82       *
  83       * @return array
  84       */
  85      public function is_advancedgrading_itemname_provider(): array {
  86          return [
  87              'rating is not advanced' => [
  88                  'rating',
  89                  false,
  90              ],
  91              'Whole forum grading is advanced' => [
  92                  'forum',
  93                  true,
  94              ],
  95          ];
  96      }
  97  }