|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SilverStripe\MFA\Tests\Service; |
|
4
|
|
|
|
|
5
|
|
|
use SilverStripe\Dev\SapphireTest; |
|
6
|
|
|
use SilverStripe\MFA\Service\MethodRegistry; |
|
7
|
|
|
use SilverStripe\MFA\Service\SchemaGenerator; |
|
8
|
|
|
use SilverStripe\MFA\Tests\Stub\BasicMath\Method as BasicMathMethod; |
|
9
|
|
|
use SilverStripe\Security\Member; |
|
10
|
|
|
|
|
11
|
|
|
class SchemaGeneratorTest extends SapphireTest |
|
12
|
|
|
{ |
|
13
|
|
|
protected static $fixture_file = 'SchemaGeneratorTest.yml'; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @var SchemaGenerator |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $generator; |
|
19
|
|
|
|
|
20
|
|
|
protected function setUp() |
|
21
|
|
|
{ |
|
22
|
|
|
parent::setUp(); |
|
23
|
|
|
|
|
24
|
|
|
MethodRegistry::config()->set('methods', [ |
|
25
|
|
|
BasicMathMethod::class, |
|
26
|
|
|
]); |
|
27
|
|
|
|
|
28
|
|
|
$this->generator = new SchemaGenerator(); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function testGetSchema() |
|
32
|
|
|
{ |
|
33
|
|
|
/** @var Member $member */ |
|
34
|
|
|
$member = $this->objFromFixture(Member::class, 'sally_smith'); |
|
35
|
|
|
$this->logInAs($member); |
|
36
|
|
|
|
|
37
|
|
|
$schema = $this->generator->getSchema($member); |
|
38
|
|
|
|
|
39
|
|
|
$this->assertArrayHasKey('registeredMethods', $schema); |
|
40
|
|
|
$this->assertNotEmpty($schema['registeredMethods']); |
|
41
|
|
|
$this->assertArrayHasKey('availableMethods', $schema); |
|
42
|
|
|
$this->assertNotEmpty($schema['availableMethods']); |
|
43
|
|
|
$this->assertArrayHasKey('defaultMethod', $schema); |
|
44
|
|
|
$this->assertNotEmpty($schema['defaultMethod']); |
|
45
|
|
|
|
|
46
|
|
|
$this->assertSame('backup-codes', $schema['registeredMethods'][0]['urlSegment']); |
|
47
|
|
|
$this->assertSame('basic-math', $schema['availableMethods'][0]['urlSegment']); |
|
48
|
|
|
$this->assertSame('backup-codes', $schema['defaultMethod']); |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|