47 lines
1.5 KiB
PHP
47 lines
1.5 KiB
PHP
<?php
|
|
|
|
use App\Http\Controllers\ModalController;
|
|
use App\User;
|
|
use Symfony\Component\HttpKernel\Exception\HttpException;
|
|
|
|
function invokeDhlModalAuth(?User $user): void
|
|
{
|
|
if ($user !== null) {
|
|
Auth::shouldReceive('user')->andReturn($user);
|
|
} else {
|
|
Auth::shouldReceive('user')->andReturnNull();
|
|
}
|
|
|
|
$controller = new ModalController;
|
|
$method = (new ReflectionClass(ModalController::class))->getMethod('authorizeDhlShipmentModal');
|
|
$method->setAccessible(true);
|
|
$method->invoke($controller);
|
|
}
|
|
|
|
afterEach(function () {
|
|
Mockery::close();
|
|
});
|
|
|
|
it('rejects guests for the DHL shipment modal', function () {
|
|
invokeDhlModalAuth(null);
|
|
})->throws(HttpException::class, 'DHL shipment modal is only available for admin users.');
|
|
|
|
it('rejects VIP users (admin == 1) for the DHL shipment modal', function () {
|
|
$vip = (new User)->forceFill(['admin' => 1]);
|
|
|
|
invokeDhlModalAuth($vip);
|
|
})->throws(HttpException::class, 'DHL shipment modal is only available for admin users.');
|
|
|
|
it('rejects regular consultants for the DHL shipment modal', function () {
|
|
$consultant = (new User)->forceFill(['admin' => 0]);
|
|
|
|
invokeDhlModalAuth($consultant);
|
|
})->throws(HttpException::class, 'DHL shipment modal is only available for admin users.');
|
|
|
|
it('allows real admin users (admin >= 2) for the DHL shipment modal', function () {
|
|
$admin = (new User)->forceFill(['admin' => 2]);
|
|
|
|
invokeDhlModalAuth($admin);
|
|
|
|
expect(true)->toBeTrue();
|
|
});
|