From e648e50d90cf2c1893b44a5066b2774dbc0af84f Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sat, 26 May 2018 11:00:28 -0700 Subject: [PATCH] Write some example tests for @stanjg --- app/Http/Middleware/MaintenanceMiddleware.php | 25 +++++-- resources/lang/en/base.php | 4 +- .../pterodactyl/errors/maintenance.blade.php | 2 +- .../Middleware/MaintenanceMiddlewareTest.php | 70 +++++++++++++++++++ 4 files changed, 94 insertions(+), 7 deletions(-) create mode 100644 tests/Unit/Http/Middleware/MaintenanceMiddlewareTest.php diff --git a/app/Http/Middleware/MaintenanceMiddleware.php b/app/Http/Middleware/MaintenanceMiddleware.php index 493582809..39f260594 100644 --- a/app/Http/Middleware/MaintenanceMiddleware.php +++ b/app/Http/Middleware/MaintenanceMiddleware.php @@ -3,23 +3,40 @@ namespace Pterodactyl\Http\Middleware; use Closure; +use Illuminate\Contracts\Routing\ResponseFactory; class MaintenanceMiddleware { + /** + * @var \Illuminate\Contracts\Routing\ResponseFactory + */ + private $response; + + /** + * MaintenanceMiddleware constructor. + * + * @param \Illuminate\Contracts\Routing\ResponseFactory $response + */ + public function __construct(ResponseFactory $response) + { + $this->response = $response; + } + /** * Handle an incoming request. * - * @param \Illuminate\Http\Request $request - * @param \Closure $next + * @param \Illuminate\Http\Request $request + * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { + /** @var \Pterodactyl\Models\Server $server */ $server = $request->attributes->get('server'); - $node = $server->node; + $node = $server->getRelation('node'); if ($node->maintenance) { - return response(view('errors.maintenance')); + return $this->response->view('errors.maintenance'); } return $next($request); diff --git a/resources/lang/en/base.php b/resources/lang/en/base.php index 579aa1080..01ac79b1e 100644 --- a/resources/lang/en/base.php +++ b/resources/lang/en/base.php @@ -23,8 +23,8 @@ return [ ], 'maintenance' => [ 'header' => 'Node Under Maintenance', - 'title' => 'Maintenance', - 'desc' => 'This node is under maintenance, therefore your server can temporarily not be accessed.' + 'title' => 'Temporarily Unavailable', + 'desc' => 'This node is under maintenance, therefore your server can temporarily not be accessed.', ], ], 'index' => [ diff --git a/resources/themes/pterodactyl/errors/maintenance.blade.php b/resources/themes/pterodactyl/errors/maintenance.blade.php index 97bb810e5..8cc8eea27 100644 --- a/resources/themes/pterodactyl/errors/maintenance.blade.php +++ b/resources/themes/pterodactyl/errors/maintenance.blade.php @@ -17,7 +17,7 @@
-

@lang('base.errors.maintenance.title')

+

@lang('base.errors.maintenance.title')

@lang('base.errors.maintenance.desc')