. */ declare(strict_types=1); namespace Tests\Unit\Helpers; use FireflyIII\Http\Middleware\IsDemoUser; use Route; use Symfony\Component\HttpFoundation\Response; use Tests\TestCase; /** * Class IsDemoUserTest */ class IsDemoUserTest extends TestCase { /** * @covers \FireflyIII\Http\Middleware\IsDemoUser::handle */ public function testMiddlewareNotAuthenticated() { $this->withoutExceptionHandling(); $response = $this->get('/_test/is-demo'); $this->assertEquals(Response::HTTP_OK, $response->getStatusCode()); } /** * @covers \FireflyIII\Http\Middleware\IsDemoUser::handle */ public function testMiddlewareAuthenticated() { $this->withoutExceptionHandling(); $this->be($this->user()); $response = $this->get('/_test/is-demo'); $this->assertEquals(Response::HTTP_OK, $response->getStatusCode()); } /** * @covers \FireflyIII\Http\Middleware\IsDemoUser::handle */ public function testMiddlewareDemoUser() { $this->withoutExceptionHandling(); $this->be($this->demoUser()); $response = $this->get('/_test/is-demo'); $this->assertEquals(Response::HTTP_FOUND, $response->getStatusCode()); $response->assertSessionHas('warning', strval(trans('firefly.not_available_demo_user'))); $response->assertRedirect(route('index')); } /** * Set up test */ protected function setUp() { parent::setUp(); Route::middleware(IsDemoUser::class)->any( '/_test/is-demo', function () { return 'OK'; } ); } }