. */ declare(strict_types=1); namespace Tests\Unit\Middleware; use FireflyIII\Http\Middleware\IsDemoUser; use FireflyIII\Http\Middleware\StartFireflySession; use Route; use Symfony\Component\HttpFoundation\Response; use Tests\TestCase; /** * Class IsDemoUserTest */ class IsDemoUserTest extends TestCase { /** * @covers \FireflyIII\Http\Middleware\IsDemoUser */ 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 */ public function testMiddlewareNotAuthenticated() { $this->withoutExceptionHandling(); $response = $this->get('/_test/is-demo'); $this->assertEquals(Response::HTTP_OK, $response->getStatusCode()); } /** * @covers \FireflyIII\Http\Middleware\IsDemoUser */ public function testMiddlewareIsDemoUser() { $this->be($this->demoUser()); $response = $this->get('/_test/is-demo'); $this->assertEquals(Response::HTTP_OK, $response->getStatusCode()); $response->assertSessionHas('info'); } /** * Set up test */ protected function setUp() { parent::setUp(); Route::middleware([StartFireflySession::class, IsDemoUser::class])->any( '/_test/is-demo', function () { return 'OK'; } ); } }