Passed
Push — master ( 33a29d...4282cd )
by Robbie
02:17 queued 25s
created

MethodTest::testGetURLSegment()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
3
namespace SilverStripe\WebAuthn\Tests;
4
5
use SilverStripe\Control\Director;
6
use SilverStripe\Core\Config\Config;
7
use SilverStripe\Dev\SapphireTest;
8
use SilverStripe\View\Requirements;
9
use SilverStripe\WebAuthn\Method;
10
use SilverStripe\WebAuthn\RegisterHandler;
11
use SilverStripe\WebAuthn\VerifyHandler;
12
13
class MethodTest extends SapphireTest
14
{
15
    public function testGetURLSegment()
16
    {
17
        $method = new Method();
18
        $this->assertSame('web-authn', $method->getURLSegment());
19
    }
20
21
    public function testGetVerifyHandler()
22
    {
23
        $method = new Method();
24
        $this->assertInstanceOf(VerifyHandler::class, $method->getVerifyHandler());
25
    }
26
27
    public function testGetRegisterHandler()
28
    {
29
        $method = new Method();
30
        $this->assertInstanceOf(RegisterHandler::class, $method->getRegisterHandler());
31
    }
32
33
    public function testGetThumbnail()
34
    {
35
        $method = new Method();
36
        $this->assertContains('images/u2f.svg', $method->getThumbnail());
37
    }
38
39
    public function testApplyRequirements()
40
    {
41
        Requirements::clear();
42
        $method = new Method();
43
        $method->applyRequirements();
44
45
        $this->assertCount(1, Requirements::backend()->getJavascript());
46
        $this->assertCount(1, Requirements::backend()->getCSS());
47
    }
48
49
    public function testIsAvailableUnderHttps()
50
    {
51
        $method = new Method();
52
        Director::config()->set('alternate_base_url', 'https://mywebsite.com');
53
        $this->assertTrue($method->isAvailable());
54
    }
55
56
    public function testIsNotAvailableUnderHttp()
57
    {
58
        $method = new Method();
59
        Director::config()->set('alternate_base_url', 'http://mywebsite.com');
60
        $this->assertFalse($method->isAvailable());
61
    }
62
63
    public function testGetUnavailableMessage()
64
    {
65
        $method = new Method();
66
        $this->assertContains('can only be used over HTTPS', $method->getUnavailableMessage());
67
    }
68
}
69