Chris@12: provisionResource([static::$format], $auth); Chris@12: } Chris@12: Chris@12: /** Chris@12: * Writes a log messages and retrieves it via the REST API. Chris@12: */ Chris@12: public function testWatchdog() { Chris@12: // Write a log message to the DB. Chris@12: $this->container->get('logger.channel.rest')->notice('Test message'); Chris@12: // Get the ID of the written message. Chris@18: $id = Database::getConnection()->queryRange("SELECT wid FROM {watchdog} WHERE type = :type ORDER BY wid DESC", 0, 1, [':type' => 'rest']) Chris@12: ->fetchField(); Chris@12: Chris@12: $this->initAuthentication(); Chris@14: $url = Url::fromRoute('rest.dblog.GET', ['id' => $id, '_format' => static::$format]); Chris@12: $request_options = $this->getAuthenticationRequestOptions('GET'); Chris@12: Chris@12: $response = $this->request('GET', $url, $request_options); Chris@17: $this->assertResourceErrorResponse(403, "The 'restful get dblog' permission is required.", $response, ['4xx-response', 'http_response'], ['user.permissions'], FALSE, FALSE); Chris@12: Chris@12: // Create a user account that has the required permissions to read Chris@12: // the watchdog resource via the REST API. Chris@12: $this->setUpAuthorization('GET'); Chris@12: Chris@12: $response = $this->request('GET', $url, $request_options); Chris@12: $this->assertResourceResponse(200, FALSE, $response, ['config:rest.resource.dblog', 'config:rest.settings', 'http_response'], ['user.permissions'], FALSE, 'MISS'); Chris@12: $log = Json::decode((string) $response->getBody()); Chris@12: $this->assertEqual($log['wid'], $id, 'Log ID is correct.'); Chris@12: $this->assertEqual($log['type'], 'rest', 'Type of log message is correct.'); Chris@12: $this->assertEqual($log['message'], 'Test message', 'Log message text is correct.'); Chris@12: Chris@12: // Request an unknown log entry. Chris@12: $url->setRouteParameter('id', 9999); Chris@12: $response = $this->request('GET', $url, $request_options); Chris@12: $this->assertResourceErrorResponse(404, 'Log entry with ID 9999 was not found', $response); Chris@12: Chris@12: // Make a bad request (a true malformed request would never be a route match). Chris@12: $url->setRouteParameter('id', 0); Chris@12: $response = $this->request('GET', $url, $request_options); Chris@12: $this->assertResourceErrorResponse(400, 'No log entry ID was provided', $response); Chris@12: } Chris@12: Chris@12: /** Chris@12: * {@inheritdoc} Chris@12: */ Chris@12: protected function setUpAuthorization($method) { Chris@12: switch ($method) { Chris@12: case 'GET': Chris@12: $this->grantPermissionsToTestedRole(['restful get dblog']); Chris@12: break; Chris@12: Chris@12: default: Chris@12: throw new \UnexpectedValueException(); Chris@12: } Chris@12: } Chris@12: Chris@12: /** Chris@12: * {@inheritdoc} Chris@12: */ Chris@12: protected function assertNormalizationEdgeCases($method, Url $url, array $request_options) {} Chris@12: Chris@12: /** Chris@12: * {@inheritdoc} Chris@12: */ Chris@12: protected function getExpectedUnauthorizedAccessMessage($method) {} Chris@12: Chris@12: /** Chris@12: * {@inheritdoc} Chris@12: */ Chris@12: protected function getExpectedBcUnauthorizedAccessMessage($method) {} Chris@12: Chris@12: /** Chris@12: * {@inheritdoc} Chris@12: */ Chris@12: protected function getExpectedUnauthorizedAccessCacheability() {} Chris@12: Chris@12: }