X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fsystem%2Ftests%2Fmodules%2Fentity_test%2Ftests%2Fsrc%2FFunctional%2FRest%2FEntityTestMapFieldResourceTestBase.php;fp=web%2Fcore%2Fmodules%2Fsystem%2Ftests%2Fmodules%2Fentity_test%2Ftests%2Fsrc%2FFunctional%2FRest%2FEntityTestMapFieldResourceTestBase.php;h=eae226cfa041d3c1e8a4834dd5e4df0dd0b32833;hp=0000000000000000000000000000000000000000;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hpb=74df008bdbb3a11eeea356744f39b802369bda3c diff --git a/web/core/modules/system/tests/modules/entity_test/tests/src/Functional/Rest/EntityTestMapFieldResourceTestBase.php b/web/core/modules/system/tests/modules/entity_test/tests/src/Functional/Rest/EntityTestMapFieldResourceTestBase.php new file mode 100644 index 000000000..eae226cfa --- /dev/null +++ b/web/core/modules/system/tests/modules/entity_test/tests/src/Functional/Rest/EntityTestMapFieldResourceTestBase.php @@ -0,0 +1,152 @@ + 'value', + 'key2' => 'no, val you', + 'π' => 3.14159, + TRUE => 42, + 'nested' => [ + 'bird' => 'robin', + 'doll' => 'Russian', + ], + ]; + + /** + * {@inheritdoc} + */ + protected function setUpAuthorization($method) { + $this->grantPermissionsToTestedRole(['administer entity_test content']); + } + + /** + * {@inheritdoc} + */ + protected function createEntity() { + $entity = EntityTestMapField::create([ + 'name' => 'Llama', + 'type' => 'entity_test_map_field', + 'data' => [ + static::$mapValue, + ], + ]); + $entity->setOwnerId(0); + $entity->save(); + return $entity; + } + + /** + * {@inheritdoc} + */ + protected function getExpectedNormalizedEntity() { + $author = User::load(0); + return [ + 'uuid' => [ + [ + 'value' => $this->entity->uuid(), + ], + ], + 'id' => [ + [ + 'value' => 1, + ], + ], + 'name' => [ + [ + 'value' => 'Llama', + ], + ], + 'langcode' => [ + [ + 'value' => 'en', + ], + ], + 'created' => [ + $this->formatExpectedTimestampItemValues((int) $this->entity->get('created')->value), + ], + 'user_id' => [ + [ + 'target_id' => (int) $author->id(), + 'target_type' => 'user', + 'target_uuid' => $author->uuid(), + 'url' => $author->toUrl()->toString(), + ], + ], + 'data' => [ + static::$mapValue, + ], + ]; + } + + /** + * {@inheritdoc} + */ + protected function getNormalizedPostEntity() { + return [ + 'name' => [ + [ + 'value' => 'Dramallama', + ], + ], + 'data' => [ + 0 => static::$mapValue, + ], + ]; + } + + /** + * {@inheritdoc} + */ + protected function getExpectedUnauthorizedAccessMessage($method) { + if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) { + return parent::getExpectedUnauthorizedAccessMessage($method); + } + + return "The 'administer entity_test content' permission is required."; + } + + /** + * {@inheritdoc} + */ + protected function getExpectedCacheContexts() { + return ['user.permissions']; + } + +}