2019-01-05 16:41:21 +01:00
|
|
|
<?php
|
|
|
|
|
2019-01-05 21:26:36 +01:00
|
|
|
namespace Tests\Integration\Controller;
|
2019-01-05 16:41:21 +01:00
|
|
|
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
2019-02-17 14:33:19 +01:00
|
|
|
use Infinito\DBAL\Types\LanguageType;
|
|
|
|
use Infinito\DBAL\Types\Meta\Right\LayerType;
|
|
|
|
use Infinito\DBAL\Types\RESTResponseType;
|
2019-01-05 17:40:15 +01:00
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
2019-01-05 16:41:21 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author kevinfrantz
|
|
|
|
*
|
|
|
|
* @todo Implement more tests for success etc.
|
|
|
|
*/
|
2019-01-05 21:26:36 +01:00
|
|
|
class RoutesReachableIntegrationTest extends KernelTestCase
|
2019-01-05 16:41:21 +01:00
|
|
|
{
|
2019-02-12 18:04:36 +01:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*
|
|
|
|
* @see \PHPUnit\Framework\TestCase::setUp()
|
|
|
|
*/
|
2019-01-05 16:41:21 +01:00
|
|
|
public function setUp(): void
|
|
|
|
{
|
|
|
|
self::bootKernel();
|
|
|
|
}
|
|
|
|
|
2019-01-05 21:26:36 +01:00
|
|
|
public function testAllRoutePossibilities()
|
2019-01-05 16:41:21 +01:00
|
|
|
{
|
2019-01-19 10:01:47 +01:00
|
|
|
foreach (LayerType::getChoices() as $layer) {
|
2019-01-05 16:41:21 +01:00
|
|
|
$this->controller($layer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-19 10:01:47 +01:00
|
|
|
/**
|
|
|
|
* @param string $entity
|
|
|
|
*/
|
|
|
|
private function controller(string $entity): void
|
2019-01-05 16:41:21 +01:00
|
|
|
{
|
2019-01-05 19:03:08 +01:00
|
|
|
$this->language($entity, Request::METHOD_GET);
|
2019-01-05 17:40:15 +01:00
|
|
|
$this->language($entity, Request::METHOD_POST);
|
|
|
|
$this->language($entity.'s', Request::METHOD_GET);
|
|
|
|
$this->slugAndId($entity, Request::METHOD_PUT);
|
|
|
|
$this->slugAndId($entity, Request::METHOD_GET);
|
|
|
|
$this->slugAndId($entity, Request::METHOD_DELETE);
|
2019-01-05 16:41:21 +01:00
|
|
|
}
|
|
|
|
|
2019-01-19 10:01:47 +01:00
|
|
|
/**
|
|
|
|
* @param string $route
|
|
|
|
* @param string $method
|
|
|
|
*/
|
2019-01-05 16:41:21 +01:00
|
|
|
private function slugAndId(string $route, string $method): void
|
|
|
|
{
|
2019-01-05 17:40:15 +01:00
|
|
|
$this->language("$route/12345", $method);
|
|
|
|
$this->language("$route/asdfg", $method);
|
2019-01-05 16:41:21 +01:00
|
|
|
}
|
|
|
|
|
2019-01-05 18:39:32 +01:00
|
|
|
/**
|
|
|
|
* @todo Implement routing without i18l part!
|
|
|
|
*
|
|
|
|
* @param string $entity
|
|
|
|
* @param string $method
|
|
|
|
*/
|
2019-01-05 16:41:21 +01:00
|
|
|
private function language(string $entity, string $method): void
|
|
|
|
{
|
2019-01-05 18:39:32 +01:00
|
|
|
//$this->type('api/'.$entity, $method);
|
2019-01-05 21:26:36 +01:00
|
|
|
foreach (LanguageType::getChoices() as $language) {
|
2019-01-05 18:39:32 +01:00
|
|
|
$this->type("$language/api/$entity", $method);
|
2019-01-05 21:26:36 +01:00
|
|
|
$this->type("$language/html/$entity", $method);
|
2019-01-05 16:41:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-19 10:01:47 +01:00
|
|
|
/**
|
|
|
|
* @param string $route
|
|
|
|
* @param string $method
|
|
|
|
*/
|
2019-01-05 16:41:21 +01:00
|
|
|
private function type(string $route, string $method): void
|
|
|
|
{
|
|
|
|
$this->routeAssert($route, $method);
|
|
|
|
foreach (RESTResponseType::getChoices() as $restResponseType => $value) {
|
|
|
|
$this->routeAssert("$route.$restResponseType", $method);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-19 10:01:47 +01:00
|
|
|
/**
|
|
|
|
* @param string $url
|
|
|
|
* @param string $method
|
|
|
|
*/
|
2019-01-05 17:40:15 +01:00
|
|
|
private function routeAssert(string $url, string $method): void
|
2019-01-05 16:41:21 +01:00
|
|
|
{
|
2019-01-05 17:40:15 +01:00
|
|
|
$request = new Request([], [], [], [], [], [
|
2019-01-05 16:41:21 +01:00
|
|
|
'REQUEST_URI' => $url,
|
|
|
|
]);
|
2019-01-05 18:39:32 +01:00
|
|
|
$request->setMethod($method);
|
2019-01-05 16:41:21 +01:00
|
|
|
$response = static::$kernel->handle($request);
|
2019-01-05 18:39:32 +01:00
|
|
|
$this->assertNotEquals(404, $response->getStatusCode(), "Route $url with Method $method sends an 404 response!");
|
2019-01-05 16:41:21 +01:00
|
|
|
}
|
|
|
|
}
|