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