summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2017-04-18 17:52:39 (GMT)
committerAlex Pott2017-04-18 17:52:39 (GMT)
commit2dc6d91d609ee76a3d463eedcb9eba0903c94580 (patch)
treee81f88e8edfdb7794081ea787c81ba170612785c
parent5875eb523c22dd9eaf28cda797bb6ebc0ff396dd (diff)
Issue #2843754 by rogierbom, Wim Leers, gaurav.kapoor, vaplas: EntityResource: Provide comprehensive test coverage for Feed entity
-rw-r--r--core/modules/hal/tests/src/Functional/EntityResource/Feed/FeedHalJsonAnonTest.php19
-rw-r--r--core/modules/hal/tests/src/Functional/EntityResource/Feed/FeedHalJsonBasicAuthTest.php24
-rw-r--r--core/modules/hal/tests/src/Functional/EntityResource/Feed/FeedHalJsonCookieTest.php19
-rw-r--r--core/modules/hal/tests/src/Functional/EntityResource/Feed/FeedHalJsonTestBase.php60
-rw-r--r--core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php2
-rw-r--r--core/modules/rest/tests/src/Functional/EntityResource/Feed/FeedJsonAnonTest.php24
-rw-r--r--core/modules/rest/tests/src/Functional/EntityResource/Feed/FeedJsonBasicAuthTest.php34
-rw-r--r--core/modules/rest/tests/src/Functional/EntityResource/Feed/FeedJsonCookieTest.php29
-rw-r--r--core/modules/rest/tests/src/Functional/EntityResource/Feed/FeedResourceTestBase.php185
9 files changed, 396 insertions, 0 deletions
diff --git a/core/modules/hal/tests/src/Functional/EntityResource/Feed/FeedHalJsonAnonTest.php b/core/modules/hal/tests/src/Functional/EntityResource/Feed/FeedHalJsonAnonTest.php
new file mode 100644
index 0000000..293b7e4
--- /dev/null
+++ b/core/modules/hal/tests/src/Functional/EntityResource/Feed/FeedHalJsonAnonTest.php
@@ -0,0 +1,19 @@
+<?php
+
+namespace Drupal\Tests\hal\Functional\EntityResource\Feed;
+
+use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
+
+/**
+ * @group hal
+ */
+class FeedHalJsonAnonTest extends FeedHalJsonTestBase {
+
+ use AnonResourceTestTrait;
+
+ /**
+ * {@inheritdoc}
+ */
+ protected static $mimeType = 'application/hal+json';
+
+}
diff --git a/core/modules/hal/tests/src/Functional/EntityResource/Feed/FeedHalJsonBasicAuthTest.php b/core/modules/hal/tests/src/Functional/EntityResource/Feed/FeedHalJsonBasicAuthTest.php
new file mode 100644
index 0000000..c3f91a7
--- /dev/null
+++ b/core/modules/hal/tests/src/Functional/EntityResource/Feed/FeedHalJsonBasicAuthTest.php
@@ -0,0 +1,24 @@
+<?php
+
+namespace Drupal\Tests\hal\Functional\EntityResource\Feed;
+
+use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
+
+/**
+ * @group hal
+ */
+class FeedHalJsonBasicAuthTest extends FeedHalJsonTestBase {
+
+ use BasicAuthResourceTestTrait;
+
+ /**
+ * {@inheritdoc}
+ */
+ public static $modules = ['basic_auth'];
+
+ /**
+ * {@inheritdoc}
+ */
+ protected static $auth = 'basic_auth';
+
+}
diff --git a/core/modules/hal/tests/src/Functional/EntityResource/Feed/FeedHalJsonCookieTest.php b/core/modules/hal/tests/src/Functional/EntityResource/Feed/FeedHalJsonCookieTest.php
new file mode 100644
index 0000000..fb4d64e
--- /dev/null
+++ b/core/modules/hal/tests/src/Functional/EntityResource/Feed/FeedHalJsonCookieTest.php
@@ -0,0 +1,19 @@
+<?php
+
+namespace Drupal\Tests\hal\Functional\EntityResource\Feed;
+
+use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
+
+/**
+ * @group hal
+ */
+class FeedHalJsonCookieTest extends FeedHalJsonTestBase {
+
+ use CookieResourceTestTrait;
+
+ /**
+ * {@inheritdoc}
+ */
+ protected static $auth = 'cookie';
+
+}
diff --git a/core/modules/hal/tests/src/Functional/EntityResource/Feed/FeedHalJsonTestBase.php b/core/modules/hal/tests/src/Functional/EntityResource/Feed/FeedHalJsonTestBase.php
new file mode 100644
index 0000000..4318132
--- /dev/null
+++ b/core/modules/hal/tests/src/Functional/EntityResource/Feed/FeedHalJsonTestBase.php
@@ -0,0 +1,60 @@
+<?php
+
+namespace Drupal\Tests\hal\Functional\EntityResource\Feed;
+
+use Drupal\Tests\rest\Functional\EntityResource\Feed\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'
+ ],
+ ],
+ ];
+ }
+
+}
diff --git a/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php
index 80d8a06..a55ae92 100644
--- a/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php
+++ b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php
@@ -757,6 +757,8 @@ abstract class EntityResourceTestBase extends ResourceTestBase {
// 201 for well-formed request.
+ // Delete the first created entity in case there is a uniqueness constraint.
+ $this->entityStorage->load(static::$firstCreatedEntityId)->delete();
$response = $this->request('POST', $url, $request_options);
$this->assertResourceResponse(201, FALSE, $response);
if ($has_canonical_url) {
diff --git a/core/modules/rest/tests/src/Functional/EntityResource/Feed/FeedJsonAnonTest.php b/core/modules/rest/tests/src/Functional/EntityResource/Feed/FeedJsonAnonTest.php
new file mode 100644
index 0000000..a4b8e0d
--- /dev/null
+++ b/core/modules/rest/tests/src/Functional/EntityResource/Feed/FeedJsonAnonTest.php
@@ -0,0 +1,24 @@
+<?php
+
+namespace Drupal\Tests\rest\Functional\EntityResource\Feed;
+
+use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
+
+/**
+ * @group rest
+ */
+class FeedJsonAnonTest extends FeedResourceTestBase {
+
+ use AnonResourceTestTrait;
+
+ /**
+ * {@inheritdoc}
+ */
+ protected static $format = 'json';
+
+ /**
+ * {@inheritdoc}
+ */
+ protected static $mimeType = 'application/json';
+
+}
diff --git a/core/modules/rest/tests/src/Functional/EntityResource/Feed/FeedJsonBasicAuthTest.php b/core/modules/rest/tests/src/Functional/EntityResource/Feed/FeedJsonBasicAuthTest.php
new file mode 100644
index 0000000..e5685c9
--- /dev/null
+++ b/core/modules/rest/tests/src/Functional/EntityResource/Feed/FeedJsonBasicAuthTest.php
@@ -0,0 +1,34 @@
+<?php
+
+namespace Drupal\Tests\rest\Functional\EntityResource\Feed;
+
+use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
+
+/**
+ * @group rest
+ */
+class FeedJsonBasicAuthTest extends FeedResourceTestBase {
+
+ use BasicAuthResourceTestTrait;
+
+ /**
+ * {@inheritdoc}
+ */
+ public static $modules = ['basic_auth'];
+
+ /**
+ * {@inheritdoc}
+ */
+ protected static $format = 'json';
+
+ /**
+ * {@inheritdoc}
+ */
+ protected static $mimeType = 'application/json';
+
+ /**
+ * {@inheritdoc}
+ */
+ protected static $auth = 'basic_auth';
+
+}
diff --git a/core/modules/rest/tests/src/Functional/EntityResource/Feed/FeedJsonCookieTest.php b/core/modules/rest/tests/src/Functional/EntityResource/Feed/FeedJsonCookieTest.php
new file mode 100644
index 0000000..7c1cc9f8
--- /dev/null
+++ b/core/modules/rest/tests/src/Functional/EntityResource/Feed/FeedJsonCookieTest.php
@@ -0,0 +1,29 @@
+<?php
+
+namespace Drupal\Tests\rest\Functional\EntityResource\Feed;
+
+use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
+
+/**
+ * @group rest
+ */
+class FeedJsonCookieTest extends FeedResourceTestBase {
+
+ use CookieResourceTestTrait;
+
+ /**
+ * {@inheritdoc}
+ */
+ protected static $format = 'json';
+
+ /**
+ * {@inheritdoc}
+ */
+ protected static $mimeType = 'application/json';
+
+ /**
+ * {@inheritdoc}
+ */
+ protected static $auth = 'cookie';
+
+}
diff --git a/core/modules/rest/tests/src/Functional/EntityResource/Feed/FeedResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/Feed/FeedResourceTestBase.php
new file mode 100644
index 0000000..f15a5e0
--- /dev/null
+++ b/core/modules/rest/tests/src/Functional/EntityResource/Feed/FeedResourceTestBase.php
@@ -0,0 +1,185 @@
+<?php
+
+namespace Drupal\Tests\rest\Functional\EntityResource\Feed;
+
+use Drupal\Tests\rest\Functional\EntityResource\EntityTest\EntityTestResourceTestBase;
+use Drupal\aggregator\Entity\Feed;
+
+abstract class FeedResourceTestBase extends EntityTestResourceTestBase {
+
+ /**
+ * {@inheritdoc}
+ */
+ public static $modules = ['aggregator'];
+
+ /**
+ * {@inheritdoc}
+ */
+ public static $entityTypeId = 'aggregator_feed';
+
+ /**
+ * {@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' => [
+ [
+ 'value' => 123456789
+ ]
+ ],
+ 'queued' => [
+ [
+ 'value' => 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' => [
+ [
+ 'value' => 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);
+ }
+ }
+
+}