diff --git a/src/Configuration/ResourceManager.php b/src/Configuration/ResourceManager.php index 7d0dd7d..cc3fc9f 100644 --- a/src/Configuration/ResourceManager.php +++ b/src/Configuration/ResourceManager.php @@ -73,7 +73,7 @@ class ResourceManager implements ResourceManagerInterface { $resource_config->setEntityTypeId($entity_type_id); $resource_config->setBundleId($bundle); $resource_config->setPath(sprintf('/%s/%s', $entity_type_id, $bundle)); - $resource_config->setTypeName($bundle); + $resource_config->setTypeName(sprintf('%s--%s', $entity_type_id, $bundle)); return $resource_config; }, array_keys($this->bundleManager->getBundleInfo($entity_type_id)))); } diff --git a/tests/src/Kernel/Configuration/ResourceManagerTest.php b/tests/src/Kernel/Configuration/ResourceManagerTest.php index e16dd13..2fa8b99 100644 --- a/tests/src/Kernel/Configuration/ResourceManagerTest.php +++ b/tests/src/Kernel/Configuration/ResourceManagerTest.php @@ -78,17 +78,31 @@ class ResourceManagerTest extends KernelTestBase { /** * @covers ::get + * @dataProvider getProvider */ - public function testGet() { + public function testGet($entity_type_id, $bundle_id, $entity_class) { // Make sure that there are resources being created. - $resource_config = $this->resourceManager->get('node', 'article'); + $resource_config = $this->resourceManager->get($entity_type_id, $bundle_id); $this->assertInstanceOf(ResourceConfigInterface::class, $resource_config); - $this->assertSame('Drupal\node\Entity\Node', $resource_config->getDeserializationTargetClass()); - $this->assertSame('node', $resource_config->getEntityTypeId()); - $this->assertSame('article', $resource_config->getBundleId()); + $this->assertSame($entity_class, $resource_config->getDeserializationTargetClass()); + $this->assertSame($entity_type_id, $resource_config->getEntityTypeId()); + $this->assertSame($bundle_id, $resource_config->getBundleId()); $this->assertNotEmpty($resource_config->getGlobalConfig()); - $this->assertSame('/node/article', $resource_config->getPath()); - $this->assertSame('article', $resource_config->getTypeName()); + $this->assertSame('/' . $entity_type_id . '/' . $bundle_id, $resource_config->getPath()); + $this->assertSame($entity_type_id . '--' . $bundle_id, $resource_config->getTypeName()); + } + + /** + * Data provider for testGet. + * + * @returns array + * The data for the test method. + */ + public function getProvider() { + return [ + ['node', 'article', 'Drupal\node\Entity\Node'], + ['node_type', 'node_type', 'Drupal\node\Entity\NodeType'], + ]; } } diff --git a/tests/src/Kernel/Normalizer/DocumentRootNormalizerTest.php b/tests/src/Kernel/Normalizer/DocumentRootNormalizerTest.php index 64d5dbb..6d7af6b 100644 --- a/tests/src/Kernel/Normalizer/DocumentRootNormalizerTest.php +++ b/tests/src/Kernel/Normalizer/DocumentRootNormalizerTest.php @@ -115,21 +115,21 @@ class DocumentRootNormalizerTest extends KernelTestBase { $request = $this->prophesize(Request::class); $query = $this->prophesize(ParameterBag::class); $query->get('fields')->willReturn([ - 'article' => 'title,type,uid', - 'user' => 'name', + 'node--article' => 'title,type,uid', + 'user--user' => 'name', ]); $query->get('include')->willReturn('uid'); $query->getIterator()->willReturn(new \ArrayIterator()); $request->query = $query->reveal(); $route = $this->prophesize(Route::class); - $route->getPath()->willReturn('/node/{node}'); + $route->getPath()->willReturn('/node/article/{node}'); $route->getRequirement('_entity_type')->willReturn('node'); $route->getRequirement('_bundle')->willReturn('article'); $request->get(RouteObjectInterface::ROUTE_OBJECT)->willReturn($route->reveal()); $document_wrapper = $this->prophesize(DocumentWrapper::class); $document_wrapper->getData()->willReturn($this->node); $resource_config = $this->prophesize(ResourceConfigInterface::CLASS); - $resource_config->getTypeName()->willReturn('article'); + $resource_config->getTypeName()->willReturn('node--article'); // Make sure the route contains the entity type and bundle. $current_context = $this->container->get('jsonapi.current_context'); @@ -152,7 +152,7 @@ class DocumentRootNormalizerTest extends KernelTestBase { $this->assertEquals($normalized['data']['id'], 1); $this->assertSame([ 'data' => [ - 'type' => 'node_type', + 'type' => 'node_type--node_type', 'id' => 'article', ], 'links' => [ @@ -161,10 +161,10 @@ class DocumentRootNormalizerTest extends KernelTestBase { ], ], $normalized['data']['relationships']['type']); $this->assertTrue(!isset($normalized['data']['attributes']['created'])); - $this->assertSame('article', $normalized['data']['type']); + $this->assertSame('node--article', $normalized['data']['type']); $this->assertEquals([ 'data' => [ - 'type' => 'user', + 'type' => 'user--user', 'id' => $this->user->id(), ], 'links' => [ @@ -173,7 +173,7 @@ class DocumentRootNormalizerTest extends KernelTestBase { ], ], $normalized['data']['relationships']['uid']); $this->assertEquals($this->user->id(), $normalized['included'][0]['data']['id']); - $this->assertEquals('user', $normalized['included'][0]['data']['type']); + $this->assertEquals('user--user', $normalized['included'][0]['data']['type']); $this->assertEquals($this->user->label(), $normalized['included'][0]['data']['attributes']['name']); $this->assertTrue(!isset($normalized['included'][0]['data']['attributes']['created'])); } @@ -185,20 +185,20 @@ class DocumentRootNormalizerTest extends KernelTestBase { $request = $this->prophesize(Request::class); $query = $this->prophesize(ParameterBag::class); $query->get('fields')->willReturn([ - 'node_type' => 'uuid,display_submitted', + 'node_type--node_type' => 'uuid,display_submitted', ]); $query->get('include')->willReturn(NULL); $query->getIterator()->willReturn(new \ArrayIterator()); $request->query = $query->reveal(); $route = $this->prophesize(Route::class); - $route->getPath()->willReturn('/node_type/{node_type}'); + $route->getPath()->willReturn('/node_type/node_type/{node_type}'); $route->getRequirement('_entity_type')->willReturn('node'); $route->getRequirement('_bundle')->willReturn('article'); $request->get(RouteObjectInterface::ROUTE_OBJECT)->willReturn($route->reveal()); $document_wrapper = $this->prophesize(DocumentWrapper::class); $document_wrapper->getData()->willReturn($this->nodeType); $resource_config = $this->prophesize(ResourceConfigInterface::CLASS); - $resource_config->getTypeName()->willReturn('node_type'); + $resource_config->getTypeName()->willReturn('node_type--node_type'); // Make sure the route contains the entity type and bundle. $current_context = $this->container->get('jsonapi.current_context'); @@ -217,7 +217,7 @@ class DocumentRootNormalizerTest extends KernelTestBase { $this->assertTrue(!empty($normalized['data']['attributes']['uuid'])); $this->assertSame($normalized['data']['attributes']['display_submitted'], TRUE); $this->assertSame($normalized['data']['id'], 'article'); - $this->assertSame($normalized['data']['type'], 'node_type'); + $this->assertSame($normalized['data']['type'], 'node_type--node_type'); } /** @@ -229,13 +229,13 @@ class DocumentRootNormalizerTest extends KernelTestBase { $payload = '{"type":"article", "data":{"attributes":{"title":"Testing article"}}}'; $request = $this->prophesize(Request::class); $route = $this->prophesize(Route::class); - $route->getPath()->willReturn('/article'); + $route->getPath()->willReturn('/node/article'); $route->getRequirement('_entity_type')->willReturn('node'); $route->getRequirement('_bundle')->willReturn('article'); $route->getDefault('_on_relationship')->willReturn(NULL); $request->get(RouteObjectInterface::ROUTE_OBJECT)->willReturn($route->reveal()); $resource_config = $this->prophesize(ResourceConfigInterface::CLASS); - $resource_config->getTypeName()->willReturn('article'); + $resource_config->getTypeName()->willReturn('node--article'); $resource_config->getEntityTypeId()->willReturn('node'); $resource_config->getBundleId()->willReturn('article'); $resource_config->getDeserializationTargetClass()->willReturn('Drupal\node\Entity\Node'); diff --git a/tests/src/Unit/Routing/RoutesTest.php b/tests/src/Unit/Routing/RoutesTest.php index 7b04823..8793da3 100644 --- a/tests/src/Unit/Routing/RoutesTest.php +++ b/tests/src/Unit/Routing/RoutesTest.php @@ -46,7 +46,7 @@ class RoutesTest extends UnitTestCase { $resource_config->getBundleId()->willReturn('bundle_1_1'); // Make sure that we're not coercing the bundle into the path, they can be // different in the future. - $resource_config->getPath()->willReturn('/bundle_path_1'); + $resource_config->getPath()->willReturn('/entity_type_1/bundle_path_1'); $resource_config->getTypeName()->willReturn('resource_type_1'); $resource_manager->all()->willReturn([$resource_config->reveal()]); $container = $this->prophesize(ContainerInterface::class); @@ -76,7 +76,7 @@ class RoutesTest extends UnitTestCase { // Check the collection route. /** @var \Symfony\Component\Routing\Route $route */ $route = $iterator->offsetGet('api.dynamic.resource_type_1.collection'); - $this->assertSame('/api/bundle_path_1', $route->getPath()); + $this->assertSame('/api/entity_type_1/bundle_path_1', $route->getPath()); $this->assertSame('entity_type_1', $route->getRequirement('_entity_type')); $this->assertSame('bundle_1_1', $route->getRequirement('_bundle')); $this->assertSame(['lorem', 'ipsum'], $route->getOption('_auth')); @@ -95,7 +95,7 @@ class RoutesTest extends UnitTestCase { // Check the individual route. /** @var \Symfony\Component\Routing\Route $route */ $route = $iterator->offsetGet('api.dynamic.resource_type_1.individual'); - $this->assertSame('/api/bundle_path_1/{entity_type_1}', $route->getPath()); + $this->assertSame('/api/entity_type_1/bundle_path_1/{entity_type_1}', $route->getPath()); $this->assertSame('entity_type_1', $route->getRequirement('_entity_type')); $this->assertSame('bundle_1_1', $route->getRequirement('_bundle')); $this->assertEquals(['GET', 'PATCH', 'DELETE'], $route->getMethods()); @@ -115,7 +115,7 @@ class RoutesTest extends UnitTestCase { // Check the related route. /** @var \Symfony\Component\Routing\Route $route */ $route = $iterator->offsetGet('api.dynamic.resource_type_1.related'); - $this->assertSame('/api/bundle_path_1/{entity_type_1}/{related}', $route->getPath()); + $this->assertSame('/api/entity_type_1/bundle_path_1/{entity_type_1}/{related}', $route->getPath()); $this->assertSame('entity_type_1', $route->getRequirement('_entity_type')); $this->assertSame('bundle_1_1', $route->getRequirement('_bundle')); $this->assertEquals(['GET'], $route->getMethods()); @@ -134,7 +134,7 @@ class RoutesTest extends UnitTestCase { // Check the relationships route. /** @var \Symfony\Component\Routing\Route $route */ $route = $iterator->offsetGet('api.dynamic.resource_type_1.relationship'); - $this->assertSame('/api/bundle_path_1/{entity_type_1}/relationships/{related}', $route->getPath()); + $this->assertSame('/api/entity_type_1/bundle_path_1/{entity_type_1}/relationships/{related}', $route->getPath()); $this->assertSame('entity_type_1', $route->getRequirement('_entity_type')); $this->assertSame('bundle_1_1', $route->getRequirement('_bundle')); $this->assertEquals(['GET', 'POST', 'PATCH', 'DELETE'], $route->getMethods());