2017-09-20 03:10:14 +00:00
|
|
|
<?php
|
2017-09-26 02:43:01 +00:00
|
|
|
/**
|
2017-09-20 03:10:14 +00:00
|
|
|
* Pterodactyl - Panel
|
|
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
|
|
|
*
|
2017-09-26 02:43:01 +00:00
|
|
|
* This software is licensed under the terms of the MIT license.
|
|
|
|
* https://opensource.org/licenses/MIT
|
2017-09-20 03:10:14 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Tests\Unit\Commands\Schedule;
|
|
|
|
|
|
|
|
use Mockery as m;
|
2018-09-01 03:52:15 +00:00
|
|
|
use Cake\Chronos\Chronos;
|
2017-09-20 03:10:14 +00:00
|
|
|
use Pterodactyl\Models\Task;
|
|
|
|
use Pterodactyl\Models\Schedule;
|
|
|
|
use Tests\Unit\Commands\CommandTestCase;
|
|
|
|
use Pterodactyl\Services\Schedules\ProcessScheduleService;
|
|
|
|
use Pterodactyl\Console\Commands\Schedule\ProcessRunnableCommand;
|
|
|
|
use Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface;
|
|
|
|
|
|
|
|
class ProcessRunnableCommandTest extends CommandTestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Console\Commands\Schedule\ProcessRunnableCommand
|
|
|
|
*/
|
|
|
|
protected $command;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Services\Schedules\ProcessScheduleService
|
|
|
|
*/
|
|
|
|
protected $processScheduleService;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface
|
|
|
|
*/
|
|
|
|
protected $repository;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup tests.
|
|
|
|
*/
|
2020-05-09 16:00:52 +00:00
|
|
|
public function setUp(): void
|
2017-09-20 03:10:14 +00:00
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
2018-09-01 03:52:15 +00:00
|
|
|
Chronos::setTestNow(Chronos::now());
|
|
|
|
|
2017-09-20 03:10:14 +00:00
|
|
|
$this->processScheduleService = m::mock(ProcessScheduleService::class);
|
|
|
|
$this->repository = m::mock(ScheduleRepositoryInterface::class);
|
|
|
|
|
2018-09-01 03:52:15 +00:00
|
|
|
$this->command = new ProcessRunnableCommand($this->processScheduleService, $this->repository);
|
2017-09-20 03:10:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that a schedule can be queued up correctly.
|
|
|
|
*/
|
|
|
|
public function testScheduleIsQueued()
|
|
|
|
{
|
|
|
|
$schedule = factory(Schedule::class)->make();
|
|
|
|
$schedule->tasks = collect([factory(Task::class)->make()]);
|
|
|
|
|
2018-09-01 03:52:15 +00:00
|
|
|
$this->repository->shouldReceive('getSchedulesToProcess')->with(Chronos::now()->toAtomString())->once()->andReturn(collect([$schedule]));
|
2017-09-20 03:10:14 +00:00
|
|
|
$this->processScheduleService->shouldReceive('handle')->with($schedule)->once()->andReturnNull();
|
|
|
|
|
|
|
|
$display = $this->runCommand($this->command);
|
2017-09-22 05:30:09 +00:00
|
|
|
|
2017-09-20 03:10:14 +00:00
|
|
|
$this->assertNotEmpty($display);
|
|
|
|
$this->assertContains(trans('command/messages.schedule.output_line', [
|
|
|
|
'schedule' => $schedule->name,
|
|
|
|
'hash' => $schedule->hashid,
|
|
|
|
]), $display);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If tasks is an empty collection, don't process it.
|
|
|
|
*/
|
|
|
|
public function testScheduleWithNoTasksIsNotProcessed()
|
|
|
|
{
|
|
|
|
$schedule = factory(Schedule::class)->make();
|
|
|
|
$schedule->tasks = collect([]);
|
|
|
|
|
2018-09-01 03:52:15 +00:00
|
|
|
$this->repository->shouldReceive('getSchedulesToProcess')->with(Chronos::now()->toAtomString())->once()->andReturn(collect([$schedule]));
|
2017-09-20 03:10:14 +00:00
|
|
|
|
|
|
|
$display = $this->runCommand($this->command);
|
2017-09-22 05:30:09 +00:00
|
|
|
|
2017-09-20 03:10:14 +00:00
|
|
|
$this->assertNotEmpty($display);
|
|
|
|
$this->assertNotContains(trans('command/messages.schedule.output_line', [
|
|
|
|
'schedule' => $schedule->name,
|
|
|
|
'hash' => $schedule->hashid,
|
|
|
|
]), $display);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If tasks isn't an instance of a collection, don't process it.
|
|
|
|
*/
|
|
|
|
public function testScheduleWithTasksObjectThatIsNotInstanceOfCollectionIsNotProcessed()
|
|
|
|
{
|
|
|
|
$schedule = factory(Schedule::class)->make(['tasks' => null]);
|
|
|
|
|
2018-09-01 03:52:15 +00:00
|
|
|
$this->repository->shouldReceive('getSchedulesToProcess')->with(Chronos::now()->toAtomString())->once()->andReturn(collect([$schedule]));
|
2017-09-20 03:10:14 +00:00
|
|
|
|
|
|
|
$display = $this->runCommand($this->command);
|
2017-09-22 05:30:09 +00:00
|
|
|
|
2017-09-20 03:10:14 +00:00
|
|
|
$this->assertNotEmpty($display);
|
|
|
|
$this->assertNotContains(trans('command/messages.schedule.output_line', [
|
|
|
|
'schedule' => $schedule->name,
|
|
|
|
'hash' => $schedule->hashid,
|
|
|
|
]), $display);
|
|
|
|
}
|
|
|
|
}
|