public function RestfulEntityAndPropertyAccessTestCase::testPublicFieldAccess in RESTful 7.2
Same name and namespace in other branches
- 7 tests/RestfulEntityAndPropertyAccessTestCase.test \RestfulEntityAndPropertyAccessTestCase::testPublicFieldAccess()
Test access callback per public field.
File
- tests/
RestfulEntityAndPropertyAccessTestCase.test, line 207 - Contains RestfulEntityAndPropertyAccessTestCase
Class
Code
public function testPublicFieldAccess() {
$settings = array(
'title' => 'no access',
'type' => 'article',
);
$node = $this
->drupalCreateNode($settings);
$handler = restful()
->getResourceManager()
->getPlugin('test_articles:1.0');
$result = $this
->doRequest(\Drupal\restful\Http\RequestInterface::METHOD_GET, $handler, array(), $node->nid);
$this
->assertNotNull($result['data'][0]['label'], 'Label access is allowed without access callback.');
variable_set('restful_test_revoke_public_field_access', 'label');
$handler = restful()
->getResourceManager()
->getPluginCopy('test_articles:1.0');
$result = $this
->doRequest(\Drupal\restful\Http\RequestInterface::METHOD_GET, $handler, array(), $node->nid);
$this
->assertTrue(empty($result['data'][0]['label']), 'Label access is denied with access callback.');
}