2020-03-02 17:11:17 +01:00
|
|
|
<?php
|
|
|
|
|
2021-11-22 01:09:54 +01:00
|
|
|
namespace Tests\Feature;
|
2020-03-02 17:11:17 +01:00
|
|
|
|
2024-06-28 16:13:45 +02:00
|
|
|
use App\Providers\RouteServiceProvider;
|
|
|
|
use Illuminate\Support\Arr;
|
|
|
|
use Illuminate\Support\Str;
|
|
|
|
use Illuminate\Support\Facades\Route;
|
|
|
|
use PHPUnit\Framework\Attributes\CoversMethod;
|
|
|
|
use PHPUnit\Framework\Attributes\DataProvider;
|
2024-06-26 14:29:13 +02:00
|
|
|
use PHPUnit\Framework\Attributes\Test;
|
2021-11-22 01:09:54 +01:00
|
|
|
use Tests\FeatureTestCase;
|
2020-03-02 17:11:17 +01:00
|
|
|
|
2024-06-28 16:13:45 +02:00
|
|
|
|
|
|
|
#[CoversMethod(RouteServiceProvider::class, 'boot')]
|
2021-11-22 01:09:54 +01:00
|
|
|
class RouteTest extends FeatureTestCase
|
2020-03-02 17:11:17 +01:00
|
|
|
{
|
2024-06-28 16:13:45 +02:00
|
|
|
const API_ROUTE_PREFIX = 'api/v1';
|
|
|
|
const API_MIDDLEWARE = 'api.v1';
|
|
|
|
|
2024-06-26 14:29:13 +02:00
|
|
|
#[Test]
|
2021-11-22 01:09:54 +01:00
|
|
|
public function test_landing_view_is_returned()
|
2020-03-02 17:11:17 +01:00
|
|
|
{
|
2020-10-11 20:40:28 +02:00
|
|
|
$response = $this->get(route('landing', ['any' => '/']));
|
2020-03-02 17:11:17 +01:00
|
|
|
|
2020-03-05 12:56:35 +01:00
|
|
|
$response->assertSuccessful()
|
|
|
|
->assertViewIs('landing');
|
2020-03-02 17:11:17 +01:00
|
|
|
}
|
|
|
|
|
2024-06-26 14:29:13 +02:00
|
|
|
#[Test]
|
2021-11-22 01:09:54 +01:00
|
|
|
public function test_exception_handler_with_web_route()
|
2020-03-08 20:16:56 +01:00
|
|
|
{
|
|
|
|
$response = $this->post('/');
|
|
|
|
|
|
|
|
$response->assertStatus(405);
|
|
|
|
}
|
2024-06-28 16:13:45 +02:00
|
|
|
|
|
|
|
#[Test]
|
|
|
|
public function test_all_api_routes_are_behind_apiv1_middleware()
|
|
|
|
{
|
|
|
|
$routes = Route::getRoutes();
|
|
|
|
|
|
|
|
foreach ($routes as $route) {
|
|
|
|
$middlewares = Route::gatherRouteMiddleware($route);
|
|
|
|
|
|
|
|
if (Str::startsWith($route->uri(), self::API_ROUTE_PREFIX)) {
|
|
|
|
$this->assertEquals(self::API_ROUTE_PREFIX, $route->getPrefix());
|
|
|
|
$this->assertTrue(in_array(self::API_MIDDLEWARE, $middlewares));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[Test]
|
|
|
|
#[DataProvider('wherePatternProvider')]
|
|
|
|
public function test_router_has_expected_global_where_patterns($pattern)
|
|
|
|
{
|
|
|
|
$patterns = Route::getPatterns();
|
|
|
|
|
|
|
|
$this->assertArrayHasKey($pattern, $patterns);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Provide data for tests
|
|
|
|
*/
|
|
|
|
public static function wherePatternProvider()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'SETTING_NAME' => ['settingName']
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-11-22 15:15:52 +01:00
|
|
|
}
|