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