Skip to content

Commit d5f226c

Browse files
Hannes FunkPhMemmel
authored andcommitted
MBS-10346: Unite dataproviders
1 parent 595011a commit d5f226c

File tree

2 files changed

+125
-87
lines changed

2 files changed

+125
-87
lines changed

tests/local/tenant_test.php

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
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 local_ai_manager\local;
18+
19+
/**
20+
* Unit tests for the tenant data object.
21+
*
22+
* @package local_ai_manager
23+
* @copyright 2026 ISB Bayern
24+
* @author Johannes Funk
25+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26+
*/
27+
final class tenant_test extends \advanced_testcase {
28+
/**
29+
* Tests the validation of identifier string in the tenant constructor.
30+
*
31+
* @dataProvider identifier_provider
32+
* @covers \local_ai_manager\local\tenant::__construct
33+
*/
34+
public function test_validation($name, $valid): void {
35+
if ($valid) {
36+
$tenant = new \local_ai_manager\local\tenant($name);
37+
$this->assertSame($name, $tenant->get_identifier());
38+
} else {
39+
$this->expectException(\invalid_parameter_exception::class);
40+
new \local_ai_manager\local\tenant($name);
41+
}
42+
}
43+
44+
/**
45+
* Data provider.
46+
*
47+
* @return array
48+
*/
49+
public static function identifier_provider(): array {
50+
return [
51+
'default_identifier' => [
52+
'name' => 'default',
53+
'valid' => true,
54+
],
55+
'identifier_with_hyphen' => [
56+
'name' => 'tenant-1',
57+
'valid' => true,
58+
],
59+
'identifier_with_space' => [
60+
'name' => 'Maths Department',
61+
'valid' => true,
62+
],
63+
'identifier_with_hypen_and_numbers' => [
64+
'name' => 'School-123 Munich',
65+
'valid' => true,
66+
],
67+
'identifier_only_numeric' => [
68+
'name' => '123',
69+
'valid' => true,
70+
],
71+
'identifier_with_multiple_spaces' => [
72+
'name' => 'a b c',
73+
'valid' => true,
74+
],
75+
'identifier_with_underscore' => [
76+
'name' => 'underscore_university',
77+
'valid' => true,
78+
],
79+
'identifier_with_exclamation_mark' => [
80+
'name' => 'name!',
81+
'valid' => false,
82+
],
83+
'identifier_with_at_symbol' => [
84+
'name' => 'name@domain',
85+
'valid' => false,
86+
],
87+
'identifier_with_hashtag' => [
88+
'name' => 'name#hash',
89+
'valid' => false,
90+
],
91+
'identifier_with_percent' => [
92+
'name' => 'percent%',
93+
'valid' => false,
94+
],
95+
'identifier_with_backslash' => [
96+
'name' => 'newline\n',
97+
'valid' => false,
98+
],
99+
'identifier_with_umlaut' => [
100+
'name' => 'unicode-ä',
101+
'valid' => false,
102+
],
103+
'identifier_with_slashes' => [
104+
'name' => '/slashes/',
105+
'valid' => false,
106+
],
107+
'identifier_with_comma' => [
108+
'name' => 'comma,comma',
109+
'valid' => false,
110+
],
111+
'identifier_with_HTML' => [
112+
'name' => 'HTML-Tag<br />',
113+
'valid' => false,
114+
],
115+
'identifier_with_leading_whitespace' => [
116+
'name' => ' Whitespace University',
117+
'valid' => false,
118+
],
119+
'identifier_with_trailing_whitespace' => [
120+
'name' => 'Whitespace School ',
121+
'valid' => false,
122+
],
123+
];
124+
}
125+
}

tests/tenant_test.php

Lines changed: 0 additions & 87 deletions
This file was deleted.

0 commit comments

Comments
 (0)