Files

63 lines
1.7 KiB
PHP
Raw Permalink Normal View History

2018-01-18 21:41:45 -06:00
<?php
2024-03-12 22:39:16 -04:00
namespace App\Tests\Unit\Http\Middleware\Api\Application;
2018-01-18 21:41:45 -06:00
2025-09-24 13:34:19 +02:00
use App\Http\Middleware\Api\Application\AuthenticateApplicationUser;
2024-03-12 22:39:16 -04:00
use App\Tests\Unit\Http\Middleware\MiddlewareTestCase;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
2018-01-18 21:41:45 -06:00
class AuthenticateUserTest extends MiddlewareTestCase
{
/**
* Test that no user defined results in an access denied exception.
*/
public function test_no_user_defined(): void
2018-01-18 21:41:45 -06:00
{
$this->expectException(AccessDeniedHttpException::class);
2018-01-18 21:41:45 -06:00
$this->setRequestUserModel(null);
$this->getMiddleware()->handle($this->request, $this->getClosureAssertions());
}
/**
* Test that a non-admin user results in an exception.
2018-01-18 21:41:45 -06:00
*/
public function test_non_admin_user(): void
2018-01-18 21:41:45 -06:00
{
$this->expectException(AccessDeniedHttpException::class);
$this->generateRequestUserModel(false, false);
2018-01-18 21:41:45 -06:00
$this->getMiddleware()->handle($this->request, $this->getClosureAssertions());
}
/**
* Test that an admin user continues though the middleware.
*/
public function test_admin_user(): void
2018-01-18 21:41:45 -06:00
{
$this->generateRequestUserModel(true, false);
$this->getMiddleware()->handle($this->request, $this->getClosureAssertions());
}
/**
* Test that a root admin user continues though the middleware.
*/
public function test_root_admin_user(): void
{
$this->generateRequestUserModel(true, true);
2018-01-18 21:41:45 -06:00
$this->getMiddleware()->handle($this->request, $this->getClosureAssertions());
}
/**
* Return an instance of the middleware for testing.
*/
private function getMiddleware(): AuthenticateApplicationUser
2018-01-18 21:41:45 -06:00
{
2021-01-23 12:33:34 -08:00
return new AuthenticateApplicationUser();
2018-01-18 21:41:45 -06:00
}
}