Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed extra trait from tests #18

Merged
merged 2 commits into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 0 additions & 101 deletions tests/Concerns/Routes.php

This file was deleted.

94 changes: 92 additions & 2 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,24 @@

namespace Tests;

use Closure;
use LaravelLang\Config\Enums\Name;
use LaravelLang\Config\ServiceProvider as ConfigServiceProvider;
use LaravelLang\Locales\ServiceProvider as LocalesServiceProvider;
use LaravelLang\Routes\Facades\LocalizationRoute;
use LaravelLang\Routes\Middlewares\LocalizationByCookie;
use LaravelLang\Routes\Middlewares\LocalizationByHeader;
use LaravelLang\Routes\Middlewares\LocalizationByModel;
use LaravelLang\Routes\Middlewares\LocalizationByParameter;
use LaravelLang\Routes\Middlewares\LocalizationByParameterWithRedirect;
use LaravelLang\Routes\Middlewares\LocalizationBySession;
use LaravelLang\Routes\ServiceProvider;
use Orchestra\Testbench\TestCase as BaseTestCase;
use Tests\Concerns\Locales;
use Tests\Concerns\Routes;
use Tests\Constants\LocaleValue;

abstract class TestCase extends BaseTestCase
{
use Routes;
use Locales;

protected function getPackageProviders($app): array
Expand Down Expand Up @@ -46,4 +52,88 @@ protected function defineDatabaseMigrations(): void
{
$this->loadMigrationsFrom(__DIR__ . '/database/migrations');
}

/**
* Define routes setup.
*
* @param \Illuminate\Routing\Router $router
*/
protected function defineRoutes($router): void
{
$router
->middleware('web')
->group(function () use ($router) {
$router
->middleware(LocalizationByParameter::class)
->get('path/{foo}/{locale?}', $this->jsonResponse())
->name('via.parameter');

$router
->middleware(LocalizationByParameterWithRedirect::class)
->get('redirect/{foo}/{locale?}', $this->jsonResponse())
->name('via.parameter.redirect');

$router
->middleware(LocalizationByParameterWithRedirect::class)
->get('not-named/redirect/{foo}/{locale?}', $this->jsonResponse());

$router
->middleware(LocalizationByHeader::class)
->get('header/{foo}', $this->jsonResponse())
->name('via.header');

$router
->middleware(LocalizationByCookie::class)
->get('cookie/{foo}', $this->jsonResponse())
->name('via.cookie');

$router
->middleware(LocalizationBySession::class)
->get('session/{foo}', $this->jsonResponse())
->name('via.session');

$router
->middleware(LocalizationByModel::class)
->get('model/default/{foo}', $this->jsonResponse())
->name('via.model.default');

$router
->middleware(LocalizationByModel::class . ':foo')
->get('model/guard/{foo}', $this->jsonResponse())
->name('via.model.guard');

$router
->middleware([
LocalizationByParameter::class,
LocalizationByParameterWithRedirect::class,
LocalizationByHeader::class,
LocalizationByCookie::class,
LocalizationBySession::class,
LocalizationByModel::class,
])
->get('clean/{foo}', $this->jsonResponse())
->name('clean');
});

$router->localizedGroup(function () use ($router) {
$router
->middleware('web')
->get('group/macro/{foo}', $this->jsonResponse())
->name('via.group.macro');
});

LocalizationRoute::group(function () use ($router) {
$router
->middleware('web')
->get('group/facade/{foo}', $this->jsonResponse())
->name('via.group.facade');
});
}

protected function jsonResponse(): Closure
{
return fn (string $foo) => response()->json([
$foo => __(LocaleValue::TranslationKey),
]);
}
}