@@ -143,4 +143,59 @@ public function testHandle_IsLoggedInWithAbility_ShouldNotAbort()
143
143
$ this ->assertNull ($ middleware ->handle ($ this ->request , function () {
144
144
}, 'admin|user ' , 'edit-users|update-users ' , 'TeamA ' , 'require_all|guard:api ' ));
145
145
}
146
+
147
+
148
+ public function testHandle_IsLoggedInWithAbilityAndMultipleGuards_ShouldNotAbort ()
149
+ {
150
+ /*
151
+ |------------------------------------------------------------
152
+ | Set
153
+ |------------------------------------------------------------
154
+ */
155
+ $ guard2 = m::mock ('Illuminate\Contracts\Auth\Guard ' );
156
+ $ user = m::mock ('Laratrust\Tests\Models\User ' )->makePartial ();
157
+ $ middleware = new LaratrustAbility ($ this ->guard );
158
+
159
+ /*
160
+ |------------------------------------------------------------
161
+ | Expectation
162
+ |------------------------------------------------------------
163
+ */
164
+ Auth::shouldReceive ('guard ' )->with ('api ' )->andReturn ($ this ->guard );
165
+ Auth::shouldReceive ('guard ' )->with ('web ' )->andReturn ($ guard2 );
166
+ $ this ->guard ->shouldReceive ('guest ' )->andReturn (true );
167
+ $ guard2 ->shouldReceive ('guest ' )->andReturn (false );
168
+ $ guard2 ->shouldReceive ('user ' )->andReturn ($ user );
169
+ $ user ->shouldReceive ('ability ' )
170
+ ->with (
171
+ ['admin ' , 'user ' ],
172
+ ['edit-users ' , 'update-users ' ],
173
+ m::anyOf (null , 'TeamA ' ),
174
+ m::anyOf (['validate_all ' => true ], ['validate_all ' => false ])
175
+ )
176
+ ->andReturn (true );
177
+
178
+ /*
179
+ |------------------------------------------------------------
180
+ | Assertion
181
+ |------------------------------------------------------------
182
+ */
183
+ $ this ->assertNull ($ middleware ->handle ($ this ->request , function () {
184
+ }, 'admin|user ' , 'edit-users|update-users ' ));
185
+
186
+ $ this ->assertNull ($ middleware ->handle ($ this ->request , function () {
187
+ }, 'admin|user ' , 'edit-users|update-users ' , 'guard:api|guard:web ' ));
188
+
189
+ $ this ->assertNull ($ middleware ->handle ($ this ->request , function () {
190
+ }, 'admin|user ' , 'edit-users|update-users ' , 'require_all ' ));
191
+
192
+ $ this ->assertNull ($ middleware ->handle ($ this ->request , function () {
193
+ }, 'admin|user ' , 'edit-users|update-users ' , 'guard:api|guard:web|require_all ' ));
194
+
195
+ $ this ->assertNull ($ middleware ->handle ($ this ->request , function () {
196
+ }, 'admin|user ' , 'edit-users|update-users ' , 'TeamA ' , 'require_all ' ));
197
+
198
+ $ this ->assertNull ($ middleware ->handle ($ this ->request , function () {
199
+ }, 'admin|user ' , 'edit-users|update-users ' , 'TeamA ' , 'require_all|guard:api|guard:web ' ));
200
+ }
146
201
}
0 commit comments