1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\Module\monitor\TestCase; |
6
|
|
|
|
7
|
|
|
use SimpleSAML\Module\monitor\State as State; |
8
|
|
|
use SimpleSAML\Module\monitor\TestData as TestData; |
9
|
|
|
use SimpleSAML\Module\monitor\TestResult as TestResult; |
10
|
|
|
|
11
|
|
|
use function explode; |
12
|
|
|
use function in_array; |
13
|
|
|
use function is_null; |
14
|
|
|
|
15
|
|
|
class Module extends \SimpleSAML\Module\monitor\TestCaseFactory |
16
|
|
|
{ |
17
|
|
|
/** @var array */ |
18
|
|
|
private array $parsed = []; |
19
|
|
|
|
20
|
|
|
/** @var array */ |
21
|
|
|
private array $available = []; |
22
|
|
|
|
23
|
|
|
/** @var string */ |
24
|
|
|
private string $module; |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param \SimpleSAML\Module\monitor\TestData $testData |
29
|
|
|
* |
30
|
|
|
* @return void |
31
|
|
|
*/ |
32
|
|
|
protected function initialize(TestData $testData): void |
33
|
|
|
{ |
34
|
|
|
$this->module = $testData->getInputItem('required'); |
35
|
|
|
$available = $testData->getInputItem('available'); |
36
|
|
|
if (!is_null($available)) { |
37
|
|
|
$this->available = $available; |
38
|
|
|
} |
39
|
|
|
$this->parsed = explode('|', $this->module); |
40
|
|
|
|
41
|
|
|
$this->setCategory($testData->getInputItem('type')); |
|
|
|
|
42
|
|
|
parent::initialize($testData); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @return void |
48
|
|
|
*/ |
49
|
|
|
public function invokeTest(): void |
50
|
|
|
{ |
51
|
|
|
$testResult = new TestResult($this->getCategory(), $this->getModuleName()); |
52
|
|
|
|
53
|
|
|
$state = State::ERROR; |
54
|
|
|
$available = $this->getAvailable(); |
55
|
|
|
|
56
|
|
|
foreach ($this->parsed as $module) { |
57
|
|
|
if (in_array($module, $available)) { |
58
|
|
|
$state = State::OK; |
59
|
|
|
break 1; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
if ($state == State::OK) { |
64
|
|
|
$testResult->setMessage('Module loaded'); |
65
|
|
|
} else { |
66
|
|
|
$testResult->setMessage('Module not loaded'); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
$testResult->setState($state); |
70
|
|
|
$this->setTestResult($testResult); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return array |
76
|
|
|
*/ |
77
|
|
|
private function getAvailable(): array |
78
|
|
|
{ |
79
|
|
|
return $this->available; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @return string |
85
|
|
|
*/ |
86
|
|
|
private function getModule(): string |
87
|
|
|
{ |
88
|
|
|
return $this->module; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @return string |
94
|
|
|
*/ |
95
|
|
|
public function getModuleName(): string |
96
|
|
|
{ |
97
|
|
|
$available = $this->available; |
98
|
|
|
|
99
|
|
|
foreach ($this->parsed as $module) { |
100
|
|
|
if (in_array($module, $available)) { |
101
|
|
|
return $module; |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
return $this->getModule(); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|