grantPermissionsToTestedRole(['view test entity']); break; case 'POST': $this->grantPermissionsToTestedRole(['create entity_test entity_test_with_bundle entities']); break; case 'PATCH': case 'DELETE': $this->grantPermissionsToTestedRole(['administer entity_test content']); break; } } /** * {@inheritdoc} */ protected function createEntity() { $entity_test = EntityTest::create([ 'name' => 'Llama', 'type' => 'entity_test', ]); $entity_test->setOwnerId(0); $entity_test->save(); return $entity_test; } /** * {@inheritdoc} */ protected function getExpectedNormalizedEntity() { $author = User::load(0); $normalization = [ 'uuid' => [ [ 'value' => $this->entity->uuid() ] ], 'id' => [ [ 'value' => 1, ], ], 'langcode' => [ [ 'value' => 'en', ], ], 'type' => [ [ 'value' => 'entity_test', ] ], 'name' => [ [ 'value' => 'Llama', ] ], 'created' => [ [ 'value' => (int) $this->entity->get('created')->value, ] ], 'user_id' => [ [ 'target_id' => (int) $author->id(), 'target_type' => 'user', 'target_uuid' => $author->uuid(), 'url' => $author->toUrl()->toString(), ] ], 'field_test_text' => [], ]; return $normalization; } /** * {@inheritdoc} */ protected function getNormalizedPostEntity() { return [ 'type' => 'entity_test', 'name' => [ [ 'value' => 'Dramallama', ], ], ]; } /** * {@inheritdoc} */ protected function getExpectedUnauthorizedAccessMessage($method) { if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) { return parent::getExpectedUnauthorizedAccessMessage($method); } switch ($method) { case 'GET': return "The 'view test entity' permission is required."; case 'POST': return "The following permissions are required: 'administer entity_test content' OR 'administer entity_test_with_bundle content' OR 'create entity_test entity_test_with_bundle entities'."; default: return parent::getExpectedUnauthorizedAccessMessage($method); } } }