2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
17 namespace core_course
;
19 defined('MOODLE_INTERNAL') ||
die();
22 require_once($CFG->dirroot
. '/course/lib.php');
23 require_once($CFG->dirroot
. '/course/format/tests/fixtures/format_theunittest.php');
24 require_once($CFG->dirroot
. '/course/format/lib.php');
27 * Course format function unit tests
29 * @package core_course
30 * @copyright 2021 Catalyst IT Pty Ltd
31 * @author Jason den Dulk
32 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34 class course_format_function_test
extends \basic_testcase
{
37 * Tests clean_param_if_not_null function
38 * @covers ::clean_param_if_not_null
40 public function test_clean_param_if_not_null() {
41 $this->assertNull(clean_param_if_not_null(null));
43 $this->assertEquals(clean_param($n, PARAM_INT
), clean_param_if_not_null($n, PARAM_INT
));
44 $this->assertEquals(clean_param($n, PARAM_RAW
), clean_param_if_not_null($n, PARAM_RAW
));
45 $this->assertEquals(clean_param($n, PARAM_ALPHANUM
), clean_param_if_not_null($n, PARAM_ALPHANUM
));
46 $this->assertEquals(clean_param($n, PARAM_ALPHA
), clean_param_if_not_null($n, PARAM_ALPHA
));
47 $s = '<abc>xyz</abc>';
48 $this->assertEquals(clean_param($s, PARAM_ALPHANUM
), clean_param_if_not_null($s, PARAM_ALPHANUM
));
49 $this->assertEquals(clean_param($s, PARAM_RAW
), clean_param_if_not_null($s, PARAM_RAW
));
53 * Tests contract_value function
54 * @covers ::contract_value
56 public function test_contract_value() {
58 'abc' => '<p>All together Now</p>',
63 'abc_editor' => [ 'text' => $input['abc'], 'format' => $input['abcformat'] ],
64 'jolly' => $input['jolly'],
68 'jolly' => [ 'type' => PARAM_ALPHA
],
72 foreach ($defs as $name => $def) {
73 contract_value($dest, $input, $def, $name);
76 $this->assertEquals($expected, $dest);
80 * Tests expand_value function
81 * @covers ::expand_value
83 public function test_expand_value() {
85 'abc_editor' => [ 'text' => '<p>All together Now</p>', 'format' => '1' ],
89 'abc' => $input['abc_editor']['text'],
90 'abcformat' => $input['abc_editor']['format'],
91 'jolly' => $input['jolly'],
95 'jolly' => [ 'type' => PARAM_ALPHA
],
99 foreach ($defs as $name => $def) {
100 expand_value($dest, $input, $def, $name);
103 $this->assertEquals($expected, $dest);