src/Configuration/ResourceConfig.php | 11 ++++------- src/Configuration/ResourceManager.php | 2 -- .../Normalizer/JsonApiDocumentTopLevelNormalizerTest.php | 2 -- tests/src/Kernel/Resource/EntityResourceTest.php | 2 +- tests/src/Unit/Context/CurrentContextTest.php | 2 +- tests/src/Unit/Context/FieldResolverTest.php | 2 +- tests/src/Unit/Normalizer/ConfigEntityNormalizerTest.php | 2 +- .../Unit/Normalizer/EntityReferenceFieldNormalizerTest.php | 8 ++++---- .../Normalizer/JsonApiDocumentTopLevelNormalizerTest.php | 2 +- .../Normalizer/Value/DocumentRootNormalizerValueTest.php | 3 ++- .../Unit/Normalizer/Value/EntityNormalizerValueTest.php | 5 +++-- .../Value/RelationshipItemNormalizerValueTest.php | 14 +++++++------- .../Normalizer/Value/RelationshipNormalizerValueTest.php | 4 ++-- tests/src/Unit/Plugin/Deriver/ResourceDeriverTest.php | 10 +++++----- tests/src/Unit/RequestHandlerTest.php | 2 +- 15 files changed, 33 insertions(+), 38 deletions(-) diff --git a/src/Configuration/ResourceConfig.php b/src/Configuration/ResourceConfig.php index ec918bf..8a02d8b 100644 --- a/src/Configuration/ResourceConfig.php +++ b/src/Configuration/ResourceConfig.php @@ -92,19 +92,16 @@ class ResourceConfig implements ResourceConfigInterface { * An entity type ID. * @param string $bundle_id * A bundle ID. - * @param string $path - * The path at which this entity bundle will be made accessible. - * @param string $type_name - * The JSON API type. * @param string $deserialization_target_class * The deserialization target class. */ - public function __construct($entity_type_id, $bundle_id, $path, $type_name, $deserialization_target_class) { + public function __construct($entity_type_id, $bundle_id, $deserialization_target_class) { $this->entityTypeId = $entity_type_id; $this->bundleId = $bundle_id; - $this->path = $path; - $this->typeName = $type_name; $this->deserializationTargetClass = $deserialization_target_class; + + $this->typeName = sprintf('%s--%s', $this->entityTypeId, $this->bundleId); + $this->path= sprintf('/%s/%s', $this->entityTypeId, $this->bundleId); } } diff --git a/src/Configuration/ResourceManager.php b/src/Configuration/ResourceManager.php index 3e41cc0..983774a 100644 --- a/src/Configuration/ResourceManager.php +++ b/src/Configuration/ResourceManager.php @@ -61,8 +61,6 @@ class ResourceManager implements ResourceManagerInterface { $resource_config = new ResourceConfig( $entity_type_id, $bundle, - sprintf('/%s/%s', $entity_type_id, $bundle), - sprintf('%s--%s', $entity_type_id, $bundle), $this->entityTypeManager->getDefinition($entity_type_id)->getClass() ); return $resource_config; diff --git a/tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php b/tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php index c9f5bb7..2834006 100644 --- a/tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php +++ b/tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php @@ -564,8 +564,6 @@ class JsonApiDocumentTopLevelNormalizerTest extends JsonapiKernelTestBase { $resource_config = new ResourceConfig( $entity_type_id, $bundle_id, - 'foo', - sprintf('%s--%s', $entity_type_id, $bundle_id), $entity_type_manager->getDefinition($entity_type_id)->getClass() ); diff --git a/tests/src/Kernel/Resource/EntityResourceTest.php b/tests/src/Kernel/Resource/EntityResourceTest.php index 46d400c..e2a393f 100644 --- a/tests/src/Kernel/Resource/EntityResourceTest.php +++ b/tests/src/Kernel/Resource/EntityResourceTest.php @@ -808,7 +808,7 @@ class EntityResourceTest extends JsonapiKernelTestBase { $this->container->set('jsonapi.current_context', $current_context); return new EntityResource( - new ResourceConfig($entity_type_id, $bundle_id, NULL, NULL, NULL), + new ResourceConfig($entity_type_id, $bundle_id, NULL), $this->container->get('entity_type.manager'), $this->container->get('jsonapi.query_builder'), $this->container->get('entity_field.manager'), diff --git a/tests/src/Unit/Context/CurrentContextTest.php b/tests/src/Unit/Context/CurrentContextTest.php index 14c2f60..d143432 100644 --- a/tests/src/Unit/Context/CurrentContextTest.php +++ b/tests/src/Unit/Context/CurrentContextTest.php @@ -82,7 +82,7 @@ class CurrentContextTest extends UnitTestCase { // Create a mock for the ResourceManager service. $resource_prophecy = $this->prophesize(ResourceManagerInterface::CLASS); - $resource_config = new ResourceConfig('node', 'article', '/node/article', 'node--article', NodeInterface::class); + $resource_config = new ResourceConfig('node', 'article', NodeInterface::class); $resource_prophecy->get('node', 'article')->willReturn($resource_config); $this->resourceManager = $resource_prophecy->reveal(); diff --git a/tests/src/Unit/Context/FieldResolverTest.php b/tests/src/Unit/Context/FieldResolverTest.php index 07ee08a..cf141b2 100644 --- a/tests/src/Unit/Context/FieldResolverTest.php +++ b/tests/src/Unit/Context/FieldResolverTest.php @@ -40,7 +40,7 @@ class FieldResolverTest extends UnitTestCase { public function setUp() { $current_context = $this->prophesize(CurrentContextInterface::class); - $resource_config = new ResourceConfig('lorem', NULL, NULL, NULL, NULL); + $resource_config = new ResourceConfig('lorem', $this->randomMachineName(), NULL); $current_context->getResourceConfig()->willReturn($resource_config); $this->currentContext = $current_context->reveal(); diff --git a/tests/src/Unit/Normalizer/ConfigEntityNormalizerTest.php b/tests/src/Unit/Normalizer/ConfigEntityNormalizerTest.php index 56f5b18..982d889 100644 --- a/tests/src/Unit/Normalizer/ConfigEntityNormalizerTest.php +++ b/tests/src/Unit/Normalizer/ConfigEntityNormalizerTest.php @@ -42,7 +42,7 @@ class ConfigEntityNormalizerTest extends UnitTestCase { $resource_manager = $this->prophesize(ResourceManagerInterface::class); $resource_manager->get(Argument::type('string'), Argument::type('string')) - ->willReturn(new ResourceConfig('dolor', 'sid', NULL, NULL, NULL)); + ->willReturn(new ResourceConfig('dolor', 'sid', NULL)); $current_context_manager->getResourceManager()->willReturn( $resource_manager->reveal() ); diff --git a/tests/src/Unit/Normalizer/EntityReferenceFieldNormalizerTest.php b/tests/src/Unit/Normalizer/EntityReferenceFieldNormalizerTest.php index 0901d62..7324340 100644 --- a/tests/src/Unit/Normalizer/EntityReferenceFieldNormalizerTest.php +++ b/tests/src/Unit/Normalizer/EntityReferenceFieldNormalizerTest.php @@ -75,7 +75,7 @@ class EntityReferenceFieldNormalizerTest extends UnitTestCase { )->willReturnArgument(2); $resource_manager = $this->prophesize(ResourceManagerInterface::class); $resource_manager->get('fake_entity_type', 'dummy_bundle') - ->willReturn(new ResourceConfig('lorem', 'dummy_bundle', NULL, 'lorem', NULL)); + ->willReturn(new ResourceConfig('lorem', 'dummy_bundle', NULL)); $entity_storage = $this->prophesize(EntityStorageInterface::class); $entity = $this->prophesize(EntityInterface::class); @@ -101,7 +101,7 @@ class EntityReferenceFieldNormalizerTest extends UnitTestCase { * @dataProvider denormalizeProvider */ public function testDenormalize($input, $field_name, $expected) { - $resource_config = new ResourceConfig('fake_entity_type', 'dummy_bundle', NULL, NULL, NULL); + $resource_config = new ResourceConfig('fake_entity_type', 'dummy_bundle', NULL); $entity = $this->prophesize(FieldableEntityInterface::class); $context = [ 'resource_config' => $resource_config, @@ -121,7 +121,7 @@ class EntityReferenceFieldNormalizerTest extends UnitTestCase { public function denormalizeProvider() { return [ [ - ['data' => [['type' => 'lorem', 'id' => '4e6cb61d-4f04-437f-99fe-42c002393658']]], + ['data' => [['type' => 'lorem--dummy_bundle', 'id' => '4e6cb61d-4f04-437f-99fe-42c002393658']]], 'field_dummy', [['bunny' => 42]], ], @@ -144,7 +144,7 @@ class EntityReferenceFieldNormalizerTest extends UnitTestCase { * @dataProvider denormalizeInvalidResourceProvider */ public function testDenormalizeInvalidResource($data, $field_name) { - $resource_config = new ResourceConfig('fake_entity_type', 'dummy_bundle', NULL, NULL, NULL); + $resource_config = new ResourceConfig('fake_entity_type', 'dummy_bundle', NULL); $context = [ 'resource_config' => $resource_config, 'related' => $field_name, diff --git a/tests/src/Unit/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php b/tests/src/Unit/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php index ee3cca3..541e549 100644 --- a/tests/src/Unit/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php +++ b/tests/src/Unit/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php @@ -95,7 +95,7 @@ class JsonApiDocumentTopLevelNormalizerTest extends UnitTestCase { * @dataProvider denormalizeProvider */ public function testDenormalize($input, $expected) { - $resource_config = new ResourceConfig($this->randomMachineName(), $this->randomMachineName(), NULL, NULL, FieldableEntityInterface::class); + $resource_config = new ResourceConfig($this->randomMachineName(), $this->randomMachineName(), FieldableEntityInterface::class); $context = [ 'resource_config' => $resource_config, ]; diff --git a/tests/src/Unit/Normalizer/Value/DocumentRootNormalizerValueTest.php b/tests/src/Unit/Normalizer/Value/DocumentRootNormalizerValueTest.php index 3944e1b..72ffb33 100644 --- a/tests/src/Unit/Normalizer/Value/DocumentRootNormalizerValueTest.php +++ b/tests/src/Unit/Normalizer/Value/DocumentRootNormalizerValueTest.php @@ -10,6 +10,7 @@ use Drupal\jsonapi\Normalizer\Value\DocumentRootNormalizerValue; use Drupal\jsonapi\Normalizer\Value\DocumentRootNormalizerValueInterface; use Drupal\jsonapi\Normalizer\Value\RelationshipNormalizerValueInterface; use Drupal\jsonapi\Normalizer\Value\FieldNormalizerValueInterface; +use Drupal\node\NodeInterface; use Drupal\Tests\UnitTestCase; use Prophecy\Argument; @@ -75,7 +76,7 @@ class DocumentRootNormalizerValueTest extends UnitTestCase{ $field2->getIncludes()->willReturn(array_map(function ($included_item) { return $included_item->reveal(); }, $included)); - $context = ['resource_config' => new ResourceConfig(NULL, NULL, NULL, 'node', NULL)]; + $context = ['resource_config' => new ResourceConfig('node', 'article', NodeInterface::class)]; $entity = $this->prophesize(EntityInterface::class); $entity->id()->willReturn(1); $entity->isNew()->willReturn(FALSE); diff --git a/tests/src/Unit/Normalizer/Value/EntityNormalizerValueTest.php b/tests/src/Unit/Normalizer/Value/EntityNormalizerValueTest.php index 630cba3..7b5e4c9 100644 --- a/tests/src/Unit/Normalizer/Value/EntityNormalizerValueTest.php +++ b/tests/src/Unit/Normalizer/Value/EntityNormalizerValueTest.php @@ -13,6 +13,7 @@ use Drupal\jsonapi\Normalizer\Value\EntityNormalizerValueInterface; use Drupal\jsonapi\Normalizer\Value\DocumentRootNormalizerValueInterface; use Drupal\jsonapi\Normalizer\Value\RelationshipNormalizerValueInterface; use Drupal\jsonapi\Normalizer\Value\FieldNormalizerValueInterface; +use Drupal\node\NodeInterface; use Drupal\Tests\UnitTestCase; use Prophecy\Argument; @@ -78,7 +79,7 @@ class EntityNormalizerValueTest extends UnitTestCase { $field2->getIncludes()->willReturn(array_map(function ($included_item) { return $included_item->reveal(); }, $included)); - $context = ['resource_config' => new ResourceConfig(NULL, NULL, NULL, 'node', NULL)]; + $context = ['resource_config' => new ResourceConfig('node', 'article', NodeInterface::class)]; $entity = $this->prophesize(EntityInterface::class); $entity->uuid()->willReturn('248150b2-79a2-4b44-9f49-bf405a51414a'); $entity->isNew()->willReturn(FALSE); @@ -109,7 +110,7 @@ class EntityNormalizerValueTest extends UnitTestCase { */ public function testRasterizeValue() { $this->assertEquals([ - 'type' => 'node', + 'type' => 'node--article', 'id' => '248150b2-79a2-4b44-9f49-bf405a51414a', 'attributes' => ['title' => 'dummy_title'], 'relationships' => [ diff --git a/tests/src/Unit/Normalizer/Value/RelationshipItemNormalizerValueTest.php b/tests/src/Unit/Normalizer/Value/RelationshipItemNormalizerValueTest.php index ac80633..806b706 100644 --- a/tests/src/Unit/Normalizer/Value/RelationshipItemNormalizerValueTest.php +++ b/tests/src/Unit/Normalizer/Value/RelationshipItemNormalizerValueTest.php @@ -20,8 +20,8 @@ class RelationshipItemNormalizerValueTest extends UnitTestCase { * @covers ::rasterizeValue * @dataProvider rasterizeValueProvider */ - public function testRasterizeValue($values, $resource_type, $expected) { - $object = new RelationshipItemNormalizerValue($values, new ResourceConfig(NULL, NULL, NULL, $resource_type, NULL)); + public function testRasterizeValue($values, $entity_type_id, $bundle, $expected) { + $object = new RelationshipItemNormalizerValue($values, new ResourceConfig($entity_type_id, $bundle, NULL)); $this->assertEquals($expected, $object->rasterizeValue()); } @@ -30,11 +30,11 @@ class RelationshipItemNormalizerValueTest extends UnitTestCase { */ public function rasterizeValueProvider() { return [ - [['target_id' => 1], 'node', ['type' => 'node', 'id' => 1]], - [['value' => 1], 'node', ['type' => 'node', 'id' => 1]], - [[1], 'node', ['type' => 'node', 'id' => 1]], - [[], 'node', []], - [[NULL], 'node', NULL], + [['target_id' => 1], 'node', 'article', ['type' => 'node--article', 'id' => 1]], + [['value' => 1], 'node', 'page', ['type' => 'node--page', 'id' => 1]], + [[1], 'node', 'foo', ['type' => 'node--foo', 'id' => 1]], + [[], 'node', 'bar', []], + [[NULL], 'node', 'baz', NULL], ]; } } diff --git a/tests/src/Unit/Normalizer/Value/RelationshipNormalizerValueTest.php b/tests/src/Unit/Normalizer/Value/RelationshipNormalizerValueTest.php index 0456f7f..aa12d36 100644 --- a/tests/src/Unit/Normalizer/Value/RelationshipNormalizerValueTest.php +++ b/tests/src/Unit/Normalizer/Value/RelationshipNormalizerValueTest.php @@ -32,7 +32,7 @@ class RelationshipNormalizerValueTest extends UnitTestCase { $object = new RelationshipNormalizerValue($values, $cardinality, [ 'link_manager' => $link_manager->reveal(), 'host_entity_id' => 'lorem', - 'resource_config' => new ResourceConfig(NULL, NULL, NULL, NULL, NULL), + 'resource_config' => new ResourceConfig($this->randomMachineName(), $this->randomMachineName(), NULL), 'field_name' => 'ipsum', ]); $this->assertEquals($expected, $object->rasterizeValue()); @@ -86,7 +86,7 @@ class RelationshipNormalizerValueTest extends UnitTestCase { $object = new RelationshipNormalizerValue([$uid1->reveal()], 1, [ 'link_manager' => $link_manager->reveal(), 'host_entity_id' => 'lorem', - 'resource_config' => new ResourceConfig(NULL, NULL, NULL, NULL, NULL), + 'resource_config' => new ResourceConfig($this->randomMachineName(), $this->randomMachineName(), NULL), 'field_name' => 'ipsum', ]); $object->rasterizeValue(); diff --git a/tests/src/Unit/Plugin/Deriver/ResourceDeriverTest.php b/tests/src/Unit/Plugin/Deriver/ResourceDeriverTest.php index e26b5ec..d52530b 100644 --- a/tests/src/Unit/Plugin/Deriver/ResourceDeriverTest.php +++ b/tests/src/Unit/Plugin/Deriver/ResourceDeriverTest.php @@ -37,7 +37,7 @@ class ResourceDeriverTest extends UnitTestCase { $resource_manager = $this->prophesize(ResourceManagerInterface::class); // Create some resource mocks for the manager. - $resource_manager->all()->willReturn([new ResourceConfig('entity_type_1', 'bundle_1_1', '/entity_type_1/bundle_path_1', 'resource_type_1', EntityInterface::class)]); + $resource_manager->all()->willReturn([new ResourceConfig('entity_type_1', 'bundle_1_1', EntityInterface::class)]); $resource_manager->hasBundle(Argument::type('string'))->willReturn(FALSE); $container = $this->prophesize(ContainerInterface::class); @@ -50,14 +50,14 @@ class ResourceDeriverTest extends UnitTestCase { * @covers ::getDerivativeDefinitions */ public function testGetDerivativeDefinitions() { - $expected = ['jsonapi.resource_type_1' => [ - 'id' => 'jsonapi.resource_type_1', + $expected = ['jsonapi.entity_type_1--bundle_1_1' => [ + 'id' => 'jsonapi.entity_type_1--bundle_1_1', 'entityType' => 'entity_type_1', 'bundle' => 'bundle_1_1', 'hasBundle' => FALSE, - 'type' => 'resource_type_1', + 'type' => 'entity_type_1--bundle_1_1', 'data' => [ - 'partialPath' => '/entity_type_1/bundle_path_1', + 'partialPath' => '/entity_type_1/bundle_1_1', ], 'permission' => 'access content', 'controller' => '\\Drupal\\jsonapi\\RequestHandler::handle', diff --git a/tests/src/Unit/RequestHandlerTest.php b/tests/src/Unit/RequestHandlerTest.php index e5e4ecb..48d9a97 100644 --- a/tests/src/Unit/RequestHandlerTest.php +++ b/tests/src/Unit/RequestHandlerTest.php @@ -45,7 +45,7 @@ class RequestHandlerTest extends UnitTestCase { $serializer->serialize(Argument::any(), Argument::any(), Argument::any()) ->willReturn('{"errors":[{"status":422,"message":"Foo"}]}'); $current_context = $this->prophesize(CurrentContextInterface::class); - $resource_config = new ResourceConfig(NULL, NULL, NULL, NULL, NULL); + $resource_config = new ResourceConfig($this->randomMachineName(), $this->randomMachineName(), NULL); $current_context->getResourceConfig()->willReturn($resource_config); try { $request_handler->deserializeBody(