Commit 6b7bdcdd authored by webchick's avatar webchick

Issue #2076033 by juampy: Fixed PHP warning when looking if a REST resource...

Issue #2076033 by juampy: Fixed PHP warning when looking if a REST resource defines authentication providers.
parent bc796738
......@@ -74,7 +74,7 @@ public function dynamicRoutes(RouteBuildEvent $event) {
}
// Check if there are authentication provider restrictions in the
// configuration and apply them to the route.
if (is_array($enabled_methods[$method]['supported_auth']) && !empty($enabled_methods[$method]['supported_auth'])) {
if (!empty($enabled_methods[$method]['supported_auth']) && is_array($enabled_methods[$method]['supported_auth'])) {
$route->setOption('_auth', $enabled_methods[$method]['supported_auth']);
}
// If there is no format requirement or if it matches the
......
......@@ -95,4 +95,27 @@ public function testRead() {
$this->assertResponse(404);
$this->assertNull(drupal_json_decode($response), 'No valid JSON found.');
}
/**
* Tests the resource structure.
*/
public function testResourceStructure() {
// Enable a service with a format restriction but no authentication.
$this->enableService('entity:node', 'GET', 'json');
// Create a user account that has the required permissions to read
// resources via the REST API.
$permissions = $this->entityPermissions('node', 'view');
$permissions[] = 'restful get entity:node';
$account = $this->drupalCreateUser($permissions);
$this->drupalLogin($account);
// Create an entity programmatically.
$entity = $this->entityCreate('node');
$entity->save();
// Read it over the REST API.
$response = $this->httpRequest('entity/node/' . $entity->id(), 'GET', NULL, 'application/json');
$this->assertResponse('200', 'HTTP response code is correct.');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment