Skip to content

Commit

Permalink
Add support to disable darkmode routes (#1310)
Browse files Browse the repository at this point in the history
* [routes]: Add support to disable darkmode routes

* [test]: Fix code style
  • Loading branch information
dfsmania authored Oct 10, 2024
1 parent 9282c7b commit 9ce9ef6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
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();
}
}

0 comments on commit 9ce9ef6

Please sign in to comment.