Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | 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
namespace quizaccess_seb;
18
 
19
/**
20
 * PHPUnit tests for link_generator.
21
 *
22
 * @package   quizaccess_seb
23
 * @author    Andrew Madden <andrewmadden@catalyst-au.net>
24
 * @copyright 2020 Catalyst IT
25
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26
 */
27
class link_generator_test extends \advanced_testcase {
28
 
29
    /**
30
     * Called before every test.
31
     */
32
    public function setUp(): void {
33
        parent::setUp();
34
        $this->resetAfterTest();
35
    }
36
 
37
    /**
38
     * Test that a http link is generated correctly.
39
     */
11 efrain 40
    public function test_http_link_generated(): void {
1 efrain 41
        $course = $this->getDataGenerator()->create_course();
42
        $quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $course->id]);
43
 
44
        $this->assertEquals(
45
            "http://www.example.com/moodle/mod/quiz/accessrule/seb/config.php?cmid=$quiz->cmid",
46
            link_generator::get_link($quiz->cmid, false, false));
47
    }
48
 
49
    /**
50
     * Test that a http link is generated correctly.
51
     */
11 efrain 52
    public function test_https_link_generated(): void {
1 efrain 53
        $course = $this->getDataGenerator()->create_course();
54
        $quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $course->id]);
55
 
56
        $this->assertEquals(
57
            "https://www.example.com/moodle/mod/quiz/accessrule/seb/config.php?cmid=$quiz->cmid",
58
            link_generator::get_link($quiz->cmid, false));
59
    }
60
 
61
    /**
62
     * Test that a seb link is generated correctly.
63
     */
11 efrain 64
    public function test_seb_link_generated(): void {
1 efrain 65
        $course = $this->getDataGenerator()->create_course();
66
        $quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $course->id]);
67
 
68
        $this->assertEquals(
69
            "seb://www.example.com/moodle/mod/quiz/accessrule/seb/config.php?cmid=$quiz->cmid",
70
            link_generator::get_link($quiz->cmid, true, false));
71
    }
72
 
73
    /**
74
     * Test that a sebs link is generated correctly.
75
     */
11 efrain 76
    public function test_sebs_link_generated(): void {
1 efrain 77
        $course = $this->getDataGenerator()->create_course();
78
        $quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $course->id]);
79
 
80
        $this->assertEquals(
81
            "sebs://www.example.com/moodle/mod/quiz/accessrule/seb/config.php?cmid=$quiz->cmid",
82
            link_generator::get_link($quiz->cmid, true));
83
    }
84
 
85
    /**
86
     * Test that link_generator can't not be instantiated with fake course module.
87
     */
11 efrain 88
    public function test_course_module_does_not_exist(): void {
1 efrain 89
        $this->expectException(\dml_exception::class);
90
        $this->expectExceptionMessageMatches("/^Can't find data record in database.*/");
91
        $generator = link_generator::get_link(123456, false);
92
    }
93
}