X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fmenu_link_content%2Ftests%2Fsrc%2FFunctional%2FRest%2FMenuLinkContentResourceTestBase.php;fp=web%2Fcore%2Fmodules%2Fmenu_link_content%2Ftests%2Fsrc%2FFunctional%2FRest%2FMenuLinkContentResourceTestBase.php;h=9b03899e450a2056e2c0926b5481a2110203d9e2;hp=0000000000000000000000000000000000000000;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hpb=74df008bdbb3a11eeea356744f39b802369bda3c diff --git a/web/core/modules/menu_link_content/tests/src/Functional/Rest/MenuLinkContentResourceTestBase.php b/web/core/modules/menu_link_content/tests/src/Functional/Rest/MenuLinkContentResourceTestBase.php new file mode 100644 index 000000000..9b03899e4 --- /dev/null +++ b/web/core/modules/menu_link_content/tests/src/Functional/Rest/MenuLinkContentResourceTestBase.php @@ -0,0 +1,213 @@ + NULL, + ]; + + /** + * The MenuLinkContent entity. + * + * @var \Drupal\menu_link_content\MenuLinkContentInterface + */ + protected $entity; + + /** + * {@inheritdoc} + */ + protected function setUpAuthorization($method) { + switch ($method) { + case 'GET': + case 'POST': + case 'PATCH': + case 'DELETE': + $this->grantPermissionsToTestedRole(['administer menu']); + break; + } + } + + /** + * {@inheritdoc} + */ + protected function createEntity() { + $menu_link = MenuLinkContent::create([ + 'id' => 'llama', + 'title' => 'Llama Gabilondo', + 'description' => 'Llama Gabilondo', + 'link' => [ + 'uri' => 'https://nl.wikipedia.org/wiki/Llama', + 'options' => [ + 'fragment' => 'a-fragment', + 'attributes' => [ + 'class' => ['example-class'], + ], + ], + ], + 'weight' => 0, + 'menu_name' => 'main', + ]); + $menu_link->save(); + + return $menu_link; + } + + /** + * {@inheritdoc} + */ + protected function getNormalizedPostEntity() { + return [ + 'title' => [ + [ + 'value' => 'Dramallama', + ], + ], + 'link' => [ + [ + 'uri' => 'http://www.urbandictionary.com/define.php?term=drama%20llama', + 'options' => [ + 'fragment' => 'a-fragment', + 'attributes' => [ + 'class' => ['example-class'], + ], + ], + ], + ], + 'bundle' => [ + [ + 'value' => 'menu_link_content', + ], + ], + ]; + } + + /** + * {@inheritdoc} + */ + protected function getExpectedNormalizedEntity() { + return [ + 'uuid' => [ + [ + 'value' => $this->entity->uuid(), + ], + ], + 'id' => [ + [ + 'value' => 1, + ], + ], + 'title' => [ + [ + 'value' => 'Llama Gabilondo', + ], + ], + 'link' => [ + [ + 'uri' => 'https://nl.wikipedia.org/wiki/Llama', + 'title' => NULL, + 'options' => [ + 'fragment' => 'a-fragment', + 'attributes' => [ + 'class' => ['example-class'], + ], + ], + ], + ], + 'weight' => [ + [ + 'value' => 0, + ], + ], + 'menu_name' => [ + [ + 'value' => 'main', + ], + ], + 'langcode' => [ + [ + 'value' => 'en', + ], + ], + 'bundle' => [ + [ + 'value' => 'menu_link_content', + ], + ], + 'description' => [ + [ + 'value' => 'Llama Gabilondo', + ], + ], + 'external' => [ + [ + 'value' => FALSE, + ], + ], + 'rediscover' => [ + [ + 'value' => FALSE, + ], + ], + 'expanded' => [ + [ + 'value' => FALSE, + ], + ], + 'enabled' => [ + [ + 'value' => TRUE, + ], + ], + 'changed' => [ + $this->formatExpectedTimestampItemValues($this->entity->getChangedTime()), + ], + 'default_langcode' => [ + [ + 'value' => TRUE, + ], + ], + 'parent' => [], + ]; + } + + /** + * {@inheritdoc} + */ + protected function getExpectedUnauthorizedAccessMessage($method) { + if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) { + return parent::getExpectedUnauthorizedAccessMessage($method); + } + + switch ($method) { + case 'DELETE': + return "You are not authorized to delete this menu_link_content entity."; + default: + return parent::getExpectedUnauthorizedAccessMessage($method); + } + } + +}