3 namespace Drupal\Tests\rest\Functional\EntityResource\Node;
5 use Drupal\node\Entity\Node;
6 use Drupal\node\Entity\NodeType;
7 use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
8 use Drupal\user\Entity\User;
10 abstract class NodeResourceTestBase extends EntityResourceTestBase {
15 public static $modules = ['node'];
20 protected static $entityTypeId = 'node';
25 protected static $patchProtectedFieldNames = [
36 * @var \Drupal\node\NodeInterface
43 protected function setUpAuthorization($method) {
46 $this->grantPermissionsToTestedRole(['access content']);
49 $this->grantPermissionsToTestedRole(['access content', 'create camelids content']);
52 $this->grantPermissionsToTestedRole(['access content', 'edit any camelids content']);
55 $this->grantPermissionsToTestedRole(['access content', 'delete any camelids content']);
63 protected function createEntity() {
64 if (!NodeType::load('camelids')) {
65 // Create a "Camelids" node type.
72 // Create a "Llama" node.
73 $node = Node::create(['type' => 'camelids']);
74 $node->setTitle('Llama')
75 ->setOwnerId(static::$auth ? $this->account->id() : 0)
77 ->setCreatedTime(123456789)
78 ->setChangedTime(123456789)
79 ->setRevisionCreationTime(123456789)
88 protected function getExpectedNormalizedEntity() {
89 $author = User::load($this->entity->getOwnerId());
95 ['value' => $this->entity->uuid()],
107 'target_id' => 'camelids',
108 'target_type' => 'node_type',
109 'target_uuid' => NodeType::load('camelids')->uuid(),
124 'value' => 123456789,
129 'value' => $this->entity->getChangedTime(),
142 'revision_timestamp' => [
144 'value' => 123456789,
147 'revision_translation_affected' => [
152 'default_langcode' => [
159 'target_id' => (int) $author->id(),
160 'target_type' => 'user',
161 'target_uuid' => $author->uuid(),
162 'url' => base_path() . 'user/' . $author->id(),
167 'target_id' => (int) $author->id(),
168 'target_type' => 'user',
169 'target_uuid' => $author->uuid(),
170 'url' => base_path() . 'user/' . $author->id(),
173 'revision_log' => [],
180 protected function getNormalizedPostEntity() {
184 'target_id' => 'camelids',
189 'value' => 'Dramallama',
198 protected function getExpectedUnauthorizedAccessMessage($method) {
199 if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) {
200 return parent::getExpectedUnauthorizedAccessMessage($method);
203 if ($method === 'GET' || $method == 'PATCH' || $method == 'DELETE') {
204 return "The 'access content' permission is required.";
206 return parent::getExpectedUnauthorizedAccessMessage($method);