public function RestfulListTestCase::testAccessHandling in RESTful 7.2
Test error handling when no access is granted to an entity in a list.
File
- tests/
RestfulListTestCase.test, line 795 - Contains RestfulListTestCase.
Class
- RestfulListTestCase
- Class RestfulListTestCase.
Code
public function testAccessHandling() {
$resource_manager = restful()
->getResourceManager();
$settings = array(
'type' => 'article',
);
$node1 = $this
->drupalCreateNode($settings);
$node2 = $this
->drupalCreateNode($settings);
$node3 = $this
->drupalCreateNode($settings);
$user1 = $this
->drupalCreateUser();
// Deny access via hook_node_access() to a specific node.
restful_test_deny_access_node($node2->nid);
variable_set('restful_show_access_denied', TRUE);
$handler = $resource_manager
->getPlugin('articles:1.0');
$handler
->setAccount($user1);
$handler
->setRequest(Request::create('api/articles/v1.0'));
$handler
->setPath('');
$result = drupal_json_decode(restful()
->getFormatterManager()
->format($handler
->process(), 'json'));
$this
->assertEqual(count($result['data']), 2, 'List returned and ignored un-accessible entity.');
$this
->assertEqual(count($result['denied']), 1, 'A denied entity was detected.');
// Get a list with specific IDs.
$ids = array(
$node1->nid,
$node2->nid,
$node3->nid,
);
$handler
->setRequest(Request::create('api/articles/v1.0' . implode(',', $ids)));
$handler
->setPath(implode(',', $ids));
$result = drupal_json_decode(restful()
->getFormatterManager()
->format($handler
->process(), 'json'));
$this
->assertEqual(count($result['data']), 2, 'List of specific items returned and ignored un-accessible entity.');
$this
->assertEqual(count($result['denied']), 1, 'A denied entity was detected.');
}