Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Clean up sandstorm tests.
James Colef22b54de3083
diff --git a/resources/views/test/test.twig b/resources/views/test/test.twigindex d2ab74c2d7..05aea8e64e 100644--- a/resources/views/test/test.twig+++ b/resources/views/test/test.twig@@ -1,2 +1,3 @@list-length: {{ listLength }}sandstorm-anon: {% if SANDSTORM_ANON %}true{% else %}false{% endif %}+user-email: {{ Auth.user.email }}diff --git a/tests/Unit/Middleware/SandstormTest.php b/tests/Unit/Middleware/SandstormTest.phpindex 47ff386cd5..a367e101e9 100644--- a/tests/Unit/Middleware/SandstormTest.php+++ b/tests/Unit/Middleware/SandstormTest.php@@ -24,11 +24,11 @@ declare(strict_types=1);namespace Tests\Unit\Middleware;use FireflyIII\Http\Middleware\Sandstorm;-use FireflyIII\Models\Role;use FireflyIII\Repositories\User\UserRepositoryInterface;use Route;use Symfony\Component\HttpFoundation\Response;use Tests\TestCase;+use Mockery;/*** Class RangeTest@@ -38,129 +38,19 @@ class SandstormTest extends TestCase/*** @covers \FireflyIII\Http\Middleware\Sandstorm::handle*/- public function testMiddlewareAnonEmpty(): void+ public function testMiddlewareBasic(): void{putenv('SANDSTORM=1');$repository = $this->mock(UserRepositoryInterface::class);- $repository->shouldReceive('count')->once()->andReturn(0);+ $repository->shouldReceive('findByEmail')->withArgs(['anonymous@firefly'])->once()->andReturn($this->user());+ // single user, checks if user is admin+ $repository->shouldReceive('count')->andReturn(1);+ $repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->once();+ $repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->once();+ $repository->shouldReceive('attachRole')->withArgs([Mockery::any(), 'owner'])->once();$response = $this->get('/_test/sandstorm');- $this->assertEquals(Response::HTTP_INTERNAL_SERVER_ERROR, $response->getStatusCode());- $response->assertSee('The first visit to a new Firefly III administration cannot be by a guest user.');-- putenv('SANDSTORM=0');- }-- /**- * @covers \FireflyIII\Http\Middleware\Sandstorm::handle- */- public function testMiddlewareAnonLoggedIn(): void- {- putenv('SANDSTORM=1');-- $this->be($this->user());- $response = $this->get('/_test/sandstorm');- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());- $response->assertSee('sandstorm-anon: true');-- putenv('SANDSTORM=0');- }-- /**- * @covers \FireflyIII\Http\Middleware\Sandstorm::handle- */- public function testMiddlewareAnonUser(): void- {- putenv('SANDSTORM=1');-- $repository = $this->mock(UserRepositoryInterface::class);- $repository->shouldReceive('count')->twice()->andReturn(1);- $repository->shouldReceive('hasRole')->andReturn(true);-- $response = $this->get('/_test/sandstorm');- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());- $response->assertSee('sandstorm-anon: true');-- putenv('SANDSTORM=0');- }-- /**- * @covers \FireflyIII\Http\Middleware\Sandstorm::handle- */- public function testMiddlewareLoggedIn(): void- {- putenv('SANDSTORM=1');-- $this->be($this->user());- $response = $this->get('/_test/sandstorm', ['X-Sandstorm-User-Id' => 'abcd']);- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());- $response->assertSee('sandstorm-anon: false');-- putenv('SANDSTORM=0');- }-- /**- * @covers \FireflyIII\Http\Middleware\Sandstorm::handle- */- public function testMiddlewareMultiUser(): void- {- putenv('SANDSTORM=1');-- $repository = $this->mock(UserRepositoryInterface::class);- $repository->shouldReceive('count')->once()->andReturn(2);-- $response = $this->get('/_test/sandstorm');- $this->assertEquals(Response::HTTP_INTERNAL_SERVER_ERROR, $response->getStatusCode());- $response->assertSee('Your Firefly III installation has more than one user, which is weird.');-- putenv('SANDSTORM=0');- }-- /**- * @covers \FireflyIII\Http\Middleware\Sandstorm::handle- */- public function testMiddlewareNoUser(): void- {- putenv('SANDSTORM=1');-- $repository = $this->mock(UserRepositoryInterface::class);- $repository->shouldReceive('count')->twice()->andReturn(0);- $repository->shouldReceive('store')->once()->andReturn($this->user());- $repository->shouldReceive('attachRole')->once()->andReturn(true);- //$repository->shouldReceive('getRole')->once()->andReturn(new Role);- $repository->shouldReceive('hasRole')->andReturn(false);-- $response = $this->get('/_test/sandstorm', ['X-Sandstorm-User-Id' => 'abcd']);- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());- $response->assertSee('sandstorm-anon: false');-- putenv('SANDSTORM=0');- }-- /**- * @covers \FireflyIII\Http\Middleware\Sandstorm::handle- */- public function testMiddlewareNotSandstorm(): void- {- $this->withoutExceptionHandling();- $response = $this->get('/_test/sandstorm');- $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());- }-- /**- * @covers \FireflyIII\Http\Middleware\Sandstorm::handle- */- public function testMiddlewareOneUser(): void- {- putenv('SANDSTORM=1');-- $repository = $this->mock(UserRepositoryInterface::class);- $repository->shouldReceive('count')->twice()->andReturn(1);- $repository->shouldReceive('first')->once()->andReturn($this->user());- $repository->shouldReceive('hasRole')->andReturn(true);-- $response = $this->get('/_test/sandstorm', ['X-Sandstorm-User-Id' => 'abcd']);$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());$response->assertSee('sandstorm-anon: false');