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