Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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
/**
18
 * Unit tests for frontend of relativedate condition.
19
 *
20
 * @package   availability_relativedate
21
 * @copyright 2022 eWallah.net
22
 * @author    Renaat Debleu <info@eWallah.net>
23
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 */
25
 
26
namespace availability_relativedate;
27
 
28
/**
29
 * Unit tests for frontend of relativedate condition.
30
 *
31
 * @package   availability_relativedate
32
 * @copyright 2022 eWallah.net
33
 * @author    Renaat Debleu <info@eWallah.net>
34
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35
 * @coversDefaultClass \availability_relativedate\frontend
36
 */
37
final class frontend_test extends \advanced_testcase {
38
    /**
39
     * Tests using relativedate condition in front end.
40
     * @covers \availability_relativedate\frontend
41
     */
42
    public function test_frontend(): void {
43
        global $DB;
44
        $this->resetAfterTest();
45
        $this->setAdminUser();
46
        set_config('enableavailability', true);
47
        $enabled = enrol_get_plugins(true);
48
        $enabled['self'] = true;
49
        set_config('enrol_plugins_enabled', implode(',', array_keys($enabled)));
50
        $dg = $this->getDataGenerator();
51
        $course = $dg->create_course(['enablecompletion' => 1, 'enddate' => time() + 999999]);
52
        $dg->get_plugin_generator('mod_page')->create_instance(['course' => $course]);
53
        $dg->create_module('assign', ['course' => $course->id], ['completion' => 1]);
54
        $modinfo = get_fast_modinfo($course);
55
        $sections = $modinfo->get_section_info_all();
56
        $selfplugin = enrol_get_plugin('self');
57
        $instance = $DB->get_record('enrol', ['courseid' => $course->id, 'enrol' => 'self'], '*', MUST_EXIST);
58
        $DB->set_field('enrol', 'enrolenddate', time() + 10000, ['id' => $instance->id]);
59
        $instance = $DB->get_record('enrol', ['courseid' => $course->id, 'enrol' => 'self'], '*', MUST_EXIST);
60
        $user = $dg->create_user();
61
        $selfplugin->enrol_user($instance, $user->id);
62
        $name = '\availability_relativedate\frontend';
63
        $frontend = new frontend();
64
        $this->assertCount(5, \phpunit_util::call_internal_method($frontend, 'get_javascript_init_params', [$course], $name));
65
        foreach ($modinfo->get_instances() as $cms) {
66
            foreach ($cms as $cm) {
67
                $this->assertCount(5, \phpunit_util::call_internal_method(
68
                    $frontend,
69
                    'get_javascript_init_params',
70
                    [$course, $cm],
71
                    $name
72
                ));
73
            }
74
        }
75
        $this->assertTrue(\phpunit_util::call_internal_method($frontend, 'allow_add', [$course, null, $sections[0]], $name));
76
        $this->assertTrue(\phpunit_util::call_internal_method($frontend, 'allow_add', [$course, null, $sections[1]], $name));
77
        $this->assertTrue(\phpunit_util::call_internal_method($frontend, 'allow_add', [$course], $name));
78
    }
79
 
80
    /**
81
     * Test behat funcs
82
     * @covers \behat_availability_relativedate
83
     */
84
    public function test_behat(): void {
85
        global $CFG;
86
        require_once($CFG->dirroot . '/availability/condition/relativedate/tests/behat/behat_availability_relativedate.php');
87
        $this->resetAfterTest();
88
        $this->setAdminUser();
89
        set_config('enableavailability', true);
90
        $dg = $this->getDataGenerator();
91
        $course = $dg->create_course(['enablecompletion' => true]);
92
        $dg->get_plugin_generator('mod_page')->create_instance(['course' => $course, 'idnumber' => 'page1']);
93
        $dg->get_plugin_generator('mod_page')->create_instance(['course' => $course, 'idnumber' => 'page2']);
94
        $class = new \behat_availability_relativedate();
95
        $class->selfenrolment_exists_in_course_starting($course->fullname, '');
96
        $class->selfenrolment_exists_in_course_starting($course->fullname, '##-10 days noon##');
97
        $class->selfenrolment_exists_in_course_ending($course->fullname, '');
98
        $class->selfenrolment_exists_in_course_ending($course->fullname, '## today ##');
99
        $this->expectExceptionMessage('behat_context_helper');
100
        $class->i_should_see_relativedate('##-10 days noon##');
101
        $class->i_make_activity_relative_date_depending_on('page1', 'page2');
102
    }
103
}