-
-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathHtmlAccessTest.php
More file actions
161 lines (115 loc) · 4.08 KB
/
HtmlAccessTest.php
File metadata and controls
161 lines (115 loc) · 4.08 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<?php
namespace Styde\Html\Tests;
use Styde\Html\Facades\Html;
use Illuminate\Support\Facades\Gate;
class HtmlAccessTest extends TestCase
{
/** @test */
function it_only_renders_the_tag_if_the_user_has_the_expected_role()
{
$tag = Html::tag('p', 'This is the content.');
$this->assertNull($tag->ifIs('admin')->render());
$this->actingAs($this->aUser());
$this->assertNull($tag->ifIs('admin')->render());
$this->actingAs($this->anAdmin());
$this->assertNotNull($tag->ifIs('admin')->render());
}
/** @test */
function it_only_renders_the_void_tag_if_the_user_has_the_expected_role()
{
$tag = Html::tag('hr');
$this->assertNull($tag->ifIs('admin')->render());
$this->actingAs($this->aUser());
$this->assertNull($tag->ifIs('admin')->render());
$this->actingAs($this->anAdmin());
$this->assertNotNull($tag->ifIs('admin')->render());
}
/** @test */
function it_only_renders_the_tag_if_the_user_is_not_guest()
{
$tag = Html::tag('p', 'This is the content.');
$this->assertNotNull($tag->ifGuest()->render());
$this->actingAs($this->aUser());
$this->assertNull($tag->ifGuest()->render());
}
/** @test */
function it_only_renders_the_void_tag_if_the_user_is_not_guest()
{
$tag = Html::tag('br');
$this->assertNotNull($tag->ifGuest()->render());
$this->actingAs($this->aUser());
$this->assertNull($tag->ifGuest()->render());
}
/** @test */
function if_only_renders_the_tag_if_user_is_logged_in()
{
$tag = Html::tag('p', 'This is the content.');
$this->assertNull($tag->ifAuth()->render());
$this->actingAs($this->aUser());
$this->assertNotNull($tag->ifAuth()->render());
}
/** @test */
function if_only_renders_the_void_tag_if_user_is_logged_in()
{
$tag = Html::tag('br');
$this->assertNull($tag->ifAuth()->render());
$this->actingAs($this->aUser());
$this->assertNotNull($tag->ifAuth()->render());
}
/** @test */
function it_only_renders_the_tag_if_the_user_has_the_given_ability()
{
$this->actingAs($this->aUser());
Gate::define('edit-all', function ($user) {
return false;
});
Gate::define('edit-mine', function ($user) {
return true;
});
$tag = Html::tag('p', 'This is the content.');
$this->assertNull($tag->ifCan('edit-all')->render());
$this->assertNotNull($tag->ifCan('edit-mine')->render());
}
/** @test */
function it_only_renders_the_tag_if_the_user_does_not_have_the_given_ability()
{
$this->actingAs($this->aUser());
Gate::define('edit-all', function ($user) {
return false;
});
Gate::define('edit-mine', function ($user) {
return true;
});
$tag = Html::tag('p', 'This is the content.');
$this->assertNotNull($tag->ifCannot('edit-all')->render());
$this->assertNull($tag->ifCannot('edit-mine')->render());
}
/** @test */
function it_only_renders_the_void_tag_if_the_user_has_the_given_ability()
{
$this->actingAs($this->aUser());
Gate::define('edit-all', function ($user) {
return false;
});
Gate::define('edit-mine', function ($user) {
return true;
});
$tag = Html::tag('br');
$this->assertNull($tag->ifCan('edit-all')->render());
$this->assertNotNull($tag->ifCan('edit-mine')->render());
}
/** @test */
function it_only_renders_the_void_tag_if_the_user_does_not_have_the_given_ability()
{
$this->actingAs($this->aUser());
Gate::define('edit-all', function ($user) {
return false;
});
Gate::define('edit-mine', function ($user) {
return true;
});
$tag = Html::tag('br');
$this->assertNotNull($tag->ifCannot('edit-all')->render());
$this->assertNull($tag->ifCannot('edit-mine')->render());
}
}