jsonapi_cross_bundles-8.x-1.0-alpha3/tests/src/Unit/Routing/Routing.php
tests/src/Unit/Routing/Routing.php
<?php
namespace Drupal\Tests\jsonapi_cross_bundles\Unit\Routing;
use Prophecy\PhpUnit\ProphecyTrait;
use Drupal\Core\Entity\EntityInterface;
use Drupal\jsonapi\ResourceType\ResourceType;
use Drupal\jsonapi\Routing\Routes;
use Drupal\jsonapi_cross_bundles\ResourceType\CrossBundleResourceTypeRepository;
use Drupal\jsonapi_cross_bundles\ResourceType\CrossBundlesResourceType;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Tests cross bundle routes.
*
* @group jsonapi_cross_bundles
*/
class Routing extends UnitTestCase {
use ProphecyTrait;
/**
* Tests the generated cross bundle route.
*/
public function testCrossBundleCollectionRoute() {
$type_2 = new ResourceType('entity_test', 'bundle_1', EntityInterface::class);
$type_3 = new ResourceType('entity_test', 'bundle_2', EntityInterface::class);
$type_1 = new CrossBundlesResourceType('entity_test', 'entity_test', EntityInterface::class);
$type_1->setBundleResourceTypes([$type_2, $type_3]);
$type_1->setRelatableResourceTypes([]);
$type_2->setRelatableResourceTypes([]);
$type_3->setRelatableResourceTypes([]);
$resource_type_repository = $this->prophesize(CrossBundleResourceTypeRepository::class);
$resource_type_repository->all()->willReturn([$type_1, $type_2, $type_3]);
$container = $this->prophesize(ContainerInterface::class);
$container->get('jsonapi.resource_type.repository')->willReturn($resource_type_repository->reveal());
$container->getParameter('jsonapi.base_path')->willReturn('/jsonapi');
$container->getParameter('authentication_providers')->willReturn([
'lorem' => [],
'ipsum' => [],
]);
$routes = Routes::create($container->reveal())->routes();
$this->assertCount(13, $routes);
$iterator = $routes->getIterator();
// Check the cross bundle collection route.
/** @var \Symfony\Component\Routing\Route $route */
$route = $iterator->offsetGet('jsonapi.entity_test.collection');
$this->assertSame('/jsonapi/entity_test', $route->getPath());
// @todo we need to disable this route, somehow.
$route = $iterator->offsetGet('jsonapi.entity_test.individual');
$this->assertSame('/jsonapi/entity_test/{entity}', $route->getPath());
}
}
