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.

Differences Between: [Versions 310 and 401] [Versions 39 and 401]

   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 tool_uploaduser;
  18  
  19  use tool_uploaduser\local\field_value_validators;
  20  
  21  /**
  22   * Tests for field value validators of tool_uploaduser.
  23   *
  24   * @package    tool_uploaduser
  25   * @copyright  2019 Jun Pataleta
  26   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  27   */
  28  class field_value_validators_test extends \advanced_testcase {
  29  
  30      /**
  31       * Data provider for \field_value_validators_testcase::test_validate_theme().
  32       */
  33      public function themes_provider() {
  34          return [
  35              'User themes disabled' => [
  36                  false, 'boost', 'warning', get_string('userthemesnotallowed', 'tool_uploaduser')
  37              ],
  38              'User themes enabled, empty theme' => [
  39                  true, '', 'warning', get_string('notheme', 'tool_uploaduser')
  40              ],
  41              'User themes enabled, invalid theme' => [
  42                  true, 'badtheme', 'warning', get_string('invalidtheme', 'tool_uploaduser', 'badtheme')
  43              ],
  44              'User themes enabled, valid theme' => [
  45                  true, 'boost', 'normal', ''
  46              ],
  47          ];
  48      }
  49  
  50      /**
  51       * Unit test for \tool_uploaduser\local\field_value_validators::validate_theme()
  52       *
  53       * @dataProvider themes_provider
  54       * @param boolean $userthemesallowed Whether to allow user themes.
  55       * @param string $themename The theme name to be tested.
  56       * @param string $expectedstatus The expected status.
  57       * @param string $expectedmessage The expected validation message.
  58       */
  59      public function test_validate_theme($userthemesallowed, $themename, $expectedstatus, $expectedmessage) {
  60          $this->resetAfterTest();
  61  
  62          // Set value for $CFG->allowuserthemes.
  63          set_config('allowuserthemes', $userthemesallowed);
  64  
  65          // Validate the theme.
  66          list($status, $message) = field_value_validators::validate_theme($themename);
  67  
  68          // Check the status and validation message.
  69          $this->assertEquals($expectedstatus, $status);
  70          $this->assertEquals($expectedmessage, $message);
  71      }
  72  }