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/>.
18 * Unit tests for MoodleQuickForm_course.
20 * This file contains unit tests related to course forms element.
24 * @copyright 2020 Ruslan Kabalin
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 defined('MOODLE_INTERNAL') ||
die();
31 require_once($CFG->libdir
. '/form/course.php');
34 * Unit tests for MoodleQuickForm_course
36 * Contains test cases for testing MoodleQuickForm_course.
40 * @copyright 2020 Ruslan Kabalin
41 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
43 class core_form_course_testcase
extends basic_testcase
{
46 * Test constructor supports all declared attributes.
48 public function test_constructor_attributes() {
51 'requiredcapabilities' => ['moodle/course:update'],
54 $element = new MoodleQuickForm_course('testel', null, $attributes);
55 $html = $element->toHtml();
56 $this->assertContains('data-exclude="1,2"', $html);
57 $this->assertContains('data-requiredcapabilities="moodle/course:update"', $html);
58 $this->assertContains('data-limittoenrolled="0"', $html);
59 $this->assertNotContains('multiple', $html);
60 $this->assertNotContains('data-includefrontpage', $html);
61 $this->assertNotContains('data-onlywithcompletion', $html);
63 // Add more attributes.
66 'limittoenrolled' => true,
67 'includefrontpage' => true,
68 'onlywithcompletion' => true,
70 $element = new MoodleQuickForm_course('testel', null, $attributes);
71 $html = $element->toHtml();
72 $this->assertContains('multiple', $html);
73 $this->assertContains('data-limittoenrolled="1"', $html);
74 $this->assertContains('data-includefrontpage="' . SITEID
. '"', $html);
75 $this->assertContains('data-onlywithcompletion="1"', $html);