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

[6.x] Configurable of Laravel dusk routes enhancement #774

Merged
merged 5 commits into from
May 13, 2020
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
27 changes: 27 additions & 0 deletions config/dusk.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

return [
/*
|--------------------------------------------------------------------------
| Dusk Path
|--------------------------------------------------------------------------
|
| This is the URI path where Laravel dusk will locate its internal API routes.
|
*/

'path' => '_dusk',

/*
|--------------------------------------------------------------------------
| Dusk Domain
|--------------------------------------------------------------------------
|
| This is the subdomain where Dusk will access its internal API routes. If this
| setting is null, Dusk will reside under the same domain as the
| application. Otherwise, this value will serve as the subdomain.
|
*/

'domain' => null,
];
6 changes: 3 additions & 3 deletions src/Concerns/InteractsWithAuthentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function loginAs($userId, $guard = null)
{
$userId = method_exists($userId, 'getKey') ? $userId->getKey() : $userId;

return $this->visit(rtrim('/_dusk/login/'.$userId.'/'.$guard, '/'));
return $this->visit(rtrim(route('dusk.login', ['userId' => $userId, 'guard' => $guard])));
}

/**
Expand All @@ -39,7 +39,7 @@ public function loginAs($userId, $guard = null)
*/
public function logout($guard = null)
{
return $this->visit(rtrim('/_dusk/logout/'.$guard, '/'));
return $this->visit(rtrim(route('dusk.logout', ['guard' => $guard]), '/'));
}

/**
Expand All @@ -50,7 +50,7 @@ public function logout($guard = null)
*/
protected function currentUserInfo($guard = null)
{
$response = $this->visit("/_dusk/user/{$guard}");
$response = $this->visit(route('dusk.user', ['guard' => $guard]));

return json_decode(strip_tags($response->driver->getPageSource()), true);
}
Expand Down
55 changes: 34 additions & 21 deletions src/DuskServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,26 @@ class DuskServiceProvider extends ServiceProvider
public function boot()
{
if (! $this->app->environment('production')) {
Route::get('/_dusk/login/{userId}/{guard?}', [
Route::group([
'prefix' => config('dusk.path'),
'domain' => config('dusk.domain', null),
'middleware' => 'web',
'uses' => 'Laravel\Dusk\Http\Controllers\UserController@login',
]);
], function () {
Route::get('/login/{userId}/{guard?}', [
'uses' => 'Laravel\Dusk\Http\Controllers\UserController@login',
'as' => 'dusk.login',
]);

Route::get('/_dusk/logout/{guard?}', [
'middleware' => 'web',
'uses' => 'Laravel\Dusk\Http\Controllers\UserController@logout',
]);
Route::get('/logout/{guard?}', [
'uses' => 'Laravel\Dusk\Http\Controllers\UserController@logout',
'as' => 'dusk.logout',
]);

Route::get('/_dusk/user/{guard?}', [
'middleware' => 'web',
'uses' => 'Laravel\Dusk\Http\Controllers\UserController@user',
]);
Route::get('/user/{guard?}', [
'uses' => 'Laravel\Dusk\Http\Controllers\UserController@user',
'as' => 'dusk.user',
]);
});
}
}

Expand All @@ -41,16 +47,23 @@ public function boot()
*/
public function register()
{
if ($this->app->runningInConsole()) {
$this->commands([
Console\InstallCommand::class,
Console\DuskCommand::class,
Console\DuskFailsCommand::class,
Console\MakeCommand::class,
Console\PageCommand::class,
Console\ComponentCommand::class,
Console\ChromeDriverCommand::class,
]);
if (! $this->app->environment('production')) {
$this->mergeConfigFrom(__DIR__.'/../config/dusk.php', 'dusk');
$this->publishes([
__DIR__.'/../config/dusk.php' => config_path('dusk.php'),
], 'dusk-config');

if ($this->app->runningInConsole()) {
$this->commands([
Console\InstallCommand::class,
Console\DuskCommand::class,
Console\DuskFailsCommand::class,
Console\MakeCommand::class,
Console\PageCommand::class,
Console\ComponentCommand::class,
Console\ChromeDriverCommand::class,
]);
}
}
}
}