2017-08-22 02:00:14 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Pterodactyl - Panel
|
|
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
* copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Tests\Unit\Services\Packs;
|
|
|
|
|
|
|
|
use Mockery as m;
|
2017-08-27 19:55:25 +00:00
|
|
|
use Tests\TestCase;
|
2017-08-22 02:00:14 +00:00
|
|
|
use Pterodactyl\Models\Pack;
|
|
|
|
use Pterodactyl\Services\Packs\PackUpdateService;
|
2017-08-27 19:55:25 +00:00
|
|
|
use Pterodactyl\Contracts\Repository\PackRepositoryInterface;
|
|
|
|
use Pterodactyl\Exceptions\Service\HasActiveServersException;
|
|
|
|
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
2017-08-22 02:00:14 +00:00
|
|
|
|
|
|
|
class PackUpdateServiceTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Contracts\Repository\PackRepositoryInterface
|
|
|
|
*/
|
|
|
|
protected $repository;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
|
|
|
|
*/
|
|
|
|
protected $serverRepository;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Services\Packs\PackUpdateService
|
|
|
|
*/
|
|
|
|
protected $service;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup tests.
|
|
|
|
*/
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->repository = m::mock(PackRepositoryInterface::class);
|
|
|
|
$this->serverRepository = m::mock(ServerRepositoryInterface::class);
|
|
|
|
|
|
|
|
$this->service = new PackUpdateService($this->repository, $this->serverRepository);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that a pack is updated.
|
|
|
|
*/
|
|
|
|
public function testPackIsUpdated()
|
|
|
|
{
|
|
|
|
$model = factory(Pack::class)->make();
|
|
|
|
$this->repository->shouldReceive('withoutFresh')->withNoArgs()->once()->andReturnSelf()
|
|
|
|
->shouldReceive('update')->with($model->id, [
|
|
|
|
'locked' => false,
|
|
|
|
'visible' => false,
|
|
|
|
'selectable' => false,
|
2017-08-22 03:10:48 +00:00
|
|
|
'test-data' => 'value',
|
2017-08-22 02:00:14 +00:00
|
|
|
])->once()->andReturn(1);
|
|
|
|
|
|
|
|
$this->assertEquals(1, $this->service->handle($model, ['test-data' => 'value']));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that an exception is thrown if the pack option ID is changed while servers are using the pack.
|
|
|
|
*/
|
|
|
|
public function testExceptionIsThrownIfModifyingOptionIdWhenServersAreAttached()
|
|
|
|
{
|
|
|
|
$model = factory(Pack::class)->make();
|
|
|
|
$this->serverRepository->shouldReceive('findCountWhere')->with([['pack_id', '=', $model->id]])->once()->andReturn(1);
|
|
|
|
|
|
|
|
try {
|
|
|
|
$this->service->handle($model, ['option_id' => 0]);
|
|
|
|
} catch (HasActiveServersException $exception) {
|
|
|
|
$this->assertEquals(trans('admin/exceptions.packs.update_has_servers'), $exception->getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that an ID for a pack can be passed in place of the model.
|
|
|
|
*/
|
|
|
|
public function testPackIdCanBePassedInPlaceOfModel()
|
|
|
|
{
|
|
|
|
$model = factory(Pack::class)->make();
|
|
|
|
|
|
|
|
$this->repository->shouldReceive('withColumns')->with(['id', 'option_id'])->once()->andReturnSelf()
|
|
|
|
->shouldReceive('find')->with($model->id)->once()->andReturn($model);
|
|
|
|
$this->repository->shouldReceive('withoutFresh')->withNoArgs()->once()->andReturnSelf()
|
|
|
|
->shouldReceive('update')->with($model->id, [
|
|
|
|
'locked' => false,
|
|
|
|
'visible' => false,
|
|
|
|
'selectable' => false,
|
2017-08-22 03:10:48 +00:00
|
|
|
'test-data' => 'value',
|
2017-08-22 02:00:14 +00:00
|
|
|
])->once()->andReturn(1);
|
|
|
|
|
|
|
|
$this->assertEquals(1, $this->service->handle($model->id, ['test-data' => 'value']));
|
|
|
|
}
|
|
|
|
}
|