1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverStripe\MFA\Tests\Report; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Core\Config\Config; |
6
|
|
|
use SilverStripe\Dev\SapphireTest; |
7
|
|
|
use SilverStripe\Forms\DropdownField; |
8
|
|
|
use SilverStripe\MFA\BackupCode\Method as BackupMethod; |
9
|
|
|
use SilverStripe\MFA\Report\EnabledMembers; |
10
|
|
|
use SilverStripe\MFA\Service\MethodRegistry; |
11
|
|
|
use SilverStripe\MFA\Tests\Stub\BasicMath\Method as BasicMathMethod; |
12
|
|
|
use SilverStripe\MFA\Tests\Stub\Null\Method as NullMethod; |
13
|
|
|
|
14
|
|
|
class EnabledMembersTest extends SapphireTest |
15
|
|
|
{ |
16
|
|
|
protected static $fixture_file = 'EnabledMembersTest.yml'; |
17
|
|
|
|
18
|
|
|
protected function setUp() |
19
|
|
|
{ |
20
|
|
|
parent::setUp(); |
21
|
|
|
Config::modify() |
22
|
|
|
->set(MethodRegistry::class, 'default_backup_method', BackupMethod::class) |
23
|
|
|
->set(MethodRegistry::class, 'methods', [BasicMathMethod::class, NullMethod::class, BackupMethod::class]); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function testRegisteredMethodFilterFieldDoesNotContainBackupMethod() |
27
|
|
|
{ |
28
|
|
|
$report = new EnabledMembers(); |
29
|
|
|
$fields = $report->parameterFields(); |
30
|
|
|
/** @var DropdownField $registeredMethodFilterField */ |
31
|
|
|
$registeredMethodFilterField = $fields->dataFieldByName('Methods'); |
32
|
|
|
$source = $registeredMethodFilterField->getSource(); |
33
|
|
|
$this->assertArrayNotHasKey(BackupMethod::class, $source); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @dataProvider sourceRecordsParamsProvider |
38
|
|
|
* @param array $params |
39
|
|
|
* @param int $expectedRows |
40
|
|
|
* @param string $explanation |
41
|
|
|
*/ |
42
|
|
|
public function testSourceRecords($params, $expectedRows, $explanation = null) |
43
|
|
|
{ |
44
|
|
|
$report = new EnabledMembers(); |
45
|
|
|
$records = $report->sourceRecords($params); |
46
|
|
|
$this->assertEquals($expectedRows, $records->count(), $explanation); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function sourceRecordsParamsProvider() |
50
|
|
|
{ |
51
|
|
|
return [ |
52
|
|
|
[[], 5, 'Sanity test'], |
53
|
|
|
[['Skipped' => '1'], 2, 'Skipped setup filter works'], |
54
|
|
|
[['Skipped' => '1', 'Count' => '0'], 1, 'Show members that have skipped and do not have a method set up'], |
55
|
|
|
[['Count' => '2'], 1, 'Filtering by number of methods set up works'], |
56
|
|
|
[['Count' => '2', 'Methods' => BasicMathMethod::class], 1, 'Count and Methods fitlers work together'], |
57
|
|
|
[ |
58
|
|
|
['Member' => 'i'], |
59
|
|
|
4, |
60
|
|
|
'Searching for a member works over FirstName or Surname and is a disjunctive partial match' |
61
|
|
|
], |
62
|
|
|
[['Member' => '.com'], 4, 'Member search includes Email'], |
63
|
|
|
[['Methods' => BasicMathMethod::class], 2, 'Searching for a particular method works'], |
64
|
|
|
[ |
65
|
|
|
['Methods' => BasicMathMethod::class, 'Member' => 'EDITOR', 'Count' => '1', 'Skipped' => '1'], |
66
|
|
|
1, |
67
|
|
|
'Control test that all filters are conjunctive' |
68
|
|
|
], |
69
|
|
|
[['Methods' => BasicMathMethod::class, 'Member' => 'EDITOR', 'Count' => '1', 'Skipped' => '0'], 0], |
70
|
|
|
[['Methods' => BasicMathMethod::class, 'Member' => 'EDITOR', 'Count' => '2', 'Skipped' => '1'], 0], |
71
|
|
|
[['Methods' => BasicMathMethod::class, 'Member' => 'MFA', 'Count' => '1', 'Skipped' => '1'], 0], |
72
|
|
|
[['Methods' => NullMethod::class, 'Member' => 'EDITOR', 'Count' => '1', 'Skipped' => '1'], 0], |
73
|
|
|
[['Methods' => NullMethod::class, 'Member' => 'MFA', 'Count' => '2', 'Skipped' => '0'], 1], |
74
|
|
|
[ |
75
|
|
|
['Methods' => '', 'Member' => '', 'Count' => '', 'Skipped' => ''], |
76
|
|
|
5, |
77
|
|
|
'An empty filter input set does not destroy the result set' |
78
|
|
|
], |
79
|
|
|
]; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|