Merge branch 'MDL-75012-39-5' of https://github.com/andrewnicols/moodle into MOODLE_3...
[moodle.git] / lib / form / tests / course_test.php
blob49c09eee3927f92d180f30f2c8fc287ccabb5a55
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 /**
18 * Unit tests for MoodleQuickForm_course.
20 * This file contains unit tests related to course forms element.
22 * @package core_form
23 * @category test
24 * @copyright 2020 Ruslan Kabalin
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 defined('MOODLE_INTERNAL') || die();
30 global $CFG;
31 require_once($CFG->libdir . '/form/course.php');
33 /**
34 * Unit tests for MoodleQuickForm_course
36 * Contains test cases for testing MoodleQuickForm_course.
38 * @package core_form
39 * @category test
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 {
45 /**
46 * Test constructor supports all declared attributes.
48 public function test_constructor_attributes() {
49 $attributes = [
50 'exclude' => [1, 2],
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.
64 $attributes = [
65 'multiple' => true,
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);