Path: blob/1.0-develop/tests/Unit/Http/Middleware/MaintenanceMiddlewareTest.php
7461 views
<?php12namespace Pterodactyl\Tests\Unit\Http\Middleware;34use Mockery as m;5use Mockery\MockInterface;6use Pterodactyl\Models\Node;7use Illuminate\Http\Response;8use Pterodactyl\Models\Server;9use Illuminate\Contracts\Routing\ResponseFactory;10use Pterodactyl\Http\Middleware\MaintenanceMiddleware;1112class MaintenanceMiddlewareTest extends MiddlewareTestCase13{14private MockInterface $response;1516/**17* Setup tests.18*/19public function setUp(): void20{21parent::setUp();2223$this->response = m::mock(ResponseFactory::class);24}2526/**27* Test that a node not in maintenance mode continues through the request cycle.28*/29public function testHandle()30{31$server = Server::factory()->make();32$node = Node::factory()->make(['maintenance' => 0]);3334$server->setRelation('node', $node);35$this->setRequestAttribute('server', $server);3637$this->getMiddleware()->handle($this->request, $this->getClosureAssertions());38}3940/**41* Test that a node in maintenance mode returns an error view.42*/43public function testHandleInMaintenanceMode()44{45$server = Server::factory()->make();46$node = Node::factory()->make(['maintenance_mode' => 1]);4748$server->setRelation('node', $node);49$this->setRequestAttribute('server', $server);5051$this->response->shouldReceive('view')52->once()53->with('errors.maintenance')54->andReturn(new Response());5556$response = $this->getMiddleware()->handle($this->request, $this->getClosureAssertions());57$this->assertInstanceOf(Response::class, $response);58}5960private function getMiddleware(): MaintenanceMiddleware61{62return new MaintenanceMiddleware($this->response);63}64}656667