-
Notifications
You must be signed in to change notification settings - Fork 37
/
IgnoreTest.php
224 lines (162 loc) · 6.92 KB
/
IgnoreTest.php
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<?php
namespace Imanghafoori\HeyManTests;
use Illuminate\Support\Facades\Route;
use Imanghafoori\HeyMan\Facades\HeyMan;
use Imanghafoori\HeyMan\StartGuarding;
use Imanghafoori\HeyManTests\Stubs\HomeController;
use Imanghafoori\MakeSure\Facades\MakeSure;
class IgnoreTest extends TestCase
{
public function testUrlIsAuthorized()
{
Route::get('/welcome', HomeController::class.'@index');
HeyMan::whenYouVisitUrl('/welco*')->always()->weDenyAccess();
HeyMan::whenYouVisitUrl('welcome1')->thisValueShouldAllow(true)->otherwise()->weDenyAccess();
HeyMan::turnOff()->routeChecks();
app(StartGuarding::class)->start();
$this->get('welcome')->assertStatus(200);
}
public function testUrlIsAuthorized657()
{
Route::get('/welcome', HomeController::class.'@index');
HeyMan::whenYouVisitUrl(['welcome_', 'welcome'])->always()->weDenyAccess();
HeyMan::whenYouVisitUrl('welcome1')->thisValueShouldAllow(true)->otherwise()->weDenyAccess();
HeyMan::turnOff()->routeChecks();
app(StartGuarding::class)->start();
$this->get('welcome')->assertStatus(200);
}
public function testUrlIsAuthorized563()
{
Route::get('/welcome', HomeController::class.'@index');
HeyMan::whenYouVisitUrl('welcome_', 'welcome')->always()->weDenyAccess();
HeyMan::whenYouVisitUrl('welcome1')->thisValueShouldAllow(true)->otherwise()->weDenyAccess();
HeyMan::turnOff()->routeChecks();
app(StartGuarding::class)->start();
$this->get('welcome')->assertStatus(200);
}
public function testUrlIsAuthorized566()
{
Route::get('/welcome', HomeController::class.'@index');
HeyMan::whenYouVisitUrl('welcome_', 'welcome')->thisValueShouldAllow(true)->otherwise()->weDenyAccess();
HeyMan::whenYouVisitUrl('welcome1')->thisValueShouldAllow(true)->otherwise()->weDenyAccess();
HeyMan::turnOff()->routeChecks();
app(StartGuarding::class)->start();
$this->get('welcome')->assertStatus(200);
}
public function testRouteNameIsAuthorized1()
{
Route::get('/welcome', HomeController::class.'@index')->name('welcome.name');
HeyMan::whenYouHitRouteName('welcome.name')->always()->weDenyAccess();
HeyMan::turnOff()->routeChecks();
app(StartGuarding::class)->start();
$this->get('welcome')->assertStatus(200);
}
public function testRouteNameIsMatchWithPattern()
{
Route::get('/welcome', HomeController::class.'@index')->name('welcome.name');
HeyMan::whenYouHitRouteName('welcome.*')->always()->weDenyAccess();
HeyMan::turnOff()->routeChecks();
app(StartGuarding::class)->start();
$this->get('welcome')->assertStatus(200);
}
public function testControllerActionIsAuthorized()
{
Route::get('/welcome', HomeController::class.'@index');
HeyMan::whenYouCallAction(HomeController::class.'@index')->always()->weDenyAccess();
HeyMan::turnOff()->routeChecks();
app(StartGuarding::class)->start();
$this->get('welcome')->assertStatus(200);
}
public function testControllerActionIsAuthorized878()
{
Route::get('/welcome', HomeController::class.'@index');
HeyMan::whenYouCallAction(HomeController::class.'@index')->always()->weDenyAccess();
HeyMan::turnOff()->routeChecks();
app(StartGuarding::class)->start();
$this->get('welcome')->assertStatus(200);
}
public function testFetchingModelsIsAuthorized_Ignorance()
{
HeyMan::whenYouFetch('\App\User')->always()->weDenyAccess();
HeyMan::turnOff()->eloquentChecks();
event('eloquent.retrieved: App\User');
$this->assertTrue(true);
}
public function testEventAuthorized_Ignorance()
{
HeyMan::whenEventHappens('hey')->always()->weDenyAccess();
app(StartGuarding::class)->start();
HeyMan::turnOff()->eventChecks();
event('hey');
$this->assertTrue(true);
}
public function testFetchingModelsIsAuthorized_closure_Ignorance()
{
HeyMan::whenYouFetch('\App\User')->always()->weDenyAccess();
HeyMan::whenYouCreate('\App\User2')->always()->weDenyAccess();
config()->set('heyman_ignore_eloquent', '2222');
HeyMan::turnOff()->eloquentChecks(function () {
event('eloquent.retrieved: App\User');
});
$this->assertEquals(config('heyman_ignore_eloquent'), '2222');
}
public function testViewIsAuthorized21134()
{
HeyMan::whenYouMakeView(['welcome', 'errors.503'])
->thisValueShouldAllow(false)
->otherwise()
->weDenyAccess();
app(StartGuarding::class)->start();
HeyMan::turnOff()->viewChecks();
view('welcome');
$this->assertTrue(true);
}
public function testViewIsAuthorized2134()
{
HeyMan::whenYouMakeView(['welcome', 'errors.503'])
->thisValueShouldAllow(false)
->otherwise()
->weDenyAccess();
app(StartGuarding::class)->start();
HeyMan::turnOff()->allChecks();
view('welcome');
$this->assertTrue(true);
}
public function test_check_would_be_turned_On_again()
{
Route::put('put', function () {
});
HeyMan::whenYouSendPut('put')->always()->weDenyAccess();
HeyMan::turnOff()->allChecks();
HeyMan::turnOn()->allChecks();
app(StartGuarding::class)->start();
MakeSure::about($this)->sendingPutRequest('put')->isRespondedWith()->statusCode(403);
}
public function test_it_ignores_validation()
{
Route::get('/welcome', HomeController::class.'@index')->name('welcome.name');
HeyMan::whenYouVisitUrl('welcome')->yourRequestShouldBeValid(['name' => 'required']);
HeyMan::turnOff()->validationChecks();
app(StartGuarding::class)->start();
MakeSure::about($this)->sendingGetRequest('welcome')->isRespondedWith()->statusCode(200);
}
public function test_it_ignores_validation2()
{
Route::get('/welcome', HomeController::class.'@index')->name('welcome.name');
HeyMan::whenYouVisitUrl('welcome')
->yourRequestShouldBeValid(['name' => 'required'])
->otherwise()
->response()->json(['oh oh'], 400);
HeyMan::turnOff()->validationChecks();
app(StartGuarding::class)->start();
MakeSure::about($this)->sendingGetRequest('welcome')->isRespondedWith()->statusCode(200);
}
public function test_it_ignores_validation3()
{
Route::get('/welcome', HomeController::class.'@index')->name('welcome.name');
HeyMan::whenYouVisitUrl('welcome')->yourRequestShouldBeValid(['name' => 'required']);
HeyMan::turnOff()->allChecks();
app(StartGuarding::class)->start();
MakeSure::about($this)->sendingGetRequest('welcome')->isRespondedWith()->statusCode(200);
}
}