firefly-iii/tests/Unit/Middleware/IsDemoUserTest.php

82 lines
2.3 KiB
PHP
Raw Normal View History

2017-12-26 10:33:53 -06:00
<?php
/**
* IsDemoUserTest.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
2018-01-25 13:38:50 -06:00
namespace Tests\Unit\Middleware;
2017-12-26 10:33:53 -06:00
use FireflyIII\Http\Middleware\IsDemoUser;
2018-01-25 13:38:50 -06:00
use FireflyIII\Http\Middleware\StartFireflySession;
2017-12-26 10:33:53 -06:00
use Route;
use Symfony\Component\HttpFoundation\Response;
use Tests\TestCase;
use Log;
2017-12-26 10:33:53 -06:00
/**
* Class IsDemoUserTest
*/
class IsDemoUserTest extends TestCase
{
2018-09-02 13:27:26 -05:00
/**
* Set up test
*/
public function setUp(): void
{
parent::setUp();
Log::info(sprintf('Now in %s.', \get_class($this)));
2018-09-02 13:27:26 -05:00
Route::middleware([StartFireflySession::class, IsDemoUser::class])->any(
'/_test/is-demo', function () {
return 'OK';
}
);
}
2017-12-26 10:33:53 -06:00
/**
2018-03-03 10:16:47 -06:00
* @covers \FireflyIII\Http\Middleware\IsDemoUser
2017-12-26 10:33:53 -06:00
*/
2018-05-11 12:58:10 -05:00
public function testMiddlewareAuthenticated(): void
2017-12-26 10:33:53 -06:00
{
$this->be($this->user());
$response = $this->get('/_test/is-demo');
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
}
2017-12-29 02:05:35 -06:00
/**
2018-03-03 10:16:47 -06:00
* @covers \FireflyIII\Http\Middleware\IsDemoUser
2017-12-29 02:05:35 -06:00
*/
2018-08-06 12:14:30 -05:00
public function testMiddlewareIsDemoUser(): void
2017-12-29 02:05:35 -06:00
{
2018-08-06 12:14:30 -05:00
$this->be($this->demoUser());
2017-12-29 02:05:35 -06:00
$response = $this->get('/_test/is-demo');
2018-08-06 12:14:30 -05:00
$this->assertEquals(Response::HTTP_FOUND, $response->getStatusCode());
$response->assertSessionHas('info');
2017-12-29 02:05:35 -06:00
}
2018-03-03 10:16:47 -06:00
/**
* @covers \FireflyIII\Http\Middleware\IsDemoUser
*/
2018-08-06 12:14:30 -05:00
public function testMiddlewareNotAuthenticated(): void
2018-03-03 10:16:47 -06:00
{
$response = $this->get('/_test/is-demo');
2018-08-06 12:14:30 -05:00
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
2018-03-03 10:16:47 -06:00
}
2018-03-04 08:14:29 -06:00
}