Skip to content

Commit

Permalink
ref: disable routes by default
Browse files Browse the repository at this point in the history
  • Loading branch information
GeoSot committed Apr 13, 2024
1 parent 148bbe2 commit d444366
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 25 deletions.
2 changes: 1 addition & 1 deletion config/env-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
|
*/
'route' => [
'enable'=> true,
'enable' => false,
// Prefix url for route Group
'prefix' => 'env-editor',
// Routes base name
Expand Down
18 changes: 9 additions & 9 deletions routes/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,28 @@
Route::prefix(config('env-editor.route.prefix'))
->middleware(config('env-editor.route.middleware'))
->group(function () use ($routeMainName) {
Route::get('/', [EnvController::class, 'index'])->name($routeMainName . '.index');
Route::get('/', [EnvController::class, 'index'])->name($routeMainName.'.index');

Route::post('key', [EnvController::class, 'addKey'])->name($routeMainName . '.key');
Route::post('key', [EnvController::class, 'addKey'])->name($routeMainName.'.key');
Route::patch('key', [EnvController::class, 'editKey']);
Route::delete('key', [EnvController::class, 'deleteKey']);

Route::delete('clear-cache', [EnvController::class, 'clearConfigCache'])->name($routeMainName . '.clearConfigCache');
Route::delete('clear-cache', [EnvController::class, 'clearConfigCache'])->name($routeMainName.'.clearConfigCache');

Route::prefix('files')->group(function () use ($routeMainName) {
Route::get('/', [EnvController::class, 'getBackupFiles'])
->name($routeMainName . '.getBackups');
->name($routeMainName.'.getBackups');
Route::post('create-backup', [EnvController::class, 'createBackup'])
->name($routeMainName . '.createBackup');
->name($routeMainName.'.createBackup');
Route::post('restore-backup/{filename?}', [EnvController::class, 'restoreBackup'])
->name($routeMainName . '.restoreBackup');
->name($routeMainName.'.restoreBackup');
Route::delete('destroy-backup/{filename?}', [EnvController::class, 'destroyBackup'])
->name($routeMainName . '.destroyBackup');
->name($routeMainName.'.destroyBackup');

Route::get('download/{filename?}', [EnvController::class, 'download'])
->name($routeMainName . '.download');
->name($routeMainName.'.download');
Route::post('upload', [EnvController::class, 'upload'])
->name($routeMainName . '.upload');
->name($routeMainName.'.upload');
});
});
}
36 changes: 36 additions & 0 deletions tests/Feature/ConfigurationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace GeoSot\EnvEditor\Tests\Feature;

use GeoSot\EnvEditor\Tests\TestCase;
use Illuminate\Support\Facades\Route;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\TestWith;

class ConfigurationTest extends TestCase
{
#[Test]
#[TestWith([false])]
#[TestWith([true])]
public function can_disable_routes(bool $enableRoutes): void
{
$this->app['config']->set('env-editor.route.enable', $enableRoutes);

$routeNames = [
'.index',
'.key',
'.clearConfigCache',
'.files.getBackups',
'.files.createBackup',
'.files.restoreBackup',
'.files.destroyBackup',
'.files.download',
'.files.upload',
];

foreach ($routeNames as $name) {
$routeName = $this->app['config']['env-editor.route.name'].$name;
$this->assertFalse(Route::has($routeName));
}
}
}
20 changes: 5 additions & 15 deletions tests/Feature/UiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,21 @@

class UiTest extends TestCase
{
protected function setUp(): void
protected function getEnvironmentSetUp($app): void
{
parent::setUp(); // TODO: Change the autogenerated stub
$this->app['config']->set('env-editor.paths.env', self::getTestPath());
$this->app['config']->set('env-editor.envFileName', self::getTestFile());
parent::getEnvironmentSetUp($app);
$app['config']->set('env-editor.paths.env', self::getTestPath());
$app['config']->set('env-editor.envFileName', self::getTestFile());
$app['config']->set('env-editor.route.enable', true);
}


#[Test]
public function can_see_dashboard(): void
{
$response = $this->get($this->makeRoute('index'));
$response->assertStatus(200)
->assertSee(trans('env-editor::env-editor.menuTitle'));
}
#[Test]
#[TestWith([true])]
#[TestWith([false])]
public function can_disable_routes(bool $enableRoutes): void
{
$this->app['config']->set('env-editor.route.enable', $enableRoutes);
$response = $this->get($this->makeRoute('index'));
$response->assertStatus($enableRoutes ? 200 : 400);

}

#[Test]
public function get_json_results(): void
Expand Down

0 comments on commit d444366

Please sign in to comment.