Merge branch 'develop' into pr/1128
This commit is contained in:
commit
4d62e4c7b9
96 changed files with 1966 additions and 874 deletions
|
@ -10,7 +10,7 @@
|
|||
namespace Tests\Unit\Commands\Schedule;
|
||||
|
||||
use Mockery as m;
|
||||
use Carbon\Carbon;
|
||||
use Cake\Chronos\Chronos;
|
||||
use Pterodactyl\Models\Task;
|
||||
use Pterodactyl\Models\Schedule;
|
||||
use Tests\Unit\Commands\CommandTestCase;
|
||||
|
@ -20,11 +20,6 @@ use Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface;
|
|||
|
||||
class ProcessRunnableCommandTest extends CommandTestCase
|
||||
{
|
||||
/**
|
||||
* @var \Carbon\Carbon
|
||||
*/
|
||||
protected $carbon;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Console\Commands\Schedule\ProcessRunnableCommand
|
||||
*/
|
||||
|
@ -47,11 +42,12 @@ class ProcessRunnableCommandTest extends CommandTestCase
|
|||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->carbon = m::mock(Carbon::class);
|
||||
Chronos::setTestNow(Chronos::now());
|
||||
|
||||
$this->processScheduleService = m::mock(ProcessScheduleService::class);
|
||||
$this->repository = m::mock(ScheduleRepositoryInterface::class);
|
||||
|
||||
$this->command = new ProcessRunnableCommand($this->carbon, $this->processScheduleService, $this->repository);
|
||||
$this->command = new ProcessRunnableCommand($this->processScheduleService, $this->repository);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -62,9 +58,7 @@ class ProcessRunnableCommandTest extends CommandTestCase
|
|||
$schedule = factory(Schedule::class)->make();
|
||||
$schedule->tasks = collect([factory(Task::class)->make()]);
|
||||
|
||||
$this->carbon->shouldReceive('now')->withNoArgs()->once()->andReturnSelf()
|
||||
->shouldReceive('toAtomString')->withNoArgs()->once()->andReturn('00:00:00');
|
||||
$this->repository->shouldReceive('getSchedulesToProcess')->with('00:00:00')->once()->andReturn(collect([$schedule]));
|
||||
$this->repository->shouldReceive('getSchedulesToProcess')->with(Chronos::now()->toAtomString())->once()->andReturn(collect([$schedule]));
|
||||
$this->processScheduleService->shouldReceive('handle')->with($schedule)->once()->andReturnNull();
|
||||
|
||||
$display = $this->runCommand($this->command);
|
||||
|
@ -84,9 +78,7 @@ class ProcessRunnableCommandTest extends CommandTestCase
|
|||
$schedule = factory(Schedule::class)->make();
|
||||
$schedule->tasks = collect([]);
|
||||
|
||||
$this->carbon->shouldReceive('now')->withNoArgs()->once()->andReturnSelf()
|
||||
->shouldReceive('toAtomString')->withNoArgs()->once()->andReturn('00:00:00');
|
||||
$this->repository->shouldReceive('getSchedulesToProcess')->with('00:00:00')->once()->andReturn(collect([$schedule]));
|
||||
$this->repository->shouldReceive('getSchedulesToProcess')->with(Chronos::now()->toAtomString())->once()->andReturn(collect([$schedule]));
|
||||
|
||||
$display = $this->runCommand($this->command);
|
||||
|
||||
|
@ -104,9 +96,7 @@ class ProcessRunnableCommandTest extends CommandTestCase
|
|||
{
|
||||
$schedule = factory(Schedule::class)->make(['tasks' => null]);
|
||||
|
||||
$this->carbon->shouldReceive('now')->withNoArgs()->once()->andReturnSelf()
|
||||
->shouldReceive('toAtomString')->withNoArgs()->once()->andReturn('00:00:00');
|
||||
$this->repository->shouldReceive('getSchedulesToProcess')->with('00:00:00')->once()->andReturn(collect([$schedule]));
|
||||
$this->repository->shouldReceive('getSchedulesToProcess')->with(Chronos::now()->toAtomString())->once()->andReturn(collect([$schedule]));
|
||||
|
||||
$display = $this->runCommand($this->command);
|
||||
|
||||
|
|
|
@ -3,24 +3,22 @@
|
|||
* Created by PhpStorm.
|
||||
* User: Stan
|
||||
* Date: 26-5-2018
|
||||
* Time: 21:06
|
||||
* Time: 21:06.
|
||||
*/
|
||||
|
||||
namespace Tests\Unit\Http\Controllers\Admin;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Mockery as m;
|
||||
use Pterodactyl\Contracts\Repository\AllocationRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\NodeRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
|
||||
use Pterodactyl\Http\Controllers\Admin\StatisticsController;
|
||||
use Pterodactyl\Models\Node;
|
||||
use Tests\Assertions\ControllerAssertionsTrait;
|
||||
use Tests\Unit\Http\Controllers\ControllerTestCase;
|
||||
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
|
||||
use Pterodactyl\Http\Controllers\Admin\StatisticsController;
|
||||
use Pterodactyl\Contracts\Repository\NodeRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\AllocationRepositoryInterface;
|
||||
|
||||
class StatisticsControllerTest extends ControllerTestCase
|
||||
{
|
||||
|
@ -88,7 +86,7 @@ class StatisticsControllerTest extends ControllerTestCase
|
|||
'disk' => [
|
||||
'value' => 1024,
|
||||
'max' => 512,
|
||||
]
|
||||
],
|
||||
]);
|
||||
|
||||
$controller->shouldReceive('injectJavascript')->once();
|
||||
|
@ -106,8 +104,7 @@ class StatisticsControllerTest extends ControllerTestCase
|
|||
$this->eggRepository,
|
||||
$this->nodeRepository,
|
||||
$this->serverRepository,
|
||||
$this->userRepository]
|
||||
$this->userRepository, ]
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@ namespace Tests\Unit\Http\Controllers\Base;
|
|||
|
||||
use Mockery as m;
|
||||
use Pterodactyl\Models\User;
|
||||
use Illuminate\Auth\AuthManager;
|
||||
use Illuminate\Auth\SessionGuard;
|
||||
use Prologue\Alerts\AlertsMessageBag;
|
||||
use Pterodactyl\Services\Users\UserUpdateService;
|
||||
use Tests\Unit\Http\Controllers\ControllerTestCase;
|
||||
|
@ -17,6 +19,16 @@ class AccountControllerTest extends ControllerTestCase
|
|||
*/
|
||||
protected $alert;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Auth\AuthManager|\Mockery\Mock
|
||||
*/
|
||||
protected $authManager;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Auth\SessionGuard|\Mockery\Mock
|
||||
*/
|
||||
protected $sessionGuard;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Users\UserUpdateService|\Mockery\Mock
|
||||
*/
|
||||
|
@ -31,6 +43,10 @@ class AccountControllerTest extends ControllerTestCase
|
|||
|
||||
$this->alert = m::mock(AlertsMessageBag::class);
|
||||
$this->updateService = m::mock(UserUpdateService::class);
|
||||
$this->authManager = m::mock(AuthManager::class);
|
||||
$this->sessionGuard = m::mock(SessionGuard::class);
|
||||
|
||||
$this->authManager->shouldReceive('guard')->once()->andReturn($this->sessionGuard);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -50,13 +66,11 @@ class AccountControllerTest extends ControllerTestCase
|
|||
public function testUpdateControllerForPassword()
|
||||
{
|
||||
$this->setRequestMockClass(AccountDataFormRequest::class);
|
||||
$user = $this->generateRequestUserModel();
|
||||
|
||||
$this->request->shouldReceive('input')->with('do_action')->andReturn('password');
|
||||
$this->request->shouldReceive('input')->with('new_password')->once()->andReturn('test-password');
|
||||
$this->sessionGuard->shouldReceive('logoutOtherDevices')->once()->with('test-password')->andReturnSelf();
|
||||
|
||||
$this->updateService->shouldReceive('setUserLevel')->with(User::USER_LEVEL_USER)->once()->andReturnNull();
|
||||
$this->updateService->shouldReceive('handle')->with($user, ['password' => 'test-password'])->once()->andReturn(collect());
|
||||
$this->alert->shouldReceive('success->flash')->once()->andReturnNull();
|
||||
|
||||
$response = $this->getController()->update($this->request);
|
||||
|
@ -113,6 +127,6 @@ class AccountControllerTest extends ControllerTestCase
|
|||
*/
|
||||
private function getController(): AccountController
|
||||
{
|
||||
return new AccountController($this->alert, $this->updateService);
|
||||
return new AccountController($this->alert, $this->authManager, $this->updateService);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -182,7 +182,7 @@ class SubuserControllerTest extends ControllerTestCase
|
|||
$response = $controller->store($this->request);
|
||||
$this->assertIsRedirectResponse($response);
|
||||
$this->assertRedirectRouteEquals('server.subusers.view', $response, [
|
||||
'uuid' => $server->uuid,
|
||||
'uuid' => $server->uuidShort,
|
||||
'id' => $subuser->hashid,
|
||||
]);
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ use Illuminate\Contracts\Session\Session;
|
|||
use Illuminate\Contracts\Config\Repository;
|
||||
use Illuminate\Contracts\Routing\ResponseFactory;
|
||||
use Tests\Unit\Http\Middleware\MiddlewareTestCase;
|
||||
use Pterodactyl\Http\Middleware\AccessingValidServer;
|
||||
use Pterodactyl\Http\Middleware\Server\AccessingValidServer;
|
||||
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
||||
|
||||
class AccessingValidServerTest extends MiddlewareTestCase
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
namespace Tests\Unit\Jobs\Schedule;
|
||||
|
||||
use Mockery as m;
|
||||
use Carbon\Carbon;
|
||||
use Tests\TestCase;
|
||||
use Cake\Chronos\Chronos;
|
||||
use Pterodactyl\Models\Task;
|
||||
use Pterodactyl\Models\User;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
|
@ -58,7 +58,7 @@ class RunTaskJobTest extends TestCase
|
|||
{
|
||||
parent::setUp();
|
||||
Bus::fake();
|
||||
Carbon::setTestNow(Carbon::now());
|
||||
Chronos::setTestNow(Chronos::now());
|
||||
|
||||
$this->commandRepository = m::mock(CommandRepositoryInterface::class);
|
||||
$this->config = m::mock(Repository::class);
|
||||
|
@ -94,7 +94,7 @@ class RunTaskJobTest extends TestCase
|
|||
|
||||
$this->scheduleRepository->shouldReceive('withoutFreshModel->update')->with($schedule->id, [
|
||||
'is_processing' => false,
|
||||
'last_run_at' => Carbon::now()->toDateTimeString(),
|
||||
'last_run_at' => Chronos::now()->toDateTimeString(),
|
||||
])->once()->andReturnNull();
|
||||
|
||||
$this->getJobInstance($task->id, $schedule->id);
|
||||
|
@ -124,7 +124,7 @@ class RunTaskJobTest extends TestCase
|
|||
|
||||
$this->scheduleRepository->shouldReceive('withoutFreshModel->update')->with($schedule->id, [
|
||||
'is_processing' => false,
|
||||
'last_run_at' => Carbon::now()->toDateTimeString(),
|
||||
'last_run_at' => Chronos::now()->toDateTimeString(),
|
||||
])->once()->andReturnNull();
|
||||
|
||||
$this->getJobInstance($task->id, $schedule->id);
|
||||
|
@ -202,7 +202,7 @@ class RunTaskJobTest extends TestCase
|
|||
|
||||
$this->scheduleRepository->shouldReceive('withoutFreshModel->update')->with($schedule->id, [
|
||||
'is_processing' => false,
|
||||
'last_run_at' => Carbon::now()->toDateTimeString(),
|
||||
'last_run_at' => Chronos::now()->toDateTimeString(),
|
||||
])->once()->andReturn(1);
|
||||
|
||||
$this->taskRepository->shouldReceive('update')->with($task->id, ['is_queued' => false])->once()->andReturn(1);
|
||||
|
|
|
@ -1,62 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Helpers;
|
||||
|
||||
use Mockery as m;
|
||||
use Tests\TestCase;
|
||||
use Tests\Traits\MocksUuids;
|
||||
use Illuminate\Contracts\Hashing\Hasher;
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
use Pterodactyl\Services\Helpers\TemporaryPasswordService;
|
||||
|
||||
class TemporaryPasswordServiceTest extends TestCase
|
||||
{
|
||||
use MocksUuids;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Database\ConnectionInterface|\Mockery\Mock
|
||||
*/
|
||||
protected $connection;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Contracts\Hashing\Hasher|\Mockery\Mock
|
||||
*/
|
||||
protected $hasher;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Helpers\TemporaryPasswordService
|
||||
*/
|
||||
protected $service;
|
||||
|
||||
/**
|
||||
* Setup tests.
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->connection = m::mock(ConnectionInterface::class);
|
||||
$this->hasher = m::mock(Hasher::class);
|
||||
|
||||
$this->service = new TemporaryPasswordService($this->connection, $this->hasher);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that a temporary password is stored and the token is returned.
|
||||
*/
|
||||
public function testTemporaryPasswordIsStored()
|
||||
{
|
||||
$token = hash_hmac(TemporaryPasswordService::HMAC_ALGO, $this->getKnownUuid(), config('app.key'));
|
||||
|
||||
$this->hasher->shouldReceive('make')->with($token)->once()->andReturn('hashed_token');
|
||||
$this->connection->shouldReceive('table')->with('password_resets')->once()->andReturnSelf();
|
||||
$this->connection->shouldReceive('insert')->with([
|
||||
'email' => 'test@example.com',
|
||||
'token' => 'hashed_token',
|
||||
])->once()->andReturnNull();
|
||||
|
||||
$response = $this->service->handle('test@example.com');
|
||||
$this->assertNotEmpty($response);
|
||||
$this->assertEquals($token, $response);
|
||||
}
|
||||
}
|
|
@ -1,11 +1,4 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* This software is licensed under the terms of the MIT license.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
namespace Tests\Unit\Services\Nodes;
|
||||
|
||||
|
@ -63,17 +56,17 @@ class NodeUpdateServiceTest extends TestCase
|
|||
->expects($this->once())->willReturn('random_string');
|
||||
|
||||
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('withoutFreshModel->update')->with($model->id, [
|
||||
$this->repository->shouldReceive('update')->with($model->id, [
|
||||
'name' => 'NewName',
|
||||
'daemonSecret' => 'random_string',
|
||||
])->andReturn(true);
|
||||
])->andReturn($model);
|
||||
|
||||
$this->configRepository->shouldReceive('setNode')->with($model)->once()->andReturnSelf()
|
||||
->shouldReceive('update')->withNoArgs()->once()->andReturn(new Response);
|
||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||
|
||||
$response = $this->getService()->returnUpdatedModel(false)->handle($model, ['name' => 'NewName', 'reset_secret' => true]);
|
||||
$this->assertTrue($response);
|
||||
$response = $this->getService()->handle($model, ['name' => 'NewName', 'reset_secret' => true]);
|
||||
$this->assertInstanceOf(Node::class, $response);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -83,37 +76,17 @@ class NodeUpdateServiceTest extends TestCase
|
|||
{
|
||||
$model = factory(Node::class)->make();
|
||||
|
||||
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('withoutFreshModel->update')->with($model->id, [
|
||||
'name' => 'NewName',
|
||||
])->andReturn(true);
|
||||
|
||||
$this->configRepository->shouldReceive('setNode')->with($model)->once()->andReturnSelf()
|
||||
->shouldReceive('update')->withNoArgs()->once()->andReturn(new Response);
|
||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||
|
||||
$response = $this->getService()->returnUpdatedModel(false)->handle($model, ['name' => 'NewName']);
|
||||
$this->assertTrue($response);
|
||||
}
|
||||
|
||||
public function testUpdatedModelIsReturned()
|
||||
{
|
||||
$model = factory(Node::class)->make();
|
||||
$updated = clone $model;
|
||||
$updated->name = 'NewName';
|
||||
|
||||
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('update')->with($model->id, [
|
||||
'name' => $updated->name,
|
||||
])->andReturn($updated);
|
||||
'name' => 'NewName',
|
||||
])->andReturn($model);
|
||||
|
||||
$this->configRepository->shouldReceive('setNode')->with($model)->once()->andReturnSelf()
|
||||
->shouldReceive('update')->withNoArgs()->once()->andReturn(new Response);
|
||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||
|
||||
$response = $this->getService()->returnUpdatedModel()->handle($model, ['name' => $updated->name]);
|
||||
$response = $this->getService()->handle($model, ['name' => 'NewName']);
|
||||
$this->assertInstanceOf(Node::class, $response);
|
||||
$this->assertSame($updated, $response);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -127,7 +100,7 @@ class NodeUpdateServiceTest extends TestCase
|
|||
$model = factory(Node::class)->make();
|
||||
|
||||
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('withoutFreshModel->update')->andReturn(new Response);
|
||||
$this->repository->shouldReceive('update')->andReturn($model);
|
||||
|
||||
$this->configRepository->shouldReceive('setNode->update')->once()->andThrow($this->getExceptionMock());
|
||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||
|
@ -146,7 +119,7 @@ class NodeUpdateServiceTest extends TestCase
|
|||
$model = factory(Node::class)->make();
|
||||
|
||||
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('withoutFreshModel->update')->andReturn(new Response);
|
||||
$this->repository->shouldReceive('update')->andReturn($model);
|
||||
|
||||
$this->configRepository->shouldReceive('setNode->update')->once()->andThrow($this->getExceptionMock());
|
||||
|
||||
|
|
|
@ -3,36 +3,32 @@
|
|||
namespace Tests\Unit\Services\Schedules;
|
||||
|
||||
use Mockery as m;
|
||||
use Carbon\Carbon;
|
||||
use Tests\TestCase;
|
||||
use Cron\CronExpression;
|
||||
use Pterodactyl\Models\Task;
|
||||
use Pterodactyl\Models\Schedule;
|
||||
use Pterodactyl\Services\Schedules\Tasks\RunTaskService;
|
||||
use Illuminate\Contracts\Bus\Dispatcher;
|
||||
use Pterodactyl\Jobs\Schedule\RunTaskJob;
|
||||
use Pterodactyl\Services\Schedules\ProcessScheduleService;
|
||||
use Pterodactyl\Contracts\Repository\TaskRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface;
|
||||
|
||||
class ProcessScheduleServiceTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Cron\CronExpression|\Mockery\Mock
|
||||
* @var \Illuminate\Contracts\Bus\Dispatcher|\Mockery\Mock
|
||||
*/
|
||||
protected $cron;
|
||||
private $dispatcher;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface|\Mockery\Mock
|
||||
*/
|
||||
protected $repository;
|
||||
private $scheduleRepository;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Schedules\Tasks\RunTaskService|\Mockery\Mock
|
||||
* @var \Pterodactyl\Contracts\Repository\TaskRepositoryInterface|\Mockery\Mock
|
||||
*/
|
||||
protected $runnerService;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Schedules\ProcessScheduleService
|
||||
*/
|
||||
protected $service;
|
||||
private $taskRepository;
|
||||
|
||||
/**
|
||||
* Setup tests.
|
||||
|
@ -40,12 +36,10 @@ class ProcessScheduleServiceTest extends TestCase
|
|||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
Carbon::setTestNow(Carbon::now());
|
||||
|
||||
$this->repository = m::mock(ScheduleRepositoryInterface::class);
|
||||
$this->runnerService = m::mock(RunTaskService::class);
|
||||
|
||||
$this->service = new ProcessScheduleService($this->runnerService, $this->repository);
|
||||
$this->dispatcher = m::mock(Dispatcher::class);
|
||||
$this->scheduleRepository = m::mock(ScheduleRepositoryInterface::class);
|
||||
$this->taskRepository = m::mock(TaskRepositoryInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -58,37 +52,36 @@ class ProcessScheduleServiceTest extends TestCase
|
|||
'sequence_id' => 1,
|
||||
])]));
|
||||
|
||||
$this->repository->shouldReceive('loadTasks')->with($model)->once()->andReturn($model);
|
||||
$this->scheduleRepository->shouldReceive('loadTasks')->with($model)->once()->andReturn($model);
|
||||
|
||||
$formatted = sprintf('%s %s %s * %s', $model->cron_minute, $model->cron_hour, $model->cron_day_of_month, $model->cron_day_of_week);
|
||||
$this->repository->shouldReceive('update')->with($model->id, [
|
||||
$this->scheduleRepository->shouldReceive('update')->with($model->id, [
|
||||
'is_processing' => true,
|
||||
'next_run_at' => CronExpression::factory($formatted)->getNextRunDate(),
|
||||
]);
|
||||
|
||||
$this->runnerService->shouldReceive('handle')->with($task)->once()->andReturnNull();
|
||||
$this->taskRepository->shouldReceive('update')->with($task->id, ['is_queued' => true])->once();
|
||||
|
||||
$this->service->handle($model);
|
||||
$this->dispatcher->shouldReceive('dispatch')->with(m::on(function ($class) use ($model, $task) {
|
||||
$this->assertInstanceOf(RunTaskJob::class, $class);
|
||||
$this->assertSame($task->time_offset, $class->delay);
|
||||
$this->assertSame($task->id, $class->task);
|
||||
$this->assertSame($model->id, $class->schedule);
|
||||
|
||||
return true;
|
||||
}))->once();
|
||||
|
||||
$this->getService()->handle($model);
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
public function testScheduleRunTimeCanBeOverridden()
|
||||
/**
|
||||
* Return an instance of the service for testing purposes.
|
||||
*
|
||||
* @return \Pterodactyl\Services\Schedules\ProcessScheduleService
|
||||
*/
|
||||
private function getService(): ProcessScheduleService
|
||||
{
|
||||
$model = factory(Schedule::class)->make();
|
||||
$model->setRelation('tasks', collect([$task = factory(Task::class)->make([
|
||||
'sequence_id' => 1,
|
||||
])]));
|
||||
|
||||
$this->repository->shouldReceive('loadTasks')->with($model)->once()->andReturn($model);
|
||||
|
||||
$this->repository->shouldReceive('update')->with($model->id, [
|
||||
'is_processing' => true,
|
||||
'next_run_at' => Carbon::now()->addSeconds(15)->toDateTimeString(),
|
||||
]);
|
||||
|
||||
$this->runnerService->shouldReceive('handle')->with($task)->once()->andReturnNull();
|
||||
|
||||
$this->service->setRunTimeOverride(Carbon::now()->addSeconds(15))->handle($model);
|
||||
$this->assertTrue(true);
|
||||
return new ProcessScheduleService($this->dispatcher, $this->scheduleRepository, $this->taskRepository);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,90 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* This software is licensed under the terms of the MIT license.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
namespace Tests\Unit\Services\Schedules\Tasks;
|
||||
|
||||
use Mockery as m;
|
||||
use Tests\TestCase;
|
||||
use Pterodactyl\Models\Task;
|
||||
use Illuminate\Support\Facades\Bus;
|
||||
use Pterodactyl\Jobs\Schedule\RunTaskJob;
|
||||
use Pterodactyl\Services\Schedules\Tasks\RunTaskService;
|
||||
use Pterodactyl\Contracts\Repository\TaskRepositoryInterface;
|
||||
|
||||
class RunTaskServiceTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Illuminate\Contracts\Bus\Dispatcher|\Mockery\Mock
|
||||
*/
|
||||
protected $dispatcher;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\TaskRepositoryInterface|\Mockery\Mock
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Schedules\Tasks\RunTaskService
|
||||
*/
|
||||
protected $service;
|
||||
|
||||
/**
|
||||
* Setup tests.
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
Bus::fake();
|
||||
$this->repository = m::mock(TaskRepositoryInterface::class);
|
||||
|
||||
$this->service = new RunTaskService($this->repository);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that a job is dispatched.
|
||||
*/
|
||||
public function testTaskIsDispatched()
|
||||
{
|
||||
$task = factory(Task::class)->make();
|
||||
|
||||
$this->repository->shouldReceive('update')->with($task->id, ['is_queued' => true])->once()->andReturnNull();
|
||||
|
||||
$this->service->handle($task);
|
||||
|
||||
Bus::assertDispatched(RunTaskJob::class, function ($job) use ($task) {
|
||||
$this->assertEquals($task->id, $job->task, 'Assert job task matches parent task model.');
|
||||
$this->assertEquals($task->schedule_id, $job->schedule, 'Assert job is linked to correct schedule.');
|
||||
$this->assertEquals($task->time_offset, $job->delay, 'Assert job delay is set correctly to match task.');
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that passing an ID in place of a model works.
|
||||
*/
|
||||
public function testIdCanBePassedInPlaceOfModel()
|
||||
{
|
||||
$task = factory(Task::class)->make();
|
||||
|
||||
$this->repository->shouldReceive('find')->with($task->id)->once()->andReturn($task);
|
||||
$this->repository->shouldReceive('update')->with($task->id, ['is_queued' => true])->once()->andReturnNull();
|
||||
|
||||
$this->service->handle($task->id);
|
||||
|
||||
Bus::assertDispatched(RunTaskJob::class, function ($job) use ($task) {
|
||||
$this->assertEquals($task->id, $job->task, 'Assert job task matches parent task model.');
|
||||
$this->assertEquals($task->schedule_id, $job->schedule, 'Assert job is linked to correct schedule.');
|
||||
$this->assertEquals($task->time_offset, $job->delay, 'Assert job delay is set correctly to match task.');
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
|
@ -12,7 +12,7 @@ use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
|||
|
||||
class EnvironmentServiceTest extends TestCase
|
||||
{
|
||||
const CONFIG_MAPPING = 'pterodactyl.environment_mappings';
|
||||
const CONFIG_MAPPING = 'pterodactyl.environment_variables';
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Contracts\Config\Repository|\Mockery\Mock
|
||||
|
|
|
@ -9,9 +9,9 @@ use Tests\Traits\MocksUuids;
|
|||
use Illuminate\Contracts\Hashing\Hasher;
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Illuminate\Contracts\Auth\PasswordBroker;
|
||||
use Pterodactyl\Notifications\AccountCreated;
|
||||
use Pterodactyl\Services\Users\UserCreationService;
|
||||
use Pterodactyl\Services\Helpers\TemporaryPasswordService;
|
||||
use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
|
||||
|
||||
class UserCreationServiceTest extends TestCase
|
||||
|
@ -29,9 +29,9 @@ class UserCreationServiceTest extends TestCase
|
|||
private $hasher;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Helpers\TemporaryPasswordService|\Mockery\Mock
|
||||
* @var \Illuminate\Contracts\Auth\PasswordBroker|\Mockery\Mock
|
||||
*/
|
||||
private $passwordService;
|
||||
private $passwordBroker;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\UserRepositoryInterface|\Mockery\Mock
|
||||
|
@ -48,7 +48,7 @@ class UserCreationServiceTest extends TestCase
|
|||
Notification::fake();
|
||||
$this->connection = m::mock(ConnectionInterface::class);
|
||||
$this->hasher = m::mock(Hasher::class);
|
||||
$this->passwordService = m::mock(TemporaryPasswordService::class);
|
||||
$this->passwordBroker = m::mock(PasswordBroker::class);
|
||||
$this->repository = m::mock(UserRepositoryInterface::class);
|
||||
}
|
||||
|
||||
|
@ -121,7 +121,7 @@ class UserCreationServiceTest extends TestCase
|
|||
$this->hasher->shouldNotReceive('make');
|
||||
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
||||
$this->hasher->shouldReceive('make')->once()->andReturn('created-enc-password');
|
||||
$this->passwordService->shouldReceive('handle')->with($user->email)->once()->andReturn('random-token');
|
||||
$this->passwordBroker->shouldReceive('createToken')->with($user)->once()->andReturn('random-token');
|
||||
|
||||
$this->repository->shouldReceive('create')->with([
|
||||
'password' => 'created-enc-password',
|
||||
|
@ -152,6 +152,6 @@ class UserCreationServiceTest extends TestCase
|
|||
*/
|
||||
private function getService(): UserCreationService
|
||||
{
|
||||
return new UserCreationService($this->connection, $this->hasher, $this->passwordService, $this->repository);
|
||||
return new UserCreationService($this->connection, $this->hasher, $this->passwordBroker, $this->repository);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue