BaseFieldOverrideResourceTestBase.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. namespace Drupal\FunctionalTests\Rest;
  3. use Drupal\Core\Field\Entity\BaseFieldOverride;
  4. use Drupal\node\Entity\NodeType;
  5. use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
  6. abstract class BaseFieldOverrideResourceTestBase extends EntityResourceTestBase {
  7. /**
  8. * {@inheritdoc}
  9. */
  10. public static $modules = ['field', 'node'];
  11. /**
  12. * {@inheritdoc}
  13. */
  14. protected static $entityTypeId = 'base_field_override';
  15. /**
  16. * @var \Drupal\Core\Field\Entity\BaseFieldOverride
  17. */
  18. protected $entity;
  19. /**
  20. * {@inheritdoc}
  21. */
  22. protected function setUpAuthorization($method) {
  23. $this->grantPermissionsToTestedRole(['administer node fields']);
  24. }
  25. /**
  26. * {@inheritdoc}
  27. */
  28. protected function createEntity() {
  29. $camelids = NodeType::create([
  30. 'name' => 'Camelids',
  31. 'type' => 'camelids',
  32. ]);
  33. $camelids->save();
  34. $entity = BaseFieldOverride::create([
  35. 'field_name' => 'promote',
  36. 'entity_type' => 'node',
  37. 'bundle' => 'camelids',
  38. ]);
  39. $entity->save();
  40. return $entity;
  41. }
  42. /**
  43. * {@inheritdoc}
  44. */
  45. protected function getExpectedNormalizedEntity() {
  46. return [
  47. 'bundle' => 'camelids',
  48. 'default_value' => [],
  49. 'default_value_callback' => '',
  50. 'dependencies' => [
  51. 'config' => [
  52. 'node.type.camelids',
  53. ],
  54. ],
  55. 'description' => '',
  56. 'entity_type' => 'node',
  57. 'field_name' => 'promote',
  58. 'field_type' => 'boolean',
  59. 'id' => 'node.camelids.promote',
  60. 'label' => NULL,
  61. 'langcode' => 'en',
  62. 'required' => FALSE,
  63. 'settings' => [
  64. 'on_label' => 'On',
  65. 'off_label' => 'Off',
  66. ],
  67. 'status' => TRUE,
  68. 'translatable' => TRUE,
  69. 'uuid' => $this->entity->uuid(),
  70. ];
  71. }
  72. /**
  73. * {@inheritdoc}
  74. */
  75. protected function getNormalizedPostEntity() {
  76. // @todo Update in https://www.drupal.org/node/2300677.
  77. }
  78. /**
  79. * {@inheritdoc}
  80. */
  81. protected function getExpectedCacheContexts() {
  82. return [
  83. 'user.permissions',
  84. ];
  85. }
  86. /**
  87. * {@inheritdoc}
  88. */
  89. protected function getExpectedUnauthorizedAccessMessage($method) {
  90. if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) {
  91. return parent::getExpectedUnauthorizedAccessMessage($method);
  92. }
  93. return "The 'administer node fields' permission is required.";
  94. }
  95. }