Passed
Push — 4 ( e6ea10...17f4cc )
by Garion
08:03 queued 10s
created

TipTest::testGeneratesAccurateCustomSchema()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 10
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 17
rs 9.9332
1
<?php
2
3
namespace SilverStripe\Forms\Tests;
4
5
use InvalidArgumentException;
6
use SilverStripe\Dev\SapphireTest;
7
use SilverStripe\Forms\Tip;
8
9
class TipTest extends SapphireTest
10
{
11
    /**
12
     * Ensure the correct defaults are output in the schema
13
     */
14
    public function testGeneratesAccurateDefaultSchema()
15
    {
16
        $tip = new Tip('message');
17
18
        $schema = $tip->getTipSchema();
19
20
        $this->assertEquals(
21
            [
22
                'content' => 'message',
23
                'icon' => 'lamp',
24
                'importance' => 'normal',
25
            ],
26
            $schema
27
        );
28
    }
29
30
    /**
31
     * Ensure custom settings are output in the schema
32
     */
33
    public function testGeneratesAccurateCustomSchema()
34
    {
35
        $tip = new Tip(
36
            'message',
37
            Tip::IMPORTANCE_LEVELS['HIGH'],
38
            'page'
39
        );
40
41
        $schema = $tip->getTipSchema();
42
43
        $this->assertEquals(
44
            [
45
                'content' => 'message',
46
                'icon' => 'page',
47
                'importance' => 'high',
48
            ],
49
            $schema
50
        );
51
    }
52
53
    /**
54
     * Ensure passing an invalid importance level to the constructor fails
55
     *
56
     * @expectedException InvalidArgumentException
57
     * @expectedExceptionMessage Provided importance level must be defined in Tip::IMPORTANCE_LEVELS
58
     */
59
    public function testInvalidImportanceLevelInConstructorCausesException()
60
    {
61
        $tip = new Tip('message', 'arbitrary-importance');
0 ignored issues
show
Unused Code introduced by
The assignment to $tip is dead and can be removed.
Loading history...
62
    }
63
64
    /**
65
     * Ensure setting an invalid importance level fails
66
     *
67
     * @expectedException InvalidArgumentException
68
     * @expectedExceptionMessage Provided importance level must be defined in Tip::IMPORTANCE_LEVELS
69
     */
70
    public function testInvalidImportanceLevelInSetterCausesException()
71
    {
72
        $tip = new Tip('message');
73
74
        $tip->setImportanceLevel('arbitrary-importance');
75
    }
76
}
77