forked from lightSAML/lightSAML
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SamlConstantsTest.php
72 lines (63 loc) · 1.91 KB
/
SamlConstantsTest.php
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
<?php
namespace LightSaml\Tests\Tests;
use LightSaml\SamlConstants;
use LightSaml\Tests\BaseTestCase;
class SamlConstantsTest extends BaseTestCase
{
/**
* @dataProvider methodsProvider
*/
public function test__is_not_valid($method)
{
$this->assertFalse(SamlConstants::$method('Nonsense'));
}
/**
* @dataProvider constantsProvider
*/
public function test__is_valid_method($method, $constant)
{
$value = constant('\LightSaml\SamlConstants::'.$constant);
$this->assertTrue(SamlConstants::$method($value));
}
public function methodsProvider()
{
return array(
array('isProtocolValid'),
array('isNsValid'),
array('isNameIdFormatValid'),
array('isBindingValid'),
array('isStatusValid'),
array('isConfirmationMethodValid'),
array('isAuthnContextValid'),
array('isLogoutReasonValid'),
);
}
public function constantsProvider()
{
return array_merge(
$this->getConstants('Protocol'),
$this->getConstants('Ns'),
$this->getConstants('NameIdFormat'),
$this->getConstants('Binding'),
$this->getConstants('Status'),
$this->getConstants('ConfirmationMethod'),
$this->getConstants('AuthnContext'),
$this->getConstants('LogoutReason')
);
}
public function getConstants($method)
{
$ret = array();
$ref = new \ReflectionClass('\LightSaml\SamlConstants');
$prefix = strtoupper(
preg_replace('/([a-z])([A-Z])/', '$1_$2', $method)
);
$method = 'is'.$method.'Valid';
foreach ($ref->getConstants() as $constant => $value) {
if (strpos($constant, $prefix) === 0) {
$ret[] = array($method, $constant);
}
}
return $ret;
}
}