]> BookStack Code Mirror - bookstack/blob - tests/StatusTest.php
Docker: Fix permission with node service by adding node as user
[bookstack] / tests / StatusTest.php
1 <?php
2
3 use Illuminate\Support\Facades\DB;
4 use Illuminate\Support\Facades\Cache;
5 use Illuminate\Support\Facades\Session;
6 use Tests\TestCase;
7
8 class StatusTest extends TestCase
9 {
10     public function test_returns_json_with_expected_results()
11     {
12         $resp = $this->get("/status");
13         $resp->assertStatus(200);
14         $resp->assertJson([
15             'database' => true,
16             'cache' => true,
17             'session' => true,
18         ]);
19     }
20
21     public function test_returns_500_status_and_false_on_db_error()
22     {
23         DB::shouldReceive('table')->andThrow(new Exception());
24
25         $resp = $this->get("/status");
26         $resp->assertStatus(500);
27         $resp->assertJson([
28             'database' => false,
29         ]);
30     }
31
32     public function test_returns_500_status_and_false_on_wrong_cache_return()
33     {
34         Cache::partialMock()->shouldReceive('get')->andReturn('cat');
35
36         $resp = $this->get("/status");
37         $resp->assertStatus(500);
38         $resp->assertJson([
39             'cache' => false,
40         ]);
41     }
42
43     public function test_returns_500_status_and_false_on_wrong_session_return()
44     {
45         $session = Session::getFacadeRoot();
46         $mockSession = Mockery::mock($session)->makePartial();
47         Session::swap($mockSession);
48         $mockSession->shouldReceive('get')->andReturn('cat');
49
50         $resp = $this->get("/status");
51         $resp->assertStatus(500);
52         $resp->assertJson([
53             'session' => false,
54         ]);
55     }
56 }