Update repository base code to be cleaner and make use of PHP 7 features
This commit is contained in:
parent
0ec5a4e08c
commit
60eb60013c
96 changed files with 1048 additions and 1785 deletions
|
@ -11,6 +11,7 @@ namespace Tests\Unit\Http\Controllers\Admin;
|
|||
|
||||
use Mockery as m;
|
||||
use Tests\TestCase;
|
||||
use Pterodactyl\Models\DatabaseHost;
|
||||
use Prologue\Alerts\AlertsMessageBag;
|
||||
use Tests\Assertions\ControllerAssertionsTrait;
|
||||
use Pterodactyl\Http\Controllers\Admin\DatabaseController;
|
||||
|
@ -74,8 +75,8 @@ class DatabaseControllerTest extends TestCase
|
|||
*/
|
||||
public function testIndexController()
|
||||
{
|
||||
$this->locationRepository->shouldReceive('getAllWithNodes')->withNoArgs()->once()->andReturn('getAllWithNodes');
|
||||
$this->repository->shouldReceive('getWithViewDetails')->withNoArgs()->once()->andReturn('getWithViewDetails');
|
||||
$this->locationRepository->shouldReceive('getAllWithNodes')->withNoArgs()->once()->andReturn(collect(['getAllWithNodes']));
|
||||
$this->repository->shouldReceive('getWithViewDetails')->withNoArgs()->once()->andReturn(collect(['getWithViewDetails']));
|
||||
|
||||
$response = $this->getController()->index();
|
||||
|
||||
|
@ -83,8 +84,8 @@ class DatabaseControllerTest extends TestCase
|
|||
$this->assertViewNameEquals('admin.databases.index', $response);
|
||||
$this->assertViewHasKey('locations', $response);
|
||||
$this->assertViewHasKey('hosts', $response);
|
||||
$this->assertViewKeyEquals('locations', 'getAllWithNodes', $response);
|
||||
$this->assertViewKeyEquals('hosts', 'getWithViewDetails', $response);
|
||||
$this->assertViewKeyEquals('locations', collect(['getAllWithNodes']), $response);
|
||||
$this->assertViewKeyEquals('hosts', collect(['getWithViewDetails']), $response);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -92,8 +93,10 @@ class DatabaseControllerTest extends TestCase
|
|||
*/
|
||||
public function testViewController()
|
||||
{
|
||||
$this->locationRepository->shouldReceive('getAllWithNodes')->withNoArgs()->once()->andReturn('getAllWithNodes');
|
||||
$this->repository->shouldReceive('getWithServers')->with(1)->once()->andReturn('getWithServers');
|
||||
$model = factory(DatabaseHost::class)->make();
|
||||
|
||||
$this->locationRepository->shouldReceive('getAllWithNodes')->withNoArgs()->once()->andReturn(collect(['getAllWithNodes']));
|
||||
$this->repository->shouldReceive('getWithServers')->with(1)->once()->andReturn($model);
|
||||
|
||||
$response = $this->getController()->view(1);
|
||||
|
||||
|
@ -101,8 +104,8 @@ class DatabaseControllerTest extends TestCase
|
|||
$this->assertViewNameEquals('admin.databases.view', $response);
|
||||
$this->assertViewHasKey('locations', $response);
|
||||
$this->assertViewHasKey('host', $response);
|
||||
$this->assertViewKeyEquals('locations', 'getAllWithNodes', $response);
|
||||
$this->assertViewKeyEquals('host', 'getWithServers', $response);
|
||||
$this->assertViewKeyEquals('locations', collect(['getAllWithNodes']), $response);
|
||||
$this->assertViewKeyEquals('host', $model, $response);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -46,15 +46,15 @@ class APIControllerTest extends ControllerTestCase
|
|||
*/
|
||||
public function testIndexController()
|
||||
{
|
||||
$model = $this->setRequestUser();
|
||||
$model = $this->generateRequestUserModel();
|
||||
|
||||
$this->repository->shouldReceive('findWhere')->with([['user_id', '=', $model->id]])->once()->andReturn(['testkeys']);
|
||||
$this->repository->shouldReceive('findWhere')->with([['user_id', '=', $model->id]])->once()->andReturn(collect(['testkeys']));
|
||||
|
||||
$response = $this->getController()->index($this->request);
|
||||
$this->assertIsViewResponse($response);
|
||||
$this->assertViewNameEquals('base.api.index', $response);
|
||||
$this->assertViewHasKey('keys', $response);
|
||||
$this->assertViewKeyEquals('keys', ['testkeys'], $response);
|
||||
$this->assertViewKeyEquals('keys', collect(['testkeys']), $response);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -64,7 +64,7 @@ class APIControllerTest extends ControllerTestCase
|
|||
*/
|
||||
public function testCreateController($admin)
|
||||
{
|
||||
$this->setRequestUser(factory(User::class)->make(['root_admin' => $admin]));
|
||||
$this->generateRequestUserModel(['root_admin' => $admin]);
|
||||
|
||||
$response = $this->getController()->create($this->request);
|
||||
$this->assertIsViewResponse($response);
|
||||
|
@ -87,7 +87,7 @@ class APIControllerTest extends ControllerTestCase
|
|||
public function testStoreController($admin)
|
||||
{
|
||||
$this->setRequestMockClass(ApiKeyFormRequest::class);
|
||||
$model = $this->setRequestUser(factory(User::class)->make(['root_admin' => $admin]));
|
||||
$model = $this->generateRequestUserModel(['root_admin' => $admin]);
|
||||
$keyModel = factory(APIKey::class)->make();
|
||||
|
||||
if ($admin) {
|
||||
|
@ -118,12 +118,12 @@ class APIControllerTest extends ControllerTestCase
|
|||
*/
|
||||
public function testRevokeController()
|
||||
{
|
||||
$model = $this->setRequestUser();
|
||||
$model = $this->generateRequestUserModel();
|
||||
|
||||
$this->repository->shouldReceive('deleteWhere')->with([
|
||||
['user_id', '=', $model->id],
|
||||
['token', '=', 'testKey123'],
|
||||
])->once()->andReturnNull();
|
||||
])->once()->andReturn(1);
|
||||
|
||||
$response = $this->getController()->revoke($this->request, 'testKey123');
|
||||
$this->assertIsResponse($response);
|
||||
|
|
|
@ -15,6 +15,7 @@ use Pterodactyl\Models\Server;
|
|||
use Tests\Assertions\ControllerAssertionsTrait;
|
||||
use Tests\Unit\Http\Controllers\ControllerTestCase;
|
||||
use Pterodactyl\Http\Controllers\Base\IndexController;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
use Pterodactyl\Services\DaemonKeys\DaemonKeyProviderService;
|
||||
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface as DaemonServerRepositoryInterface;
|
||||
|
@ -62,19 +63,19 @@ class IndexControllerTest extends ControllerTestCase
|
|||
*/
|
||||
public function testIndexController()
|
||||
{
|
||||
$model = $this->setRequestUser();
|
||||
$paginator = m::mock(LengthAwarePaginator::class);
|
||||
$model = $this->generateRequestUserModel();
|
||||
|
||||
$this->request->shouldReceive('input')->with('query')->once()->andReturn('searchTerm');
|
||||
$this->repository->shouldReceive('search')->with('searchTerm')->once()->andReturnSelf()
|
||||
->shouldReceive('filterUserAccessServers')->with(
|
||||
$model->id, $model->root_admin, 'all', ['user']
|
||||
)->once()->andReturn(['test']);
|
||||
$this->repository->shouldReceive('setSearchTerm')->with('searchTerm')->once()->andReturnSelf()
|
||||
->shouldReceive('filterUserAccessServers')->with($model, User::FILTER_LEVEL_ALL)
|
||||
->once()->andReturn($paginator);
|
||||
|
||||
$response = $this->controller->getIndex($this->request);
|
||||
$this->assertIsViewResponse($response);
|
||||
$this->assertViewNameEquals('base.index', $response);
|
||||
$this->assertViewHasKey('servers', $response);
|
||||
$this->assertViewKeyEquals('servers', ['test'], $response);
|
||||
$this->assertViewKeyEquals('servers', $paginator, $response);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -82,7 +83,7 @@ class IndexControllerTest extends ControllerTestCase
|
|||
*/
|
||||
public function testStatusController()
|
||||
{
|
||||
$user = $this->setRequestUser();
|
||||
$user = $this->generateRequestUserModel();
|
||||
$server = factory(Server::class)->make(['suspended' => 0, 'installed' => 1]);
|
||||
|
||||
$this->repository->shouldReceive('findFirstWhere')->with([['uuidShort', '=', $server->uuidShort]])->once()->andReturn($server);
|
||||
|
@ -105,7 +106,7 @@ class IndexControllerTest extends ControllerTestCase
|
|||
*/
|
||||
public function testStatusControllerWhenServerNotInstalled()
|
||||
{
|
||||
$user = $this->setRequestUser();
|
||||
$user = $this->generateRequestUserModel();
|
||||
$server = factory(Server::class)->make(['suspended' => 0, 'installed' => 0]);
|
||||
|
||||
$this->repository->shouldReceive('findFirstWhere')->with([['uuidShort', '=', $server->uuidShort]])->once()->andReturn($server);
|
||||
|
|
|
@ -61,13 +61,13 @@ class SecurityControllerTest extends ControllerTestCase
|
|||
$model = $this->generateRequestUserModel();
|
||||
|
||||
$this->config->shouldReceive('get')->with('session.driver')->once()->andReturn('database');
|
||||
$this->repository->shouldReceive('getUserSessions')->with($model->id)->once()->andReturn(['sessions']);
|
||||
$this->repository->shouldReceive('getUserSessions')->with($model->id)->once()->andReturn(collect(['sessions']));
|
||||
|
||||
$response = $this->getController()->index($this->request);
|
||||
$this->assertIsViewResponse($response);
|
||||
$this->assertViewNameEquals('base.security', $response);
|
||||
$this->assertViewHasKey('sessions', $response);
|
||||
$this->assertViewKeyEquals('sessions', ['sessions'], $response);
|
||||
$this->assertViewKeyEquals('sessions', collect(['sessions']), $response);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -103,7 +103,7 @@ class FileActionsControllerTest extends ControllerTestCase
|
|||
->shouldReceive('setAccessToken')->with('abc123')->once()->andReturnSelf()
|
||||
->shouldReceive('getContent')->with($file)->once()->andReturn('file contents');
|
||||
|
||||
$response = $controller->update($this->request, '1234', $file);
|
||||
$response = $controller->view($this->request, '1234', $file);
|
||||
$this->assertIsViewResponse($response);
|
||||
$this->assertViewNameEquals('server.files.edit', $response);
|
||||
$this->assertViewHasKey('file', $response);
|
||||
|
@ -134,7 +134,7 @@ class FileActionsControllerTest extends ControllerTestCase
|
|||
$this->repository->shouldReceive('setNode')->with($server->node_id)->once()->andThrow($this->getExceptionMock());
|
||||
|
||||
try {
|
||||
$controller->update($this->request, '1234', 'file.txt');
|
||||
$controller->view($this->request, '1234', 'file.txt');
|
||||
} catch (PterodactylException $exception) {
|
||||
$this->assertInstanceOf(DaemonConnectionException::class, $exception);
|
||||
$this->assertInstanceOf(RequestException::class, $exception->getPrevious());
|
||||
|
|
|
@ -76,7 +76,7 @@ class SubuserControllerTest extends ControllerTestCase
|
|||
$this->mockInjectJavascript();
|
||||
|
||||
$controller->shouldReceive('authorize')->with('list-subusers', $server)->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('findWhere')->with([['server_id', '=', $server->id]])->once()->andReturn([]);
|
||||
$this->repository->shouldReceive('findWhere')->with([['server_id', '=', $server->id]])->once()->andReturn(collect());
|
||||
|
||||
$response = $controller->index($this->request);
|
||||
$this->assertIsViewResponse($response);
|
||||
|
|
|
@ -34,7 +34,7 @@ class DaemonAuthenticateTest extends MiddlewareTestCase
|
|||
$this->request->shouldReceive('route->getName')->withNoArgs()->once()->andReturn('random.name');
|
||||
$this->request->shouldReceive('header')->with('X-Access-Node')->twice()->andReturn($node->uuid);
|
||||
|
||||
$this->repository->shouldReceive('findWhere')->with(['daemonSecret' => $node->uuid])->once()->andReturn($node);
|
||||
$this->repository->shouldReceive('findFirstWhere')->with(['daemonSecret' => $node->uuid])->once()->andReturn($node);
|
||||
|
||||
$this->getMiddleware()->handle($this->request, $this->getClosureAssertions());
|
||||
$this->assertRequestHasAttribute('node');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue