protected function CartResourceTestBase::setUpAuthorization in Commerce Cart API 8
Sets up the necessary authorization.
In case of a test verifying publicly accessible REST resources: grant permissions to the anonymous user role.
In case of a test verifying behavior when using a particular authentication provider: create a user with a particular set of permissions.
Because of the $method parameter, it's possible to first set up authentication for only GET, then add POST, et cetera. This then also allows for verifying a 403 in case of missing authorization.
Parameters
string $method: The HTTP method for which to set up authentication.
Overrides ResourceTestBase::setUpAuthorization
See also
::grantPermissionsToAnonymousRole()
::grantPermissionsToAuthenticatedRole()
10 calls to CartResourceTestBase::setUpAuthorization()
- CartAccessApiResourceTest::setUp in tests/
src/ Functional/ CartAccessApiResourceTest.php - CartAddResourceTest::setUp in tests/
src/ Functional/ CartAddResourceTest.php - CartCanonicalResourceTest::setUp in tests/
src/ Functional/ CartCanonicalResourceTest.php - CartClearResourceTest::setUp in tests/
src/ Functional/ CartClearResourceTest.php - CartCollectionResourceTest::setUp in tests/
src/ Functional/ CartCollectionResourceTest.php
File
- tests/
src/ Functional/ CartResourceTestBase.php, line 143
Class
- CartResourceTestBase
- Defines base class for commerce_cart_api test cases.
Namespace
Drupal\Tests\commerce_cart_api\FunctionalCode
protected function setUpAuthorization($method) {
switch ($method) {
case 'GET':
$this
->grantPermissionsToTestedRole([
'restful get ' . static::$resourceConfigId,
]);
break;
case 'POST':
$this
->grantPermissionsToTestedRole([
'restful post ' . static::$resourceConfigId,
]);
break;
case 'PATCH':
$this
->grantPermissionsToTestedRole([
'restful patch ' . static::$resourceConfigId,
]);
break;
case 'DELETE':
$this
->grantPermissionsToTestedRole([
'restful delete ' . static::$resourceConfigId,
]);
break;
default:
throw new \UnexpectedValueException();
}
}