1 |
efrain |
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 core_form;
|
|
|
18 |
|
|
|
19 |
defined('MOODLE_INTERNAL') || die();
|
|
|
20 |
|
|
|
21 |
global $CFG;
|
|
|
22 |
require_once($CFG->libdir . '/form/course.php');
|
|
|
23 |
|
|
|
24 |
/**
|
|
|
25 |
* Unit tests for MoodleQuickForm_course
|
|
|
26 |
*
|
|
|
27 |
* Contains test cases for testing MoodleQuickForm_course.
|
|
|
28 |
*
|
|
|
29 |
* @package core_form
|
|
|
30 |
* @category test
|
|
|
31 |
* @copyright 2020 Ruslan Kabalin
|
|
|
32 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
33 |
*/
|
|
|
34 |
class course_test extends \basic_testcase {
|
|
|
35 |
|
|
|
36 |
/**
|
|
|
37 |
* Test constructor supports all declared attributes.
|
|
|
38 |
*/
|
11 |
efrain |
39 |
public function test_constructor_attributes(): void {
|
1 |
efrain |
40 |
$attributes = [
|
|
|
41 |
'exclude' => [1, 2],
|
|
|
42 |
'requiredcapabilities' => ['moodle/course:update'],
|
|
|
43 |
];
|
|
|
44 |
|
|
|
45 |
$element = new \MoodleQuickForm_course('testel', null, $attributes);
|
|
|
46 |
$html = $element->toHtml();
|
|
|
47 |
$this->assertStringContainsString('data-exclude="1,2"', $html);
|
|
|
48 |
$this->assertStringContainsString('data-requiredcapabilities="moodle/course:update"', $html);
|
|
|
49 |
$this->assertStringContainsString('data-limittoenrolled="0"', $html);
|
|
|
50 |
$this->assertStringNotContainsString('multiple', $html);
|
|
|
51 |
$this->assertStringNotContainsString('data-includefrontpage', $html);
|
|
|
52 |
$this->assertStringNotContainsString('data-onlywithcompletion', $html);
|
|
|
53 |
|
|
|
54 |
// Add more attributes.
|
|
|
55 |
$attributes = [
|
|
|
56 |
'multiple' => true,
|
|
|
57 |
'limittoenrolled' => true,
|
|
|
58 |
'includefrontpage' => true,
|
|
|
59 |
'onlywithcompletion' => true,
|
|
|
60 |
];
|
|
|
61 |
$element = new \MoodleQuickForm_course('testel', null, $attributes);
|
|
|
62 |
$html = $element->toHtml();
|
|
|
63 |
$this->assertStringContainsString('multiple', $html);
|
|
|
64 |
$this->assertStringContainsString('data-limittoenrolled="1"', $html);
|
|
|
65 |
$this->assertStringContainsString('data-includefrontpage="' . SITEID . '"', $html);
|
|
|
66 |
$this->assertStringContainsString('data-onlywithcompletion="1"', $html);
|
|
|
67 |
}
|
|
|
68 |
}
|