7 protected $apiTokenId = 'apitoken';
8 protected $apiTokenSecret = 'password';
11 * Set the API editor role as the current user via the API driver.
13 protected function actingAsApiEditor()
15 $this->actingAs($this->getEditor(), 'api');
21 * Set the API admin role as the current user via the API driver.
23 protected function actingAsApiAdmin()
25 $this->actingAs($this->getAdmin(), 'api');
31 * Format the given items into a standardised error format.
33 protected function errorResponse(string $message, int $code): array
35 return ['error' => ['code' => $code, 'message' => $message]];
39 * Get the structure that matches a permission error response.
41 protected function permissionErrorResponse(): array
43 return $this->errorResponse('You do not have permission to perform the requested action.', 403);
47 * Format the given (field_name => ["messages"]) array
48 * into a standard validation response format.
50 protected function validationResponse(array $messages): array
52 $err = $this->errorResponse('The given data was invalid.', 422);
53 $err['error']['validation'] = $messages;
59 * Get an approved API auth header.
61 protected function apiAuthHeader(): array
64 'Authorization' => "Token {$this->apiTokenId}:{$this->apiTokenSecret}",