EntityFormDisplayResourceTestBase.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. namespace Drupal\FunctionalTests\Rest;
  3. use Drupal\Core\Entity\Entity\EntityFormDisplay;
  4. use Drupal\node\Entity\NodeType;
  5. use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
  6. abstract class EntityFormDisplayResourceTestBase extends EntityResourceTestBase {
  7. /**
  8. * {@inheritdoc}
  9. */
  10. public static $modules = ['node'];
  11. /**
  12. * {@inheritdoc}
  13. */
  14. protected static $entityTypeId = 'entity_form_display';
  15. /**
  16. * @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface
  17. */
  18. protected $entity;
  19. /**
  20. * {@inheritdoc}
  21. */
  22. protected function setUpAuthorization($method) {
  23. $this->grantPermissionsToTestedRole(['administer node form display']);
  24. }
  25. /**
  26. * {@inheritdoc}
  27. */
  28. protected function createEntity() {
  29. // Create a "Camelids" node type.
  30. $camelids = NodeType::create([
  31. 'name' => 'Camelids',
  32. 'type' => 'camelids',
  33. ]);
  34. $camelids->save();
  35. // Create a form display.
  36. $form_display = EntityFormDisplay::create([
  37. 'targetEntityType' => 'node',
  38. 'bundle' => 'camelids',
  39. 'mode' => 'default',
  40. ]);
  41. $form_display->save();
  42. return $form_display;
  43. }
  44. /**
  45. * {@inheritdoc}
  46. */
  47. protected function getExpectedNormalizedEntity() {
  48. return [
  49. 'bundle' => 'camelids',
  50. 'content' => [
  51. 'created' => [
  52. 'type' => 'datetime_timestamp',
  53. 'weight' => 10,
  54. 'region' => 'content',
  55. 'settings' => [],
  56. 'third_party_settings' => [],
  57. ],
  58. 'promote' => [
  59. 'type' => 'boolean_checkbox',
  60. 'settings' => [
  61. 'display_label' => TRUE,
  62. ],
  63. 'weight' => 15,
  64. 'region' => 'content',
  65. 'third_party_settings' => [],
  66. ],
  67. 'status' => [
  68. 'type' => 'boolean_checkbox',
  69. 'weight' => 120,
  70. 'region' => 'content',
  71. 'settings' => [
  72. 'display_label' => TRUE,
  73. ],
  74. 'third_party_settings' => [],
  75. ],
  76. 'sticky' => [
  77. 'type' => 'boolean_checkbox',
  78. 'settings' => [
  79. 'display_label' => TRUE,
  80. ],
  81. 'weight' => 16,
  82. 'region' => 'content',
  83. 'third_party_settings' => [],
  84. ],
  85. 'title' => [
  86. 'type' => 'string_textfield',
  87. 'weight' => -5,
  88. 'region' => 'content',
  89. 'settings' => [
  90. 'size' => 60,
  91. 'placeholder' => '',
  92. ],
  93. 'third_party_settings' => [],
  94. ],
  95. 'uid' => [
  96. 'type' => 'entity_reference_autocomplete',
  97. 'weight' => 5,
  98. 'settings' => [
  99. 'match_operator' => 'CONTAINS',
  100. 'match_limit' => 10,
  101. 'size' => 60,
  102. 'placeholder' => '',
  103. ],
  104. 'region' => 'content',
  105. 'third_party_settings' => [],
  106. ],
  107. ],
  108. 'dependencies' => [
  109. 'config' => [
  110. 'node.type.camelids',
  111. ],
  112. ],
  113. 'hidden' => [],
  114. 'id' => 'node.camelids.default',
  115. 'langcode' => 'en',
  116. 'mode' => 'default',
  117. 'status' => NULL,
  118. 'targetEntityType' => 'node',
  119. 'uuid' => $this->entity->uuid(),
  120. ];
  121. }
  122. /**
  123. * {@inheritdoc}
  124. */
  125. protected function getNormalizedPostEntity() {
  126. // @todo Update in https://www.drupal.org/node/2300677.
  127. }
  128. /**
  129. * {@inheritdoc}
  130. */
  131. protected function getExpectedCacheContexts() {
  132. return [
  133. 'user.permissions',
  134. ];
  135. }
  136. /**
  137. * {@inheritdoc}
  138. */
  139. protected function getExpectedUnauthorizedAccessMessage($method) {
  140. if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) {
  141. return parent::getExpectedUnauthorizedAccessMessage($method);
  142. }
  143. return "The 'administer node form display' permission is required.";
  144. }
  145. }