Proyectos de Subversion Moodle

Rev

Rev 11 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 11 Rev 1441
Línea 14... Línea 14...
14
// You should have received a copy of the GNU General Public License
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/>.
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
Línea 16... Línea 16...
16
 
16
 
Línea -... Línea 17...
-
 
17
namespace quizaccess_seb;
-
 
18
 
-
 
19
defined('MOODLE_INTERNAL') || die();
-
 
20
 
17
namespace quizaccess_seb;
21
require_once(__DIR__ . '/test_helper_trait.php');
18
 
22
 
19
/**
23
/**
20
 * PHPUnit tests for template class.
24
 * PHPUnit tests for template class.
21
 *
25
 *
22
 * @package   quizaccess_seb
26
 * @package   quizaccess_seb
23
 * @author    Dmitrii Metelkin <dmitriim@catalyst-au.net>
27
 * @author    Dmitrii Metelkin <dmitriim@catalyst-au.net>
24
 * @copyright 2020 Catalyst IT
28
 * @copyright 2020 Catalyst IT
25
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
-
 
30
 */
Línea 26... Línea 31...
26
 */
31
final class template_test extends \advanced_testcase {
27
class template_test extends \advanced_testcase {
32
    use \quizaccess_seb_test_helper_trait;
28
 
33
 
29
    /**
34
    /**
Línea 47... Línea 52...
47
        $data->content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
52
        $data->content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
48
<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
53
<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
49
<plist version=\"1.0\"><dict><key>showTaskBar</key><true/><key>allowWlan</key><false/><key>showReloadButton</key><true/>"
54
<plist version=\"1.0\"><dict><key>showTaskBar</key><true/><key>allowWlan</key><false/><key>showReloadButton</key><true/>"
50
            . "<key>showTime</key><false/><key>showInputLanguage</key><true/><key>allowQuit</key><true/>"
55
            . "<key>showTime</key><false/><key>showInputLanguage</key><true/><key>allowQuit</key><true/>"
51
            . "<key>quitURLConfirm</key><true/><key>audioControlEnabled</key><true/><key>audioMute</key><false/>"
56
            . "<key>quitURLConfirm</key><true/><key>audioControlEnabled</key><true/><key>audioMute</key><false/>"
-
 
57
            . "<key>browserMediaCaptureCamera</key><true/><key>browserMediaCaptureMicrophone</key><true/>"
52
            . "<key>allowSpellCheck</key><false/><key>browserWindowAllowReload</key><true/><key>URLFilterEnable</key><true/>"
58
            . "<key>allowSpellCheck</key><false/><key>browserWindowAllowReload</key><true/><key>URLFilterEnable</key><true/>"
53
            . "<key>URLFilterEnableContentFilter</key><false/><key>hashedQuitPassword</key>"
59
            . "<key>URLFilterEnableContentFilter</key><false/><key>hashedQuitPassword</key>"
54
            . "<string>9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08</string><key>URLFilterRules</key>"
60
            . "<string>9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08</string><key>URLFilterRules</key>"
55
            . "<array><dict><key>action</key><integer>1</integer><key>active</key><true/><key>expression</key>"
61
            . "<array><dict><key>action</key><integer>1</integer><key>active</key><true/><key>expression</key>"
56
            . "<string>test.com</string><key>regex</key><false/></dict></array>"
62
            . "<string>test.com</string><key>regex</key><false/></dict></array>"
Línea 95... Línea 101...
95
        $data->content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
101
        $data->content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
96
<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
102
<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
97
<plist version=\"1.0\"><dict><key>showTaskBar</key><true/><key>allowWlan</key><false/><key>showReloadButton</key><true/>"
103
<plist version=\"1.0\"><dict><key>showTaskBar</key><true/><key>allowWlan</key><false/><key>showReloadButton</key><true/>"
98
            . "<key>showTime</key><false/><key>showInputLanguage</key><true/><key>allowQuit</key><true/>"
104
            . "<key>showTime</key><false/><key>showInputLanguage</key><true/><key>allowQuit</key><true/>"
99
            . "<key>quitURLConfirm</key><true/><key>audioControlEnabled</key><true/><key>audioMute</key><false/>"
105
            . "<key>quitURLConfirm</key><true/><key>audioControlEnabled</key><true/><key>audioMute</key><false/>"
-
 
106
            . "<key>browserMediaCaptureCamera</key><true/><key>browserMediaCaptureMicrophone</key><true/>"
100
            . "<key>allowSpellCheck</key><false/><key>browserWindowAllowReload</key><true/><key>URLFilterEnable</key><true/>"
107
            . "<key>allowSpellCheck</key><false/><key>browserWindowAllowReload</key><true/><key>URLFilterEnable</key><true/>"
101
            . "<key>URLFilterEnableContentFilter</key><false/><key>hashedQuitPassword</key>"
108
            . "<key>URLFilterEnableContentFilter</key><false/><key>hashedQuitPassword</key>"
102
            . "<string>9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08</string><key>URLFilterRules</key>"
109
            . "<string>9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08</string><key>URLFilterRules</key>"
103
            . "<array><dict><key>action</key><integer>1</integer><key>active</key><true/><key>expression</key>"
110
            . "<array><dict><key>action</key><integer>1</integer><key>active</key><true/><key>expression</key>"
104
            . "<string>test.com</string><key>regex</key><false/></dict></array>"
111
            . "<string>test.com</string><key>regex</key><false/></dict></array>"
Línea 122... Línea 129...
122
            'allowuserquitseb' => '1',
129
            'allowuserquitseb' => '1',
123
            'quitpassword' => 'test',
130
            'quitpassword' => 'test',
124
            'linkquitseb' => '',
131
            'linkquitseb' => '',
125
            'userconfirmquit' => '1',
132
            'userconfirmquit' => '1',
126
            'enableaudiocontrol' => '1',
133
            'enableaudiocontrol' => '1',
-
 
134
            'allowcapturecamera' => '1',
-
 
135
            'allowcapturemicrophone' => '1',
127
            'muteonstartup' => '0',
136
            'muteonstartup' => '0',
128
            'allowspellchecking' => '0',
137
            'allowspellchecking' => '0',
129
            'allowreloadinexam' => '1',
138
            'allowreloadinexam' => '1',
130
            'activateurlfiltering' => '1',
139
            'activateurlfiltering' => '1',
131
            'filterembeddedcontent' => '0',
140
            'filterembeddedcontent' => '0',
Línea 138... Línea 147...
138
        ]);
147
        ]);
Línea 139... Línea 148...
139
 
148
 
140
        $this->assertFalse($template->can_delete());
149
        $this->assertFalse($template->can_delete());
Línea -... Línea 150...
-
 
150
    }
-
 
151
 
-
 
152
    /**
-
 
153
     * Test that a disabled template no longer shows up in quiz SEB settings other than quizzes already using it.
-
 
154
     *
-
 
155
     * @covers \quizaccess_seb\seb_quiz_settings::get_record
-
 
156
     * @covers \quizaccess_seb\settings_provider::get_requiresafeexambrowser_options
-
 
157
     */
-
 
158
    public function test_disabled_template_quiz_setting_options(): void {
-
 
159
        // Create quiz and fetch standard SEB requirement options.
-
 
160
        $this->setAdminUser();
-
 
161
        $this->course = $this->getDataGenerator()->create_course();
-
 
162
 
-
 
163
        $templateoptionstr = get_string('seb_use_template', 'quizaccess_seb');
-
 
164
 
-
 
165
        // Create a quiz.
-
 
166
        $this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
-
 
167
        $context = \context_module::instance($this->quiz->cmid);
-
 
168
 
-
 
169
        // Check there is no template option (as there aren't any).
-
 
170
        $options = settings_provider::get_requiresafeexambrowser_options($context);
-
 
171
        $this->assertNotContainsEquals($templateoptionstr, $options);
-
 
172
 
-
 
173
        // Create a template.
-
 
174
        $data = new \stdClass();
-
 
175
        $data->name = 'Test name';
-
 
176
        $data->description = 'Test description';
-
 
177
        $data->enabled = 1;
-
 
178
        $data->content = file_get_contents(self::get_fixture_path(__NAMESPACE__, 'unencrypted.seb'));
-
 
179
        $template = new template(0, $data);
-
 
180
        $template->save();
-
 
181
 
-
 
182
        // Check options now include template option.
-
 
183
        $options = settings_provider::get_requiresafeexambrowser_options($context);
-
 
184
        $this->assertContainsEquals($templateoptionstr, $options);
-
 
185
 
-
 
186
        // Set SEB setting to use template for quiz.
-
 
187
        $settings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
-
 
188
        $settings->set('templateid', $template->get('id'));
-
 
189
        $settings->set('requiresafeexambrowser', settings_provider::USE_SEB_TEMPLATE);
-
 
190
        $settings->save();
-
 
191
 
-
 
192
        // Disable template.
-
 
193
        $template->set('enabled', 0);
-
 
194
        $template->save();
-
 
195
 
-
 
196
        // Check option still exists on current quiz.
-
 
197
        $options = settings_provider::get_requiresafeexambrowser_options($context);
-
 
198
        $this->assertContainsEquals($templateoptionstr, $options);
-
 
199
 
-
 
200
        // Create a new quiz.
-
 
201
        $newquiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
-
 
202
        $context = \context_module::instance($newquiz->cmid);
-
 
203
 
-
 
204
        // Check there is no template option (as the template is now disabled).
-
 
205
        $options = settings_provider::get_requiresafeexambrowser_options($context);
141
    }
206
        $this->assertNotContainsEquals($templateoptionstr, $options);