1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverStripe\MFA\Tests\State; |
4
|
|
|
|
5
|
|
|
use PHPUnit_Framework_MockObject_MockObject; |
6
|
|
|
use SilverStripe\Dev\SapphireTest; |
7
|
|
|
use SilverStripe\MFA\Method\Handler\RegisterHandlerInterface; |
8
|
|
|
use SilverStripe\MFA\Method\MethodInterface; |
9
|
|
|
use SilverStripe\MFA\State\AvailableMethodDetails; |
10
|
|
|
|
11
|
|
|
class AvailableMethodDetailsTest extends SapphireTest |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var MethodInterface|PHPUnit_Framework_MockObject_MockObject |
15
|
|
|
*/ |
16
|
|
|
protected $method; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var AvailableMethodDetails |
20
|
|
|
*/ |
21
|
|
|
protected $details; |
22
|
|
|
|
23
|
|
|
protected function setUp() |
24
|
|
|
{ |
25
|
|
|
parent::setUp(); |
26
|
|
|
|
27
|
|
|
$this->method = $this->createMock(MethodInterface::class); |
28
|
|
|
$this->method->method('getRegisterHandler')->willReturn( |
29
|
|
|
$this->createMock(RegisterHandlerInterface::class) |
30
|
|
|
); |
31
|
|
|
|
32
|
|
|
$this->details = new AvailableMethodDetails($this->method); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testGetDescription() |
36
|
|
|
{ |
37
|
|
|
$this->method->getRegisterHandler()->expects($this->once())->method('getDescription')->willReturn('foo'); |
38
|
|
|
$this->assertSame('foo', $this->details->getDescription()); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testGetName() |
42
|
|
|
{ |
43
|
|
|
$this->method->getRegisterHandler()->expects($this->once())->method('getName')->willReturn('Backup Codes'); |
44
|
|
|
$this->assertSame('Backup Codes', $this->details->getName()); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testJsonSerialize() |
48
|
|
|
{ |
49
|
|
|
$this->method->getRegisterHandler()->expects($this->once())->method('getName')->willReturn('Backup Codes'); |
50
|
|
|
$result = json_encode($this->details); |
51
|
|
|
$this->assertContains('Backup Codes', $result); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function testGetSupportLink() |
55
|
|
|
{ |
56
|
|
|
$this->method->getRegisterHandler()->expects($this->once())->method('getSupportLink')->willReturn('google.com'); |
57
|
|
|
$this->assertSame('google.com', $this->details->getSupportLink()); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function testGetURLSegment() |
61
|
|
|
{ |
62
|
|
|
$this->method->expects($this->once())->method('getURLSegment')->willReturn('backup-codes'); |
63
|
|
|
$this->assertSame('backup-codes', $this->details->getURLSegment()); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function testGetThumbnail() |
67
|
|
|
{ |
68
|
|
|
$this->method->expects($this->once())->method('getThumbnail')->willReturn('clipper'); |
69
|
|
|
$this->assertSame('clipper', $this->details->getThumbnail()); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function testIsAvailable() |
73
|
|
|
{ |
74
|
|
|
$this->method->getRegisterHandler() |
75
|
|
|
->expects($this->exactly(2)) |
76
|
|
|
->method('isAvailable') |
77
|
|
|
->willReturnOnConsecutiveCalls(false, true); |
78
|
|
|
|
79
|
|
|
$this->assertFalse($this->details->isAvailable()); |
80
|
|
|
$this->assertTrue($this->details->isAvailable()); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function testGetUnavailableMesssage() |
84
|
|
|
{ |
85
|
|
|
$this->method->getRegisterHandler() |
86
|
|
|
->expects($this->once()) |
87
|
|
|
->method('getUnavailableMessage') |
88
|
|
|
->willReturn('We don\'t like it.'); |
89
|
|
|
$this->assertSame('We don\'t like it.', $this->details->getUnavailableMessage()); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|