-
-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathAlertTest.php
More file actions
130 lines (102 loc) · 3.45 KB
/
AlertTest.php
File metadata and controls
130 lines (102 loc) · 3.45 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
namespace Styde\Html\Tests;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\View;
use Styde\Html\Alert\Middleware as AlertMiddleware;
use Styde\Html\Facades\Alert;
class AlertTest extends TestCase
{
/** @test */
function it_renders_new_messages()
{
Alert::message('This is a message', 'info');
$this->assertTemplateMatches('alert/alert', Alert::render());
}
/** @test */
function it_uses_magic_methods()
{
Alert::success('Success!');
Alert::info('Some information');
$this->assertTemplateMatches('alert/magic', Alert::render());
}
/** @test */
function it_chains_methods_to_build_complex_alert_messages()
{
Alert::info('Your account is about to expire')
->details('A lot of knowledge still waits for you:')
->items([
'Laravel courses',
'OOP classes',
'Access to real projects',
'Support',
'And more'
])
->button('Renew now!', '#', 'primary')
->button('Take me to your leader', 'http://google.com', 'info');
$this->assertTemplateMatches('alert/complex', Alert::render());
}
/** @test */
function can_customize_the_template()
{
View::addLocation(__DIR__.'/views');
Alert::message('This is a message', 'info');
$this->assertTemplateMatches('alert/custom-template', Alert::render('custom-templates.alert'));
}
/** @test */
function can_customize_the_themes_folder_name_in_resources_views()
{
View::addLocation(__DIR__.'/views');
Config::set('html.custom', 'custom-folder');
Alert::message('This is a message', 'info');
$this->assertTemplateMatches('alert/custom-folder-in-resources-views', Alert::render());
}
/** @test */
function it_renders_a_view_inside_the_alert()
{
View::addLocation(__DIR__.'/views');
Alert::info()->view('custom-templates.partial-for-alert');
$this->assertTemplateMatches('alert/with-partial-view', Alert::render());
}
/** @test */
function it_returns_raw_messages()
{
Alert::info('This is a info');
Alert::message('This is a message');
$this->assertEquals([
[
'message' => 'This is a info',
'type' => 'info'
],
[
'message' => 'This is a message',
'type' => 'success'
]
], Alert::toArray());
}
/** @test */
function it_returns_empty_when_there_are_any_alert_messages()
{
$this->assertEmpty(Alert::render());
}
/** @test */
function it_persist_the_alert_messages()
{
Alert::success('Success!');
$middleware = new AlertMiddleware($this->app->get('alert'));
$this->assertNull($this->app['session.store']->get('styde/alerts'));
$middleware->handle(new Request, function () {
return new Response;
});
$session = $this->app['session.store']->get('styde/alerts');
$this->assertNotNull($session);
$this->assertContains(['message' => 'Success!', 'type' => 'success'], $session);
}
/** @test */
function it_has_a_helper()
{
alert('This is a message', 'info');
$this->assertTemplateMatches('alert/alert', Alert::render());
}
}