You are here

public function RestfulEntityAndPropertyAccessTestCase::testEndPointAccessCallback in RESTful 7.2

Same name and namespace in other branches
  1. 7 tests/RestfulEntityAndPropertyAccessTestCase.test \RestfulEntityAndPropertyAccessTestCase::testEndPointAccessCallback()

Tests custom access callbacks at the resource method level.

File

tests/RestfulEntityAndPropertyAccessTestCase.test, line 183
Contains RestfulEntityAndPropertyAccessTestCase

Class

RestfulEntityAndPropertyAccessTestCase

Code

public function testEndPointAccessCallback() {
  $settings = array(
    'type' => 'article',
  );
  $node = $this
    ->drupalCreateNode($settings);
  $handler = restful()
    ->getResourceManager()
    ->getPlugin('test_articles:1.3');
  try {
    $handler
      ->doGet($node->nid);
    $this
      ->fail('Custom access callback per resource\'s method not executed correctly.');
  } catch (ForbiddenException $e) {
    $this
      ->pass('Custom access callback per endpoint executed correctly.');
  }
  $handler
    ->setPath($node->nid);
  $handler
    ->setRequest(\Drupal\restful\Http\Request::create($handler
    ->versionedUrl($node->nid, array(
    'absolute' => FALSE,
  )), array(), \Drupal\restful\Http\RequestInterface::METHOD_HEAD));
  $handler
    ->process();
  $this
    ->pass('Custom access callback per endpoint executed correctly.');
}