- $method = 'GET';
- $uri = $this->prepareUrlForRequest($uri);
- $this->call($method, $uri, $parameters, $cookies, $files);
- $this->clearInputs()->followRedirects();
- $this->currentUri = $this->app->make('request')->fullUrl();
- $this->crawler = new Crawler($this->response->getContent(), $uri);
- return $this;
+ PHPUnit::assertTrue($this->isPermissionError($response->baseResponse ?? $response->response), 'Failed asserting the response contains a permission error.');
+ }
+
+ /**
+ * Assert a permission error has occurred.
+ */
+ protected function assertNotPermissionError($response)
+ {
+ PHPUnit::assertFalse($this->isPermissionError($response->baseResponse ?? $response->response), 'Failed asserting the response does not contain a permission error.');
+ }
+
+ /**
+ * Check if the given response is a permission error.
+ */
+ private function isPermissionError($response): bool
+ {
+ if ($response->status() === 403 && $response instanceof JsonResponse) {
+ $errMessage = $response->getData(true)['error']['message'] ?? '';
+ return $errMessage === 'You do not have permission to perform the requested action.';
+ }
+
+ return $response->status() === 302
+ && $response->headers->get('Location') === url('/')
+ && str_starts_with(session()->pull('error', ''), 'You do not have permission to access');
+ }
+
+ /**
+ * Assert that the session has a particular error notification message set.
+ */
+ protected function assertSessionError(string $message)
+ {
+ $error = session()->get('error');
+ PHPUnit::assertTrue($error === $message, "Failed asserting the session contains an error. \nFound: {$error}\nExpecting: {$message}");