Unverified Commit 92be45b4 authored by alexpott's avatar alexpott
Browse files

Issue #2910883 by vaplas, ShawnB, Wim Leers: Move all entity type REST tests...

Issue #2910883 by vaplas, ShawnB, Wim Leers: Move all entity type REST tests to the providing modules
parent 29cff725
<?php
namespace Drupal\Tests\hal\Functional\EntityResource\Feed;
namespace Drupal\Tests\aggregator\Functional\Hal;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
......
<?php
namespace Drupal\Tests\hal\Functional\EntityResource\Feed;
namespace Drupal\Tests\aggregator\Functional\Hal;
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
......
<?php
namespace Drupal\Tests\hal\Functional\EntityResource\Feed;
namespace Drupal\Tests\aggregator\Functional\Hal;
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
......
<?php
namespace Drupal\Tests\aggregator\Functional\Hal;
use Drupal\Tests\aggregator\Functional\Rest\FeedResourceTestBase;
use Drupal\Tests\hal\Functional\EntityResource\HalEntityNormalizationTrait;
abstract class FeedHalJsonTestBase extends FeedResourceTestBase {
use HalEntityNormalizationTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['hal'];
/**
* {@inheritdoc}
*/
protected static $format = 'hal_json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/hal+json';
/**
* {@inheritdoc}
*/
protected function getExpectedNormalizedEntity() {
$default_normalization = parent::getExpectedNormalizedEntity();
$normalization = $this->applyHalFieldNormalization($default_normalization);
return $normalization + [
'_links' => [
'self' => [
'href' => $this->baseUrl . '/aggregator/sources/1?_format=hal_json',
],
'type' => [
'href' => $this->baseUrl . '/rest/type/aggregator_feed/aggregator_feed',
],
],
];
}
/**
* {@inheritdoc}
*/
protected function getNormalizedPostEntity() {
return parent::getNormalizedPostEntity() + [
'_links' => [
'type' => [
'href' => $this->baseUrl . '/rest/type/aggregator_feed/aggregator_feed',
],
],
];
}
}
<?php
namespace Drupal\Tests\hal\Functional\EntityResource\Item;
namespace Drupal\Tests\aggregator\Functional\Hal;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
......
<?php
namespace Drupal\Tests\hal\Functional\EntityResource\Item;
namespace Drupal\Tests\aggregator\Functional\Hal;
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
......
<?php
namespace Drupal\Tests\hal\Functional\EntityResource\Item;
namespace Drupal\Tests\aggregator\Functional\Hal;
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
......
<?php
namespace Drupal\Tests\aggregator\Functional\Hal;
use Drupal\aggregator\Entity\Feed;
use Drupal\Tests\aggregator\Functional\Rest\ItemResourceTestBase;
use Drupal\Tests\hal\Functional\EntityResource\HalEntityNormalizationTrait;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
/**
* ResourceTestBase for Item entity.
*/
abstract class ItemHalJsonTestBase extends ItemResourceTestBase {
use HalEntityNormalizationTrait;
use AnonResourceTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['hal'];
/**
* {@inheritdoc}
*/
protected static $format = 'hal_json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/hal+json';
/**
* {@inheritdoc}
*/
protected function getExpectedNormalizedEntity() {
$default_normalization = parent::getExpectedNormalizedEntity();
$normalization = $this->applyHalFieldNormalization($default_normalization);
$feed = Feed::load($this->entity->getFeedId());
return $normalization + [
'_embedded' => [
$this->baseUrl . '/rest/relation/aggregator_item/aggregator_item/fid' => [
[
'_links' => [
'self' => [
'href' => $this->baseUrl . '/aggregator/sources/1?_format=hal_json',
],
'type' => [
'href' => $this->baseUrl . '/rest/type/aggregator_feed/aggregator_feed',
],
],
'uuid' => [
[
'value' => $feed->uuid(),
],
],
],
],
],
'_links' => [
'self' => [
'href' => '',
],
'type' => [
'href' => $this->baseUrl . '/rest/type/aggregator_item/aggregator_item',
],
$this->baseUrl . '/rest/relation/aggregator_item/aggregator_item/fid' => [
[
'href' => $this->baseUrl . '/aggregator/sources/' . $feed->id() . '?_format=hal_json',
],
],
],
];
}
/**
* {@inheritdoc}
*/
protected function getNormalizedPostEntity() {
return parent::getNormalizedPostEntity() + [
'_links' => [
'type' => [
'href' => $this->baseUrl . '/rest/type/aggregator_item/aggregator_item',
],
],
];
}
/**
* {@inheritdoc}
*/
protected function getExpectedCacheContexts() {
return [
'url.site',
'user.permissions',
];
}
}
<?php
namespace Drupal\Tests\rest\Functional\EntityResource\Feed;
namespace Drupal\Tests\aggregator\Functional\Rest;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
......
<?php
namespace Drupal\Tests\rest\Functional\EntityResource\Feed;
namespace Drupal\Tests\aggregator\Functional\Rest;
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
......
<?php
namespace Drupal\Tests\rest\Functional\EntityResource\Feed;
namespace Drupal\Tests\aggregator\Functional\Rest;
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
......
<?php
namespace Drupal\Tests\aggregator\Functional\Rest;
use Drupal\Tests\rest\Functional\BcTimestampNormalizerUnixTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
use Drupal\aggregator\Entity\Feed;
abstract class FeedResourceTestBase extends EntityResourceTestBase {
use BcTimestampNormalizerUnixTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['aggregator'];
/**
* {@inheritdoc}
*/
public static $entityTypeId = 'aggregator_feed';
/**
* {@inheritdoc}
*/
protected static $patchProtectedFieldNames = [];
/**
* {@inheritdoc}
*/
protected static $uniqueFieldNames = ['url'];
/**
* {@inheritdoc}
*/
protected function setUpAuthorization($method) {
switch ($method) {
case 'GET':
$this->grantPermissionsToTestedRole(['access news feeds']);
break;
case 'POST':
case 'PATCH':
case 'DELETE':
$this->grantPermissionsToTestedRole(['administer news feeds']);
break;
}
}
/**
* {@inheritdoc}
*/
public function createEntity() {
$feed = Feed::create();
$feed->set('fid', 1)
->set('uuid', 'abcdefg')
->setTitle('Feed')
->setUrl('http://example.com/rss.xml')
->setDescription('Feed Resource Test 1')
->setRefreshRate(900)
->setLastCheckedTime(123456789)
->setQueuedTime(123456789)
->setWebsiteUrl('http://example.com')
->setImage('http://example.com/feed_logo')
->setHash('abcdefg')
->setEtag('hijklmn')
->setLastModified(123456789)
->save();
return $feed;
}
/**
* {@inheritdoc}
*/
protected function getExpectedNormalizedEntity() {
return [
'uuid' => [
[
'value' => 'abcdefg',
],
],
'fid' => [
[
'value' => 1,
],
],
'langcode' => [
[
'value' => 'en',
],
],
'url' => [
[
'value' => 'http://example.com/rss.xml',
],
],
'title' => [
[
'value' => 'Feed',
],
],
'refresh' => [
[
'value' => 900,
],
],
'checked' => [
$this->formatExpectedTimestampItemValues(123456789),
],
'queued' => [
$this->formatExpectedTimestampItemValues(123456789),
],
'link' => [
[
'value' => 'http://example.com',
],
],
'description' => [
[
'value' => 'Feed Resource Test 1',
],
],
'image' => [
[
'value' => 'http://example.com/feed_logo',
],
],
'hash' => [
[
'value' => 'abcdefg',
],
],
'etag' => [
[
'value' => 'hijklmn',
],
],
'modified' => [
$this->formatExpectedTimestampItemValues(123456789),
],
];
}
/**
* {@inheritdoc}
*/
protected function getNormalizedPostEntity() {
return [
'title' => [
[
'value' => 'Feed Resource Post Test',
],
],
'url' => [
[
'value' => 'http://example.com/feed',
],
],
'refresh' => [
[
'value' => 900,
],
],
'description' => [
[
'value' => 'Feed Resource Post Test Description',
],
],
];
}
/**
* {@inheritdoc}
*/
protected function getExpectedUnauthorizedAccessMessage($method) {
if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) {
return parent::getExpectedUnauthorizedAccessMessage($method);
}
switch ($method) {
case 'GET':
return "The 'access news feeds' permission is required.";
case 'POST':
case 'PATCH':
case 'DELETE':
return "The 'administer news feeds' permission is required.";
default:
return parent::getExpectedUnauthorizedAccessMessage($method);
}
}
}
<?php
namespace Drupal\Tests\rest\Functional\EntityResource\Feed;
namespace Drupal\Tests\aggregator\Functional\Rest;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
......
<?php
namespace Drupal\Tests\rest\Functional\EntityResource\Feed;
namespace Drupal\Tests\aggregator\Functional\Rest;
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
......
<?php
namespace Drupal\Tests\rest\Functional\EntityResource\Feed;
namespace Drupal\Tests\aggregator\Functional\Rest;
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
......
<?php
namespace Drupal\Tests\rest\Functional\EntityResource\Item;
namespace Drupal\Tests\aggregator\Functional\Rest;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
......
<?php
namespace Drupal\Tests\rest\Functional\EntityResource\Item;
namespace Drupal\Tests\aggregator\Functional\Rest;
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
......
<?php
namespace Drupal\Tests\rest\Functional\EntityResource\Item;
namespace Drupal\Tests\aggregator\Functional\Rest;
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
......
<?php
namespace Drupal\Tests\aggregator\Functional\Rest;
use Drupal\aggregator\Entity\Feed;
use Drupal\aggregator\Entity\Item;
use Drupal\Tests\rest\Functional\BcTimestampNormalizerUnixTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
/**
* ResourceTestBase for Item entity.
*/
abstract class ItemResourceTestBase extends EntityResourceTestBase {
use BcTimestampNormalizerUnixTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['aggregator'];
/**
* {@inheritdoc}
*/
protected static $entityTypeId = 'aggregator_item';
/**
* {@inheritdoc}
*/
protected static $patchProtectedFieldNames = [];
/**
* The Item entity.
*
* @var \Drupal\aggregator\ItemInterface
*/
protected $entity;
/**
* {@inheritdoc}
*/
protected function setUpAuthorization($method) {
switch ($method) {
case 'GET':
$this->grantPermissionsToTestedRole(['access news feeds']);
break;
case 'POST':
case 'PATCH':
case 'DELETE':
$this->grantPermissionsToTestedRole(['administer news feeds']);
break;
}
}
/**
* {@inheritdoc}
*/
protected function createEntity() {
// Create a "Camelids" feed.
$feed = Feed::create([
'title' => 'Camelids',
'url' => 'https://groups.drupal.org/not_used/167169',
'refresh' => 900,
'checked' => 1389919932,
'description' => 'Drupal Core Group feed',
]);
$feed->save();
// Create a "Llama" item.
$item = Item::create();
$item->setTitle('Llama')
->setFeedId($feed->id())
->setLink('https://www.drupal.org/')
->setPostedTime(123456789)
->save();
return $item;
}
/**
* {@inheritdoc}
*/
protected function createAnotherEntity() {
$entity = $this->entity->createDuplicate();
$entity->setLink('https://www.example.org/');
$label_key = $entity->getEntityType()->getKey('label');
if ($label_key) {
$entity->set($label_key, $entity->label() . '_dupe');
}
$entity->save();
return $entity;
}
/**
* {@inheritdoc}
*/
protected function getExpectedNormalizedEntity() {
$feed = Feed::load($this->entity->getFeedId());
return [
'iid' => [
[
'value' => 1,