summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2017-03-27 08:15:12 (GMT)
committerAlex Pott2017-03-27 08:15:12 (GMT)
commit48261599246bb9369e79ae4ec4b11de6de01e5b8 (patch)
treecfcac9d9e35406b757f8bb7eab9ae6ba59659efd
parent885965f4e4787f167570f2e8b8cc3d840b4748cd (diff)
Issue #2843757 by vaplas, Wim Leers, alexpott: EntityResource: Provide comprehensive test coverage for FilterFormat entity
-rw-r--r--core/modules/filter/src/FilterFormatAccessControlHandler.php2
-rw-r--r--core/modules/hal/tests/src/Functional/EntityResource/FilterFormat/FilterFormatHalJsonAnonTest.php30
-rw-r--r--core/modules/hal/tests/src/Functional/EntityResource/FilterFormat/FilterFormatHalJsonBasicAuthTest.php35
-rw-r--r--core/modules/hal/tests/src/Functional/EntityResource/FilterFormat/FilterFormatHalJsonCookieTest.php35
-rw-r--r--core/modules/rest/tests/src/Functional/EntityResource/FilterFormat/FilterFormatJsonAnonTest.php24
-rw-r--r--core/modules/rest/tests/src/Functional/EntityResource/FilterFormat/FilterFormatJsonBasicAuthTest.php34
-rw-r--r--core/modules/rest/tests/src/Functional/EntityResource/FilterFormat/FilterFormatJsonCookieTest.php29
-rw-r--r--core/modules/rest/tests/src/Functional/EntityResource/FilterFormat/FilterFormatResourceTestBase.php88
8 files changed, 276 insertions, 1 deletions
diff --git a/core/modules/filter/src/FilterFormatAccessControlHandler.php b/core/modules/filter/src/FilterFormatAccessControlHandler.php
index 090944a..2dcb6dc 100644
--- a/core/modules/filter/src/FilterFormatAccessControlHandler.php
+++ b/core/modules/filter/src/FilterFormatAccessControlHandler.php
@@ -41,7 +41,7 @@ class FilterFormatAccessControlHandler extends EntityAccessControlHandler {
return AccessResult::forbidden();
}
- if (in_array($operation, ['disable', 'update'])) {
+ if (in_array($operation, ['disable', 'update', 'view'])) {
return parent::checkAccess($filter_format, $operation, $account);
}
diff --git a/core/modules/hal/tests/src/Functional/EntityResource/FilterFormat/FilterFormatHalJsonAnonTest.php b/core/modules/hal/tests/src/Functional/EntityResource/FilterFormat/FilterFormatHalJsonAnonTest.php
new file mode 100644
index 0000000..b0d1a61
--- /dev/null
+++ b/core/modules/hal/tests/src/Functional/EntityResource/FilterFormat/FilterFormatHalJsonAnonTest.php
@@ -0,0 +1,30 @@
+<?php
+
+namespace Drupal\Tests\hal\Functional\EntityResource\FilterFormat;
+
+use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
+use Drupal\Tests\rest\Functional\EntityResource\FilterFormat\FilterFormatResourceTestBase;
+
+/**
+ * @group hal
+ */
+class FilterFormatHalJsonAnonTest extends FilterFormatResourceTestBase {
+
+ use AnonResourceTestTrait;
+
+ /**
+ * {@inheritdoc}
+ */
+ public static $modules = ['hal'];
+
+ /**
+ * {@inheritdoc}
+ */
+ protected static $format = 'hal_json';
+
+ /**
+ * {@inheritdoc}
+ */
+ protected static $mimeType = 'application/hal+json';
+
+}
diff --git a/core/modules/hal/tests/src/Functional/EntityResource/FilterFormat/FilterFormatHalJsonBasicAuthTest.php b/core/modules/hal/tests/src/Functional/EntityResource/FilterFormat/FilterFormatHalJsonBasicAuthTest.php
new file mode 100644
index 0000000..fa40970
--- /dev/null
+++ b/core/modules/hal/tests/src/Functional/EntityResource/FilterFormat/FilterFormatHalJsonBasicAuthTest.php
@@ -0,0 +1,35 @@
+<?php
+
+namespace Drupal\Tests\hal\Functional\EntityResource\FilterFormat;
+
+use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
+use Drupal\Tests\rest\Functional\EntityResource\FilterFormat\FilterFormatResourceTestBase;
+
+/**
+ * @group hal
+ */
+class FilterFormatHalJsonBasicAuthTest extends FilterFormatResourceTestBase {
+
+ use BasicAuthResourceTestTrait;
+
+ /**
+ * {@inheritdoc}
+ */
+ public static $modules = ['hal', 'basic_auth'];
+
+ /**
+ * {@inheritdoc}
+ */
+ protected static $format = 'hal_json';
+
+ /**
+ * {@inheritdoc}
+ */
+ protected static $mimeType = 'application/hal+json';
+
+ /**
+ * {@inheritdoc}
+ */
+ protected static $auth = 'basic_auth';
+
+}
diff --git a/core/modules/hal/tests/src/Functional/EntityResource/FilterFormat/FilterFormatHalJsonCookieTest.php b/core/modules/hal/tests/src/Functional/EntityResource/FilterFormat/FilterFormatHalJsonCookieTest.php
new file mode 100644
index 0000000..1957793
--- /dev/null
+++ b/core/modules/hal/tests/src/Functional/EntityResource/FilterFormat/FilterFormatHalJsonCookieTest.php
@@ -0,0 +1,35 @@
+<?php
+
+namespace Drupal\Tests\hal\Functional\EntityResource\FilterFormat;
+
+use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
+use Drupal\Tests\rest\Functional\EntityResource\FilterFormat\FilterFormatResourceTestBase;
+
+/**
+ * @group hal
+ */
+class FilterFormatHalJsonCookieTest extends FilterFormatResourceTestBase {
+
+ use CookieResourceTestTrait;
+
+ /**
+ * {@inheritdoc}
+ */
+ public static $modules = ['hal'];
+
+ /**
+ * {@inheritdoc}
+ */
+ protected static $format = 'hal_json';
+
+ /**
+ * {@inheritdoc}
+ */
+ protected static $mimeType = 'application/hal+json';
+
+ /**
+ * {@inheritdoc}
+ */
+ protected static $auth = 'cookie';
+
+}
diff --git a/core/modules/rest/tests/src/Functional/EntityResource/FilterFormat/FilterFormatJsonAnonTest.php b/core/modules/rest/tests/src/Functional/EntityResource/FilterFormat/FilterFormatJsonAnonTest.php
new file mode 100644
index 0000000..60a24fb
--- /dev/null
+++ b/core/modules/rest/tests/src/Functional/EntityResource/FilterFormat/FilterFormatJsonAnonTest.php
@@ -0,0 +1,24 @@
+<?php
+
+namespace Drupal\Tests\rest\Functional\EntityResource\FilterFormat;
+
+use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
+
+/**
+ * @group rest
+ */
+class FilterFormatJsonAnonTest extends FilterFormatResourceTestBase {
+
+ use AnonResourceTestTrait;
+
+ /**
+ * {@inheritdoc}
+ */
+ protected static $format = 'json';
+
+ /**
+ * {@inheritdoc}
+ */
+ protected static $mimeType = 'application/json';
+
+}
diff --git a/core/modules/rest/tests/src/Functional/EntityResource/FilterFormat/FilterFormatJsonBasicAuthTest.php b/core/modules/rest/tests/src/Functional/EntityResource/FilterFormat/FilterFormatJsonBasicAuthTest.php
new file mode 100644
index 0000000..4e143c3
--- /dev/null
+++ b/core/modules/rest/tests/src/Functional/EntityResource/FilterFormat/FilterFormatJsonBasicAuthTest.php
@@ -0,0 +1,34 @@
+<?php
+
+namespace Drupal\Tests\rest\Functional\EntityResource\FilterFormat;
+
+use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
+
+/**
+ * @group rest
+ */
+class FilterFormatJsonBasicAuthTest extends FilterFormatResourceTestBase {
+
+ 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/FilterFormat/FilterFormatJsonCookieTest.php b/core/modules/rest/tests/src/Functional/EntityResource/FilterFormat/FilterFormatJsonCookieTest.php
new file mode 100644
index 0000000..73c0c22
--- /dev/null
+++ b/core/modules/rest/tests/src/Functional/EntityResource/FilterFormat/FilterFormatJsonCookieTest.php
@@ -0,0 +1,29 @@
+<?php
+
+namespace Drupal\Tests\rest\Functional\EntityResource\FilterFormat;
+
+use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
+
+/**
+ * @group rest
+ */
+class FilterFormatJsonCookieTest extends FilterFormatResourceTestBase {
+
+ 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/FilterFormat/FilterFormatResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/FilterFormat/FilterFormatResourceTestBase.php
new file mode 100644
index 0000000..4d65e00
--- /dev/null
+++ b/core/modules/rest/tests/src/Functional/EntityResource/FilterFormat/FilterFormatResourceTestBase.php
@@ -0,0 +1,88 @@
+<?php
+
+namespace Drupal\Tests\rest\Functional\EntityResource\FilterFormat;
+
+use Drupal\filter\Entity\FilterFormat;
+use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
+
+abstract class FilterFormatResourceTestBase extends EntityResourceTestBase {
+
+ /**
+ * {@inheritdoc}
+ */
+ public static $modules = [];
+
+ /**
+ * {@inheritdoc}
+ */
+ protected static $entityTypeId = 'filter_format';
+
+ /**
+ * @var \Drupal\filter\FilterFormatInterface
+ */
+ protected $entity;
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function setUpAuthorization($method) {
+ $this->grantPermissionsToTestedRole(['administer filters']);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function createEntity() {
+ $pablo_format = FilterFormat::create([
+ 'name' => 'Pablo Piccasso',
+ 'format' => 'pablo',
+ 'langcode' => 'es',
+ 'filters' => [
+ 'filter_html' => [
+ 'status' => TRUE,
+ 'settings' => [
+ 'allowed_html' => '<p> <a> <b> <lo>',
+ ],
+ ],
+ ],
+ ]);
+ $pablo_format->save();
+ return $pablo_format;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function getExpectedNormalizedEntity() {
+ return [
+ 'dependencies' => [],
+ 'filters' => [
+ 'filter_html' => [
+ 'id' => 'filter_html',
+ 'provider' => 'filter',
+ 'status' => TRUE,
+ 'weight' => -10,
+ 'settings' => [
+ 'allowed_html' => '<p> <a> <b> <lo>',
+ 'filter_html_help' => TRUE,
+ 'filter_html_nofollow' => FALSE,
+ ],
+ ],
+ ],
+ 'format' => 'pablo',
+ 'langcode' => 'es',
+ 'name' => 'Pablo Piccasso',
+ 'status' => TRUE,
+ 'uuid' => $this->entity->uuid(),
+ 'weight' => 0,
+ ];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function getNormalizedPostEntity() {
+ // @todo Update in https://www.drupal.org/node/2300677.
+ }
+
+}