You are here

protected function RESTTestBase::enableService in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/rest/src/Tests/RESTTestBase.php \Drupal\rest\Tests\RESTTestBase::enableService()

Enables the REST service interface for a specific entity type.

Parameters

string|FALSE $resource_type: The resource type that should get REST API enabled or FALSE to disable all resource types.

string $method: The HTTP method to enable, e.g. GET, POST etc.

string $format: (Optional) The serialization format, e.g. hal_json.

array $auth: (Optional) The list of valid authentication methods.

19 calls to RESTTestBase::enableService()
AuthTest::testRead in core/modules/rest/src/Tests/AuthTest.php
Tests reading from an authenticated resource.
CreateTest::testCreateComment in core/modules/rest/src/Tests/CreateTest.php
Test comment creation.
CreateTest::testCreateEntityTest in core/modules/rest/src/Tests/CreateTest.php
Tests valid and invalid create requests for 'entity_test' entity type.
CreateTest::testCreateNode in core/modules/rest/src/Tests/CreateTest.php
Tests several valid and invalid create requests for 'node' entity type.
CreateTest::testCreateResourceRestApiNotEnabled in core/modules/rest/src/Tests/CreateTest.php
Try to create a resource which is not REST API enabled.

... See full list

File

core/modules/rest/src/Tests/RESTTestBase.php, line 250
Contains \Drupal\rest\Tests\RESTTestBase.

Class

RESTTestBase
Test helper class that provides a REST client method to send HTTP requests.

Namespace

Drupal\rest\Tests

Code

protected function enableService($resource_type, $method = 'GET', $format = NULL, $auth = NULL) {

  // Enable REST API for this entity type.
  $config = $this
    ->config('rest.settings');
  $settings = array();
  if ($resource_type) {
    if ($format == NULL) {
      $format = $this->defaultFormat;
    }
    $settings[$resource_type][$method]['supported_formats'][] = $format;
    if ($auth == NULL) {
      $auth = $this->defaultAuth;
    }
    $settings[$resource_type][$method]['supported_auth'] = $auth;
  }
  $config
    ->set('resources', $settings);
  $config
    ->save();
  $this
    ->rebuildCache();
}