2017-08-26 18:31:18 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* 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-08-26 18:31:18 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Tests\Unit\Services\Subusers;
|
|
|
|
|
|
|
|
use Mockery as m;
|
2017-08-27 19:55:25 +00:00
|
|
|
use Tests\TestCase;
|
2017-08-26 18:31:18 +00:00
|
|
|
use Pterodactyl\Models\Subuser;
|
2017-08-27 19:55:25 +00:00
|
|
|
use Illuminate\Database\ConnectionInterface;
|
2017-08-26 18:31:18 +00:00
|
|
|
use Pterodactyl\Services\Subusers\SubuserDeletionService;
|
2017-09-25 03:28:16 +00:00
|
|
|
use Pterodactyl\Services\DaemonKeys\DaemonKeyDeletionService;
|
2017-08-27 19:55:25 +00:00
|
|
|
use Pterodactyl\Contracts\Repository\SubuserRepositoryInterface;
|
2017-08-26 18:31:18 +00:00
|
|
|
|
|
|
|
class SubuserDeletionServiceTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
2017-09-25 03:28:16 +00:00
|
|
|
* @var \Illuminate\Database\ConnectionInterface|\Mockery\Mock
|
2017-08-26 18:31:18 +00:00
|
|
|
*/
|
|
|
|
protected $connection;
|
|
|
|
|
|
|
|
/**
|
2017-09-25 03:28:16 +00:00
|
|
|
* @var \Pterodactyl\Services\DaemonKeys\DaemonKeyDeletionService|\Mockery\Mock
|
2017-08-26 18:31:18 +00:00
|
|
|
*/
|
2017-09-25 03:28:16 +00:00
|
|
|
protected $keyDeletionService;
|
2017-08-26 18:31:18 +00:00
|
|
|
|
|
|
|
/**
|
2017-09-25 03:28:16 +00:00
|
|
|
* @var \Pterodactyl\Contracts\Repository\SubuserRepositoryInterface|\Mockery\Mock
|
2017-08-26 18:31:18 +00:00
|
|
|
*/
|
|
|
|
protected $repository;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Services\Subusers\SubuserDeletionService
|
|
|
|
*/
|
|
|
|
protected $service;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup tests.
|
|
|
|
*/
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->connection = m::mock(ConnectionInterface::class);
|
2017-09-25 03:28:16 +00:00
|
|
|
$this->keyDeletionService = m::mock(DaemonKeyDeletionService::class);
|
2017-08-26 18:31:18 +00:00
|
|
|
$this->repository = m::mock(SubuserRepositoryInterface::class);
|
|
|
|
|
|
|
|
$this->service = new SubuserDeletionService(
|
|
|
|
$this->connection,
|
2017-09-25 03:28:16 +00:00
|
|
|
$this->keyDeletionService,
|
|
|
|
$this->repository
|
2017-08-26 18:31:18 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that a subuser is deleted correctly.
|
|
|
|
*/
|
2017-09-25 03:28:16 +00:00
|
|
|
public function testSubuserIsDeletedIfModelIsPassed()
|
2017-08-26 18:31:18 +00:00
|
|
|
{
|
|
|
|
$subuser = factory(Subuser::class)->make();
|
|
|
|
|
|
|
|
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
2017-09-25 03:28:16 +00:00
|
|
|
$this->keyDeletionService->shouldReceive('handle')->with($subuser->server_id, $subuser->user_id)->once()->andReturnNull();
|
|
|
|
$this->repository->shouldReceive('delete')->with($subuser->id)->once()->andReturnNull();
|
2017-08-26 18:31:18 +00:00
|
|
|
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
|
|
|
|
2017-09-25 03:28:16 +00:00
|
|
|
$this->service->handle($subuser);
|
|
|
|
$this->assertTrue(true);
|
2017-08-26 18:31:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-09-25 03:28:16 +00:00
|
|
|
* Test that a subuser is deleted correctly if only the subuser ID is passed.
|
2017-08-26 18:31:18 +00:00
|
|
|
*/
|
2017-09-25 03:28:16 +00:00
|
|
|
public function testSubuserIsDeletedIfIdPassedInPlaceOfModel()
|
2017-08-26 18:31:18 +00:00
|
|
|
{
|
|
|
|
$subuser = factory(Subuser::class)->make();
|
|
|
|
|
2017-09-25 03:28:16 +00:00
|
|
|
$this->repository->shouldReceive('find')->with($subuser->id)->once()->andReturn($subuser);
|
2017-08-26 18:31:18 +00:00
|
|
|
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
2017-09-25 03:28:16 +00:00
|
|
|
$this->keyDeletionService->shouldReceive('handle')->with($subuser->server_id, $subuser->user_id)->once()->andReturnNull();
|
|
|
|
$this->repository->shouldReceive('delete')->with($subuser->id)->once()->andReturnNull();
|
|
|
|
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
2017-08-26 18:31:18 +00:00
|
|
|
|
2017-09-25 03:28:16 +00:00
|
|
|
$this->service->handle($subuser->id);
|
|
|
|
$this->assertTrue(true);
|
2017-08-26 18:31:18 +00:00
|
|
|
}
|
|
|
|
}
|