3 namespace Drupal\Tests\rest\Functional\EntityResource\Item;
5 use Drupal\aggregator\Entity\Feed;
6 use Drupal\aggregator\Entity\Item;
7 use Drupal\Tests\rest\Functional\BcTimestampNormalizerUnixTestTrait;
8 use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
11 * ResourceTestBase for Item entity.
13 abstract class ItemResourceTestBase extends EntityResourceTestBase {
15 use BcTimestampNormalizerUnixTestTrait;
20 public static $modules = ['aggregator'];
25 protected static $entityTypeId = 'aggregator_item';
30 protected static $patchProtectedFieldNames = [];
35 * @var \Drupal\aggregator\ItemInterface
42 protected function setUpAuthorization($method) {
45 $this->grantPermissionsToTestedRole(['access news feeds']);
51 $this->grantPermissionsToTestedRole(['administer news feeds']);
59 protected function createEntity() {
60 // Create a "Camelids" feed.
61 $feed = Feed::create([
62 'title' => 'Camelids',
63 'url' => 'https://groups.drupal.org/not_used/167169',
65 'checked' => 1389919932,
66 'description' => 'Drupal Core Group feed',
70 // Create a "Llama" item.
71 $item = Item::create();
72 $item->setTitle('Llama')
73 ->setFeedId($feed->id())
74 ->setLink('https://www.drupal.org/')
75 ->setPostedTime(123456789)
84 protected function createAnotherEntity() {
85 $entity = $this->entity->createDuplicate();
86 $entity->setLink('https://www.example.org/');
87 $label_key = $entity->getEntityType()->getKey('label');
89 $entity->set($label_key, $entity->label() . '_dupe');
98 protected function getExpectedNormalizedEntity() {
99 $feed = Feed::load($this->entity->getFeedId());
115 'target_type' => 'aggregator_feed',
116 'target_uuid' => $feed->uuid(),
117 'url' => base_path() . 'aggregator/sources/1',
127 'value' => 'https://www.drupal.org/',
133 $this->formatExpectedTimestampItemValues(123456789),
142 protected function getNormalizedPostEntity() {
156 'value' => 'https://www.drupal.org/',
165 protected function getExpectedCacheContexts() {
166 // @see ::createEntity()
167 return ['user.permissions'];
173 protected function getExpectedUnauthorizedAccessMessage($method) {
174 if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) {
175 return parent::getExpectedUnauthorizedAccessMessage($method);
180 return "The 'access news feeds' permission is required.";
185 return "The 'administer news feeds' permission is required.";
188 return parent::getExpectedUnauthorizedAccessMessage($method);