]> BookStack Code Mirror - bookstack/blob - tests/TestsApi.php
0bb10a4cc764c22941a0c0c99b280c7b59587bf6
[bookstack] / tests / TestsApi.php
1 <?php
2
3 namespace Tests;
4
5 trait TestsApi
6 {
7
8     protected $apiTokenId = 'apitoken';
9     protected $apiTokenSecret = 'password';
10
11     /**
12      * Set the API editor role as the current user via the API driver.
13      */
14     protected function actingAsApiEditor()
15     {
16         $this->actingAs($this->getEditor(), 'api');
17         return $this;
18     }
19
20     /**
21      * Format the given items into a standardised error format.
22      */
23     protected function errorResponse(string $message, int $code): array
24     {
25         return ["error" => ["code" => $code, "message" => $message]];
26     }
27
28     /**
29      * Get an approved API auth header.
30      */
31     protected function apiAuthHeader(): array
32     {
33         return [
34             "Authorization" => "Token {$this->apiTokenId}:{$this->apiTokenSecret}"
35         ];
36     }
37
38 }