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