3 namespace Drupal\Tests\rest\Functional\EntityResource\BlockContent;
5 use Drupal\block_content\Entity\BlockContent;
6 use Drupal\block_content\Entity\BlockContentType;
7 use Drupal\Core\Cache\Cache;
8 use Drupal\Tests\rest\Functional\BcTimestampNormalizerUnixTestTrait;
9 use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
12 * ResourceTestBase for BlockContent entity.
14 abstract class BlockContentResourceTestBase extends EntityResourceTestBase {
16 use BcTimestampNormalizerUnixTestTrait;
21 public static $modules = ['block_content'];
26 protected static $entityTypeId = 'block_content';
31 protected static $patchProtectedFieldNames = [
36 * @var \Drupal\block_content\BlockContentInterface
43 protected function setUpAuthorization($method) {
44 $this->grantPermissionsToTestedRole(['administer blocks']);
50 protected function createEntity() {
51 if (!BlockContentType::load('basic')) {
52 $block_content_type = BlockContentType::create([
57 $block_content_type->save();
58 block_content_add_body_field($block_content_type->id());
61 // Create a "Llama" custom block.
62 $block_content = BlockContent::create([
66 'value' => 'The name "llama" was adopted by European settlers from native Peruvians.',
67 'format' => 'plain_text',
70 ->setPublished(FALSE);
71 $block_content->save();
72 return $block_content;
78 protected function getExpectedNormalizedEntity() {
87 'value' => $this->entity->uuid(),
97 'target_id' => 'basic',
98 'target_type' => 'block_content_type',
99 'target_uuid' => BlockContentType::load('basic')->uuid(),
107 'revision_log' => [],
109 $this->formatExpectedTimestampItemValues($this->entity->getChangedTime()),
116 'revision_created' => [
117 $this->formatExpectedTimestampItemValues((int) $this->entity->getRevisionCreationTime()),
119 'revision_user' => [],
120 'revision_translation_affected' => [
125 'default_langcode' => [
132 'value' => 'The name "llama" was adopted by European settlers from native Peruvians.',
133 'format' => 'plain_text',
135 'processed' => "<p>The name "llama" was adopted by European settlers from native Peruvians.</p>\n",
149 protected function getNormalizedPostEntity() {
153 'target_id' => 'basic',
158 'value' => 'Dramallama',
168 protected function getExpectedUnauthorizedAccessMessage($method) {
169 if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) {
170 return parent::getExpectedUnauthorizedAccessMessage($method);
173 return parent::getExpectedUnauthorizedAccessMessage($method);
179 protected function getExpectedUnauthorizedAccessCacheability() {
180 // @see \Drupal\block_content\BlockContentAccessControlHandler()
181 return parent::getExpectedUnauthorizedAccessCacheability()
182 ->addCacheTags(['block_content:1']);
188 protected function getExpectedCacheTags() {
189 return Cache::mergeTags(parent::getExpectedCacheTags(), ['config:filter.format.plain_text']);
195 protected function getExpectedCacheContexts() {
196 return Cache::mergeContexts(['url.site'], $this->container->getParameter('renderer.config')['required_cache_contexts']);