1 <?php namespace Tests\Api;
3 use BookStack\Auth\User;
6 class ApiDocsTest extends TestCase
10 protected $endpoint = '/api/docs';
12 public function test_docs_page_not_visible_to_normal_viewers()
14 $viewer = $this->getViewer();
15 $resp = $this->actingAs($viewer)->get($this->endpoint);
16 $resp->assertStatus(403);
18 $resp = $this->actingAsApiEditor()->get($this->endpoint);
19 $resp->assertStatus(200);
22 public function test_docs_page_returns_view_with_docs_content()
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');
31 public function test_docs_json_endpoint_returns_json()
33 $resp = $this->actingAsApiEditor()->get($this->endpoint . '.json');
34 $resp->assertStatus(200);
35 $resp->assertHeader('Content-Type', 'application/json');
38 'name' => 'docs-display',
44 public function test_docs_page_visible_by_public_user_if_given_permission()
46 $this->setSettings(['app-public' => true]);
47 $guest = User::getDefault();
49 $this->startSession();
50 $resp = $this->get('/api/docs');
51 $resp->assertStatus(403);
53 $this->giveUserPermissions($guest, ['access-api']);
55 $resp = $this->get('/api/docs');
56 $resp->assertStatus(200);