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

Add support to disable darkmode routes #1310

Merged
merged 2 commits into from
Oct 10, 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
1 change: 1 addition & 0 deletions config/adminlte.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@
'password_reset_url' => 'password/reset',
'password_email_url' => 'password/email',
'profile_url' => false,
'disable_darkmode_routes' => false,

/*
|--------------------------------------------------------------------------
Expand Down
6 changes: 4 additions & 2 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@
// Dark Mode routes.
//-----------------------------------------------------------------------------

Route::post('/darkmode/toggle', [DarkModeController::class, 'toggle'])
->name('darkmode.toggle');
if (! config('adminlte.disable_darkmode_routes', false)) {
Route::post('/darkmode/toggle', [DarkModeController::class, 'toggle'])
->name('darkmode.toggle');
}
34 changes: 32 additions & 2 deletions tests/ServiceProviderTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use JeroenNoten\LaravelAdminLte\AdminLte;
use JeroenNoten\LaravelAdminLte\AdminLteServiceProvider;

class ServiceProviderTest extends TestCase
{
Expand Down Expand Up @@ -112,10 +113,39 @@ public function testBootLoadComponents()
$this->assertTrue(isset($aliases['adminlte-modal']));
}

public function testBootLoadRoutes()
public function testBootLoadDarkModeRoutes()
{
// Assert the package routes names are registered.
// Disable dark mode routes and check.

config(['adminlte.disable_darkmode_routes' => true]);
$this->clearRoutesAndReRegisterProvider();

$this->assertFalse(Route::has('adminlte.darkmode.toggle'));

// Enable dark mode routes and check again.

config(['adminlte.disable_darkmode_routes' => false]);
$this->clearRoutesAndReRegisterProvider();

$this->assertTrue(Route::has('adminlte.darkmode.toggle'));
}

/**
* Clear routes and re-register the service provider.
*/
protected function clearRoutesAndReRegisterProvider()
{
// Clear the current route collection.

Route::setRoutes(new \Illuminate\Routing\RouteCollection());

// Unregister and register the provider again.

$provider = $this->app->register(AdminLteServiceProvider::class);
$provider->boot();

// Refresh route names after loading routes again.

Route::getRoutes()->refreshNameLookups();
}
}