From cc34cb8055821db244e9a916e7f31cca7ead115f Mon Sep 17 00:00:00 2001 From: effulgentsia <alex.bronstein@acquia.com> Date: Fri, 15 Sep 2017 12:49:39 -0700 Subject: [PATCH] Issue #2843776 by Wim Leers, vaplas: EntityResource: Provide comprehensive test coverage for EntityTestBundle entity --- .../EntityTestBundleHalJsonAnonTest.php | 32 ++++++++ .../EntityTestBundleHalJsonBasicAuthTest.php | 35 +++++++++ .../EntityTestBundleHalJsonCookieTest.php | 35 +++++++++ .../EntityTestBundleJsonAnonTest.php | 24 ++++++ .../EntityTestBundleJsonBasicAuthTest.php | 34 +++++++++ .../EntityTestBundleJsonCookieTest.php | 29 +++++++ .../EntityTestBundleResourceTestBase.php | 76 +++++++++++++++++++ 7 files changed, 265 insertions(+) create mode 100644 core/modules/hal/tests/src/Functional/EntityResource/EntityTestBundle/EntityTestBundleHalJsonAnonTest.php create mode 100644 core/modules/hal/tests/src/Functional/EntityResource/EntityTestBundle/EntityTestBundleHalJsonBasicAuthTest.php create mode 100644 core/modules/hal/tests/src/Functional/EntityResource/EntityTestBundle/EntityTestBundleHalJsonCookieTest.php create mode 100644 core/modules/rest/tests/src/Functional/EntityResource/EntityTestBundle/EntityTestBundleJsonAnonTest.php create mode 100644 core/modules/rest/tests/src/Functional/EntityResource/EntityTestBundle/EntityTestBundleJsonBasicAuthTest.php create mode 100644 core/modules/rest/tests/src/Functional/EntityResource/EntityTestBundle/EntityTestBundleJsonCookieTest.php create mode 100644 core/modules/rest/tests/src/Functional/EntityResource/EntityTestBundle/EntityTestBundleResourceTestBase.php diff --git a/core/modules/hal/tests/src/Functional/EntityResource/EntityTestBundle/EntityTestBundleHalJsonAnonTest.php b/core/modules/hal/tests/src/Functional/EntityResource/EntityTestBundle/EntityTestBundleHalJsonAnonTest.php new file mode 100644 index 000000000000..9e6bcb306502 --- /dev/null +++ b/core/modules/hal/tests/src/Functional/EntityResource/EntityTestBundle/EntityTestBundleHalJsonAnonTest.php @@ -0,0 +1,32 @@ +<?php + +namespace Drupal\Tests\hal\Functional\EntityResource\EntityTestBundle; + +use Drupal\Tests\hal\Functional\EntityResource\HalEntityNormalizationTrait; +use Drupal\Tests\rest\Functional\AnonResourceTestTrait; +use Drupal\Tests\rest\Functional\EntityResource\EntityTestBundle\EntityTestBundleResourceTestBase; + +/** + * @group hal + */ +class EntityTestBundleHalJsonAnonTest extends EntityTestBundleResourceTestBase { + + use HalEntityNormalizationTrait; + 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/EntityTestBundle/EntityTestBundleHalJsonBasicAuthTest.php b/core/modules/hal/tests/src/Functional/EntityResource/EntityTestBundle/EntityTestBundleHalJsonBasicAuthTest.php new file mode 100644 index 000000000000..09e5970890e5 --- /dev/null +++ b/core/modules/hal/tests/src/Functional/EntityResource/EntityTestBundle/EntityTestBundleHalJsonBasicAuthTest.php @@ -0,0 +1,35 @@ +<?php + +namespace Drupal\Tests\hal\Functional\EntityResource\EntityTestBundle; + +use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait; +use Drupal\Tests\rest\Functional\EntityResource\EntityTestBundle\EntityTestBundleResourceTestBase; + +/** + * @group hal + */ +class EntityTestBundleHalJsonBasicAuthTest extends EntityTestBundleResourceTestBase { + + use BasicAuthResourceTestTrait; + + /** + * {@inheritdoc} + */ + public static $modules = ['hal', 'basic_auth']; + + /** + * {@inheritdoc} + */ + protected static $auth = 'basic_auth'; + + /** + * {@inheritdoc} + */ + protected static $format = 'hal_json'; + + /** + * {@inheritdoc} + */ + protected static $mimeType = 'application/hal+json'; + +} diff --git a/core/modules/hal/tests/src/Functional/EntityResource/EntityTestBundle/EntityTestBundleHalJsonCookieTest.php b/core/modules/hal/tests/src/Functional/EntityResource/EntityTestBundle/EntityTestBundleHalJsonCookieTest.php new file mode 100644 index 000000000000..7f499fa01620 --- /dev/null +++ b/core/modules/hal/tests/src/Functional/EntityResource/EntityTestBundle/EntityTestBundleHalJsonCookieTest.php @@ -0,0 +1,35 @@ +<?php + +namespace Drupal\Tests\hal\Functional\EntityResource\EntityTestBundle; + +use Drupal\Tests\rest\Functional\CookieResourceTestTrait; +use Drupal\Tests\rest\Functional\EntityResource\EntityTestBundle\EntityTestBundleResourceTestBase; + +/** + * @group hal + */ +class EntityTestBundleHalJsonCookieTest extends EntityTestBundleResourceTestBase { + + use CookieResourceTestTrait; + + /** + * {@inheritdoc} + */ + public static $modules = ['hal']; + + /** + * {@inheritdoc} + */ + protected static $auth = 'cookie'; + + /** + * {@inheritdoc} + */ + protected static $format = 'hal_json'; + + /** + * {@inheritdoc} + */ + protected static $mimeType = 'application/hal+json'; + +} diff --git a/core/modules/rest/tests/src/Functional/EntityResource/EntityTestBundle/EntityTestBundleJsonAnonTest.php b/core/modules/rest/tests/src/Functional/EntityResource/EntityTestBundle/EntityTestBundleJsonAnonTest.php new file mode 100644 index 000000000000..1df26f3869c7 --- /dev/null +++ b/core/modules/rest/tests/src/Functional/EntityResource/EntityTestBundle/EntityTestBundleJsonAnonTest.php @@ -0,0 +1,24 @@ +<?php + +namespace Drupal\Tests\rest\Functional\EntityResource\EntityTestBundle; + +use Drupal\Tests\rest\Functional\AnonResourceTestTrait; + +/** + * @group rest + */ +class EntityTestBundleJsonAnonTest extends EntityTestBundleResourceTestBase { + + use AnonResourceTestTrait; + + /** + * {@inheritdoc} + */ + protected static $format = 'json'; + + /** + * {@inheritdoc} + */ + protected static $mimeType = 'application/json'; + +} diff --git a/core/modules/rest/tests/src/Functional/EntityResource/EntityTestBundle/EntityTestBundleJsonBasicAuthTest.php b/core/modules/rest/tests/src/Functional/EntityResource/EntityTestBundle/EntityTestBundleJsonBasicAuthTest.php new file mode 100644 index 000000000000..022080137947 --- /dev/null +++ b/core/modules/rest/tests/src/Functional/EntityResource/EntityTestBundle/EntityTestBundleJsonBasicAuthTest.php @@ -0,0 +1,34 @@ +<?php + +namespace Drupal\Tests\rest\Functional\EntityResource\EntityTestBundle; + +use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait; + +/** + * @group rest + */ +class EntityTestBundleJsonBasicAuthTest extends EntityTestBundleResourceTestBase { + + 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/EntityTestBundle/EntityTestBundleJsonCookieTest.php b/core/modules/rest/tests/src/Functional/EntityResource/EntityTestBundle/EntityTestBundleJsonCookieTest.php new file mode 100644 index 000000000000..56fecfd6b062 --- /dev/null +++ b/core/modules/rest/tests/src/Functional/EntityResource/EntityTestBundle/EntityTestBundleJsonCookieTest.php @@ -0,0 +1,29 @@ +<?php + +namespace Drupal\Tests\rest\Functional\EntityResource\EntityTestBundle; + +use Drupal\Tests\rest\Functional\CookieResourceTestTrait; + +/** + * @group rest + */ +class EntityTestBundleJsonCookieTest extends EntityTestBundleResourceTestBase { + + 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/EntityTestBundle/EntityTestBundleResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/EntityTestBundle/EntityTestBundleResourceTestBase.php new file mode 100644 index 000000000000..f43d877097cb --- /dev/null +++ b/core/modules/rest/tests/src/Functional/EntityResource/EntityTestBundle/EntityTestBundleResourceTestBase.php @@ -0,0 +1,76 @@ +<?php + +namespace Drupal\Tests\rest\Functional\EntityResource\EntityTestBundle; + +use Drupal\entity_test\Entity\EntityTestBundle; +use Drupal\Tests\rest\Functional\BcTimestampNormalizerUnixTestTrait; +use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase; + +abstract class EntityTestBundleResourceTestBase extends EntityResourceTestBase { + + use BcTimestampNormalizerUnixTestTrait; + + /** + * {@inheritdoc} + */ + public static $modules = ['entity_test']; + + /** + * {@inheritdoc} + */ + protected static $entityTypeId = 'entity_test_bundle'; + + /** + * {@inheritdoc} + */ + protected static $patchProtectedFieldNames = []; + + /** + * @var \Drupal\entity_test\Entity\EntityTestBundle + */ + protected $entity; + + /** + * {@inheritdoc} + */ + protected function setUpAuthorization($method) { + $this->grantPermissionsToTestedRole(['administer entity_test_bundle content']); + } + + /** + * {@inheritdoc} + */ + protected function createEntity() { + $entity_test_bundle = EntityTestBundle::create([ + 'id' => 'camelids', + 'label' => 'Camelids', + 'description' => 'Camelids are large, strictly herbivorous animals with slender necks and long legs.', + ]); + $entity_test_bundle->save(); + + return $entity_test_bundle; + } + + /** + * {@inheritdoc} + */ + protected function getExpectedNormalizedEntity() { + return [ + 'dependencies' => [], + 'description' => 'Camelids are large, strictly herbivorous animals with slender necks and long legs.', + 'id' => 'camelids', + 'label' => 'Camelids', + 'langcode' => 'en', + 'status' => TRUE, + 'uuid' => $this->entity->uuid(), + ]; + } + + /** + * {@inheritdoc} + */ + protected function getNormalizedPostEntity() { + // @todo Update in https://www.drupal.org/node/2300677. + } + +} -- GitLab