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 template class. 19 * 20 * @package quizaccess_seb 21 * @author Dmitrii Metelkin <dmitriim@catalyst-au.net> 22 * @copyright 2020 Catalyst IT 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 use quizaccess_seb\template; 27 28 defined('MOODLE_INTERNAL') || die(); 29 30 /** 31 * PHPUnit tests for template class. 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_template_testcase extends advanced_testcase { 37 38 /** 39 * Called before every test. 40 */ 41 public function setUp(): void { 42 parent::setUp(); 43 44 $this->resetAfterTest(); 45 } 46 47 /** 48 * Test that template saved with valid content. 49 */ 50 public function test_template_is_saved() { 51 global $DB; 52 $data = new stdClass(); 53 $data->name = 'Test name'; 54 $data->description = 'Test description'; 55 $data->enabled = 1; 56 $data->content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> 57 <!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"> 58 <plist version=\"1.0\"><dict><key>showTaskBar</key><true/><key>allowWlan</key><false/><key>showReloadButton</key><true/>" 59 . "<key>showTime</key><false/><key>showInputLanguage</key><true/><key>allowQuit</key><true/>" 60 . "<key>quitURLConfirm</key><true/><key>audioControlEnabled</key><true/><key>audioMute</key><false/>" 61 . "<key>allowSpellCheck</key><false/><key>browserWindowAllowReload</key><true/><key>URLFilterEnable</key><true/>" 62 . "<key>URLFilterEnableContentFilter</key><false/><key>hashedQuitPassword</key>" 63 . "<string>9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08</string><key>URLFilterRules</key>" 64 . "<array><dict><key>action</key><integer>1</integer><key>active</key><true/><key>expression</key>" 65 . "<string>test.com</string><key>regex</key><false/></dict></array>" 66 . "<key>sendBrowserExamKey</key><true/></dict></plist>\n"; 67 $template = new template(0, $data); 68 $template->save(); 69 70 $actual = $DB->get_record(template::TABLE, ['id' => $template->get('id')]); 71 $this->assertEquals($data->name, $actual->name); 72 $this->assertEquals($data->description, $actual->description); 73 $this->assertEquals($data->enabled, $actual->enabled); 74 $this->assertEquals($data->content, $actual->content); 75 $this->assertTrue($template->can_delete()); 76 } 77 78 /** 79 * Test that template is not saved with invalid content. 80 */ 81 public function test_template_is_not_saved_with_invalid_content() { 82 $this->expectException(\core\invalid_persistent_exception::class); 83 $this->expectExceptionMessage('Invalid SEB config template'); 84 85 $data = new stdClass(); 86 $data->name = 'Test name'; 87 $data->description = 'Test description'; 88 $data->enabled = 1; 89 $data->content = "Invalid content"; 90 $template = new template(0, $data); 91 $template->save(); 92 } 93 94 /** 95 * Test that a template cannot be deleted when assigned to a quiz. 96 */ 97 public function test_cannot_delete_template_when_assigned_to_quiz() { 98 global $DB; 99 100 $data = new stdClass(); 101 $data->name = 'Test name'; 102 $data->description = 'Test description'; 103 $data->enabled = 1; 104 $data->content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> 105 <!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"> 106 <plist version=\"1.0\"><dict><key>showTaskBar</key><true/><key>allowWlan</key><false/><key>showReloadButton</key><true/>" 107 . "<key>showTime</key><false/><key>showInputLanguage</key><true/><key>allowQuit</key><true/>" 108 . "<key>quitURLConfirm</key><true/><key>audioControlEnabled</key><true/><key>audioMute</key><false/>" 109 . "<key>allowSpellCheck</key><false/><key>browserWindowAllowReload</key><true/><key>URLFilterEnable</key><true/>" 110 . "<key>URLFilterEnableContentFilter</key><false/><key>hashedQuitPassword</key>" 111 . "<string>9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08</string><key>URLFilterRules</key>" 112 . "<array><dict><key>action</key><integer>1</integer><key>active</key><true/><key>expression</key>" 113 . "<string>test.com</string><key>regex</key><false/></dict></array>" 114 . "<key>sendBrowserExamKey</key><true/></dict></plist>\n"; 115 $template = new template(0, $data); 116 117 $template->save(); 118 $this->assertTrue($template->can_delete()); 119 120 $DB->insert_record(\quizaccess_seb\quiz_settings::TABLE, (object) [ 121 'quizid' => 1, 122 'cmid' => 1, 123 'templateid' => $template->get('id'), 124 'requiresafeexambrowser' => '1', 125 'sebconfigfile' => '373552893', 126 'showsebtaskbar' => '1', 127 'showwificontrol' => '0', 128 'showreloadbutton' => '1', 129 'showtime' => '0', 130 'showkeyboardlayout' => '1', 131 'allowuserquitseb' => '1', 132 'quitpassword' => 'test', 133 'linkquitseb' => '', 134 'userconfirmquit' => '1', 135 'enableaudiocontrol' => '1', 136 'muteonstartup' => '0', 137 'allowspellchecking' => '0', 138 'allowreloadinexam' => '1', 139 'activateurlfiltering' => '1', 140 'filterembeddedcontent' => '0', 141 'expressionsallowed' => 'test.com', 142 'regexallowed' => '', 143 'expressionsblocked' => '', 144 'regexblocked' => '', 145 'showsebdownloadlink' => '1', 146 'config' => '', 147 ]); 148 149 $this->assertFalse($template->can_delete()); 150 } 151 152 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body