EntityViewDisplayResourceTestBase.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. namespace Drupal\FunctionalTests\Rest;
  3. use Drupal\Core\Entity\Entity\EntityViewDisplay;
  4. use Drupal\node\Entity\NodeType;
  5. use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
  6. abstract class EntityViewDisplayResourceTestBase extends EntityResourceTestBase {
  7. /**
  8. * {@inheritdoc}
  9. */
  10. public static $modules = ['node'];
  11. /**
  12. * {@inheritdoc}
  13. */
  14. protected static $entityTypeId = 'entity_view_display';
  15. /**
  16. * {@inheritdoc}
  17. */
  18. protected static $patchProtectedFieldNames = [];
  19. /**
  20. * @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface
  21. */
  22. protected $entity;
  23. /**
  24. * {@inheritdoc}
  25. */
  26. protected function setUpAuthorization($method) {
  27. $this->grantPermissionsToTestedRole(['administer node display']);
  28. }
  29. /**
  30. * {@inheritdoc}
  31. */
  32. protected function createEntity() {
  33. // Create a "Camelids" node type.
  34. $camelids = NodeType::create([
  35. 'name' => 'Camelids',
  36. 'type' => 'camelids',
  37. ]);
  38. $camelids->save();
  39. // Create a view display.
  40. $view_display = EntityViewDisplay::create([
  41. 'targetEntityType' => 'node',
  42. 'bundle' => 'camelids',
  43. 'mode' => 'default',
  44. 'status' => TRUE,
  45. ]);
  46. $view_display->save();
  47. return $view_display;
  48. }
  49. /**
  50. * {@inheritdoc}
  51. */
  52. protected function getExpectedNormalizedEntity() {
  53. return [
  54. 'bundle' => 'camelids',
  55. 'content' => [
  56. 'links' => [
  57. 'region' => 'content',
  58. 'weight' => 100,
  59. 'settings' => [],
  60. 'third_party_settings' => [],
  61. ],
  62. ],
  63. 'dependencies' => [
  64. 'config' => [
  65. 'node.type.camelids',
  66. ],
  67. 'module' => [
  68. 'user',
  69. ],
  70. ],
  71. 'hidden' => [],
  72. 'id' => 'node.camelids.default',
  73. 'langcode' => 'en',
  74. 'mode' => 'default',
  75. 'status' => TRUE,
  76. 'targetEntityType' => 'node',
  77. 'uuid' => $this->entity->uuid(),
  78. ];
  79. }
  80. /**
  81. * {@inheritdoc}
  82. */
  83. protected function getNormalizedPostEntity() {
  84. // @todo Update in https://www.drupal.org/node/2300677.
  85. }
  86. /**
  87. * {@inheritdoc}
  88. */
  89. protected function getExpectedCacheContexts() {
  90. return [
  91. 'user.permissions',
  92. ];
  93. }
  94. /**
  95. * {@inheritdoc}
  96. */
  97. protected function getExpectedUnauthorizedAccessMessage($method) {
  98. if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) {
  99. return parent::getExpectedUnauthorizedAccessMessage($method);
  100. }
  101. return "The 'administer node display' permission is required.";
  102. }
  103. }