]> BookStack Code Mirror - bookstack/blob - tests/Api/ApiDocsTest.php
Merge branch 'footer-links' of git://github.com/james-geiger/BookStack into james...
[bookstack] / tests / Api / ApiDocsTest.php
1 <?php namespace Tests\Api;
2
3 use BookStack\Auth\User;
4 use Tests\TestCase;
5
6 class ApiDocsTest extends TestCase
7 {
8     use TestsApi;
9
10     protected $endpoint = '/api/docs';
11
12     public function test_docs_page_not_visible_to_normal_viewers()
13     {
14         $viewer = $this->getViewer();
15         $resp = $this->actingAs($viewer)->get($this->endpoint);
16         $resp->assertStatus(403);
17
18         $resp = $this->actingAsApiEditor()->get($this->endpoint);
19         $resp->assertStatus(200);
20     }
21
22     public function test_docs_page_returns_view_with_docs_content()
23     {
24         $resp = $this->actingAsApiEditor()->get($this->endpoint);
25         $resp->assertStatus(200);
26         $resp->assertSee(url('/api/docs.json'));
27         $resp->assertSee('Show a JSON view of the API docs data.');
28         $resp->assertHeader('Content-Type', 'text/html; charset=UTF-8');
29     }
30
31     public function test_docs_json_endpoint_returns_json()
32     {
33         $resp = $this->actingAsApiEditor()->get($this->endpoint . '.json');
34         $resp->assertStatus(200);
35         $resp->assertHeader('Content-Type', 'application/json');
36         $resp->assertJson([
37             'docs' => [ [
38                 'name' => 'docs-display',
39                 'uri' => 'api/docs'
40             ] ]
41         ]);
42     }
43
44     public function test_docs_page_visible_by_public_user_if_given_permission()
45     {
46         $this->setSettings(['app-public' => true]);
47         $guest = User::getDefault();
48
49         $this->startSession();
50         $resp = $this->get('/api/docs');
51         $resp->assertStatus(403);
52
53         $this->giveUserPermissions($guest, ['access-api']);
54
55         $resp = $this->get('/api/docs');
56         $resp->assertStatus(200);
57     }
58 }