-
Notifications
You must be signed in to change notification settings - Fork 143
Expand file tree
/
Copy pathtests_generator.php
More file actions
74 lines (68 loc) · 2.51 KB
/
tests_generator.php
File metadata and controls
74 lines (68 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace auth_saml2\testing;
/**
* Methods common to Moodle and Totara tests generators
*
* @package auth_saml2
* @author Noemie Ariste <noemie.ariste@catalyst.net.nz>
* @copyright Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @internal
*/
trait tests_generator {
/**
* To be called from data reset code only,
* do not use in tests.
* @return void
*/
public function reset() {
$this->entitiescount = 0;
}
/**
* Creates new IdP entity
*
* @param array|stdClass $idprecord
* @param bool $createfiles
* @return stdClass record from db
*/
public function create_idp_entity($idprecord = [], $createfiles = true) : \stdClass {
global $DB;
// Add IdP and configuration.
$entitycount = ++$this->entitiescount;
if (!array_key_exists('metadataurl', $idprecord)) {
$idprecord['metadataurl'] = 'https://idp.example.org/idp/shibboleth';
}
if (!array_key_exists('entityid', $idprecord)) {
$idprecord['entityid'] = "https://idp{$entitycount}.example.org/idp/shibboleth";
}
if (!array_key_exists('defaultname', $idprecord)) {
$idprecord['defaultname'] = "Test IdP {$entitycount}";
}
if (!array_key_exists('activeidp', $idprecord)) {
$idprecord['activeidp'] = 1;
}
$recordid = $DB->insert_record('auth_saml2_idps', $idprecord);
set_config('idpmetadata', $idprecord['metadataurl'], 'auth_saml2');
if ($createfiles) {
$auth = get_auth_plugin('saml2');
touch($auth->certcrt);
touch($auth->certpem);
touch($auth->get_file(md5($idprecord['metadataurl']). ".idp.xml"));
}
return $DB->get_record('auth_saml2_idps', ['id' => $recordid]);
}
}