MDL-80949 mod_data: Remove unused Allow autolink param for text field
[moodle.git] / course / tests / course_format_function_test.php
blob6e89eca9786b9a89a752c8b953e18cedf872e90b
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.
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();
21 global $CFG;
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');
26 /**
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 {
36 /**
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));
42 $n = '3x';
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));
52 /**
53 * Tests contract_value function
54 * @covers ::contract_value
56 public function test_contract_value() {
57 $input = [
58 'abc' => '<p>All together Now</p>',
59 'abcformat' => '1',
60 'jolly' => 'Roger'
62 $expected = [
63 'abc_editor' => [ 'text' => $input['abc'], 'format' => $input['abcformat'] ],
64 'jolly' => $input['jolly'],
66 $defs = [
67 'abc_editor' => [],
68 'jolly' => [ 'type' => PARAM_ALPHA ],
70 $dest = [];
72 foreach ($defs as $name => $def) {
73 contract_value($dest, $input, $def, $name);
76 $this->assertEquals($expected, $dest);
79 /**
80 * Tests expand_value function
81 * @covers ::expand_value
83 public function test_expand_value() {
84 $input = [
85 'abc_editor' => [ 'text' => '<p>All together Now</p>', 'format' => '1' ],
86 'jolly' => 'Roger',
88 $expected = [
89 'abc' => $input['abc_editor']['text'],
90 'abcformat' => $input['abc_editor']['format'],
91 'jolly' => $input['jolly'],
93 $defs = [
94 'abc_editor' => [],
95 'jolly' => [ 'type' => PARAM_ALPHA ],
97 $dest = [];
99 foreach ($defs as $name => $def) {
100 expand_value($dest, $input, $def, $name);
103 $this->assertEquals($expected, $dest);