-
Notifications
You must be signed in to change notification settings - Fork 91
Expand file tree
/
Copy pathMessageTest.php
More file actions
100 lines (81 loc) · 3.42 KB
/
Copy pathMessageTest.php
File metadata and controls
100 lines (81 loc) · 3.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
use PHPUnit\Framework\TestCase;
class MessageTest extends TestCase
{
public function testMessageConstructor()
{
$message = new \Krucas\Notification\Message('error', 'test message', false, ':type: :message', 4);
$this->assertInstanceOf('Krucas\Notification\Message', $message);
$this->assertEquals('error', $message->getType());
$this->assertEquals('test message', $message->getMessage());
$this->assertEquals(':type: :message', $message->getFormat());
$this->assertFalse($message->isFlash());
$this->assertEquals(4, $message->getPosition());
}
public function testMethodChaining()
{
$message = new \Krucas\Notification\Message();
$this->assertInstanceOf('Krucas\Notification\Message', $message);
$this->assertNull($message->getType());
$this->assertNull($message->getMessage());
$this->assertNull($message->getFormat());
$this->assertTrue($message->isFlash());
$this->assertNull($message->getPosition());
$message->setFlash(false)
->setFormat('Test: :message')
->setType('warning')
->setMessage('test')
->setPosition(5);
$this->assertEquals('warning', $message->getType());
$this->assertEquals('test', $message->getMessage());
$this->assertEquals('Test: :message', $message->getFormat());
$this->assertFalse($message->isFlash());
$this->assertEquals(5, $message->getPosition());
}
public function testToStringMethod()
{
$message = new \Krucas\Notification\Message('error', 'test message', false, ':type: :message');
$this->assertEquals('error: test message', (string)$message);
}
public function testMessageRendering()
{
$message = new \Krucas\Notification\Message('error', 'test message', false, ':type: :message');
$this->assertEquals('error: test message', $message->render());
}
public function testMessageToArray()
{
$message = new \Krucas\Notification\Message('error', 'test message', false, ':type: :message');
$this->assertEquals(array(
'message' => 'test message',
'format' => ':type: :message',
'type' => 'error',
'flash' => false,
'position' => null
), $message->toArray());
}
public function testMessageToJson()
{
$message = new \Krucas\Notification\Message('error', 'test message', false, ':type: :message');
$this->assertEquals(
'{"message":"test message","format":":type: :message","type":"error","flash":false,"position":null}',
$message->toJson()
);
}
public function testMethodsShortcuts()
{
$message = new \Krucas\Notification\Message();
$this->assertNull($message->getMessage());
$this->assertNull($message->getFormat());
$this->assertNull($message->getPosition());
$this->assertTrue($message->isFlash());
$message->message('test')->format(':message')->position(5);
$this->assertEquals('test', $message->getMessage());
$this->assertEquals(':message', $message->getFormat());
$this->assertEquals(5, $message->getPosition());
$this->assertTrue($message->isFlash());
$message->instant();
$this->assertFalse($message->isFlash());
$message->flash();
$this->assertTrue($message->isFlash());
}
}