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.
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.

< /** < * Tests for field value validators of tool_uploaduser. < * < * @package tool_uploaduser < * @copyright 2019 Jun Pataleta < * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later < */
> namespace tool_uploaduser;
use tool_uploaduser\local\field_value_validators;
< defined('MOODLE_INTERNAL') || die(); < < global $CFG; <
/** * Tests for field value validators of tool_uploaduser. * * @package tool_uploaduser * @copyright 2019 Jun Pataleta * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */
< class field_value_validators_testcase extends advanced_testcase {
> class field_value_validators_test extends \advanced_testcase {
/** * Data provider for \field_value_validators_testcase::test_validate_theme(). */ public function themes_provider() { return [ 'User themes disabled' => [ false, 'boost', 'warning', get_string('userthemesnotallowed', 'tool_uploaduser') ], 'User themes enabled, empty theme' => [ true, '', 'warning', get_string('notheme', 'tool_uploaduser') ], 'User themes enabled, invalid theme' => [ true, 'badtheme', 'warning', get_string('invalidtheme', 'tool_uploaduser', 'badtheme') ], 'User themes enabled, valid theme' => [ true, 'boost', 'normal', '' ], ]; } /** * Unit test for \tool_uploaduser\local\field_value_validators::validate_theme() * * @dataProvider themes_provider * @param boolean $userthemesallowed Whether to allow user themes. * @param string $themename The theme name to be tested. * @param string $expectedstatus The expected status. * @param string $expectedmessage The expected validation message. */ public function test_validate_theme($userthemesallowed, $themename, $expectedstatus, $expectedmessage) { $this->resetAfterTest(); // Set value for $CFG->allowuserthemes. set_config('allowuserthemes', $userthemesallowed); // Validate the theme. list($status, $message) = field_value_validators::validate_theme($themename); // Check the status and validation message. $this->assertEquals($expectedstatus, $status); $this->assertEquals($expectedmessage, $message); } }