Merge branch 'develop' into feature/vuejs
This commit is contained in:
commit
21ffa08d66
54 changed files with 407 additions and 243 deletions
82
tests/Unit/Http/Controllers/Admin/MailControllerTest.php
Normal file
82
tests/Unit/Http/Controllers/Admin/MailControllerTest.php
Normal file
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Unit\Http\Controllers;
|
||||
|
||||
use Mockery as m;
|
||||
use Prologue\Alerts\AlertsMessageBag;
|
||||
use Illuminate\Contracts\Console\Kernel;
|
||||
use Illuminate\Contracts\Encryption\Encrypter;
|
||||
use Illuminate\Contracts\Config\Repository as ConfigRepository;
|
||||
use Pterodactyl\Http\Controllers\Admin\Settings\MailController;
|
||||
use Pterodactyl\Contracts\Repository\SettingsRepositoryInterface;
|
||||
|
||||
class MailControllerTest extends ControllerTestCase
|
||||
{
|
||||
/**
|
||||
* @var \Prologue\Alerts\AlertsMessageBag
|
||||
*/
|
||||
private $alert;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Contracts\Config\Repository
|
||||
*/
|
||||
private $configRepository;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Contracts\Encryption\Encrypter
|
||||
*/
|
||||
private $encrypter;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Contracts\Console\Kernel
|
||||
*/
|
||||
private $kernel;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\SettingsRepositoryInterface
|
||||
*/
|
||||
private $settingsRepositoryInterface;
|
||||
|
||||
/**
|
||||
* Setup tests.
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->alert = m::mock(AlertsMessageBag::class);
|
||||
$this->configRepository = m::mock(ConfigRepository::class);
|
||||
$this->encrypter = m::mock(Encrypter::class);
|
||||
$this->kernel = m::mock(Kernel::class);
|
||||
$this->settingsRepositoryInterface = m::mock(SettingsRepositoryInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the mail controller for viewing mail settings page.
|
||||
*/
|
||||
public function testIndex()
|
||||
{
|
||||
$this->configRepository->shouldReceive('get');
|
||||
|
||||
$response = $this->getController()->index();
|
||||
|
||||
$this->assertIsViewResponse($response);
|
||||
$this->assertViewNameEquals('admin.settings.mail', $response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare a MailController using our mocks.
|
||||
*
|
||||
* @return MailController
|
||||
*/
|
||||
public function getController()
|
||||
{
|
||||
return new MailController(
|
||||
$this->alert,
|
||||
$this->configRepository,
|
||||
$this->encrypter,
|
||||
$this->kernel,
|
||||
$this->settingsRepositoryInterface
|
||||
);
|
||||
}
|
||||
}
|
|
@ -73,7 +73,7 @@ class IndexControllerTest extends ControllerTestCase
|
|||
|
||||
$this->request->shouldReceive('input')->with('query')->once()->andReturn('searchTerm');
|
||||
$this->repository->shouldReceive('setSearchTerm')->with('searchTerm')->once()->andReturnSelf()
|
||||
->shouldReceive('filterUserAccessServers')->with($model, User::FILTER_LEVEL_ALL)
|
||||
->shouldReceive('filterUserAccessServers')->with($model, User::FILTER_LEVEL_ALL, config('pterodactyl.paginate.frontend.servers'))
|
||||
->once()->andReturn($paginator);
|
||||
|
||||
$response = $this->controller->index($this->request);
|
||||
|
|
|
@ -51,21 +51,34 @@ class NodeUpdateServiceTest extends TestCase
|
|||
public function testNodeIsUpdatedAndDaemonSecretIsReset()
|
||||
{
|
||||
$model = factory(Node::class)->make();
|
||||
$updatedModel = factory(Node::class)->make([
|
||||
'name' => 'New Name',
|
||||
'daemonSecret' => 'abcd1234',
|
||||
]);
|
||||
|
||||
$this->getFunctionMock('\\Pterodactyl\\Services\\Nodes', 'str_random')
|
||||
->expects($this->once())->willReturn('random_string');
|
||||
->expects($this->once())->willReturn($updatedModel->daemonSecret);
|
||||
|
||||
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('update')->with($model->id, [
|
||||
'name' => 'NewName',
|
||||
'daemonSecret' => 'random_string',
|
||||
'name' => $updatedModel->name,
|
||||
'daemonSecret' => $updatedModel->daemonSecret,
|
||||
])->andReturn($model);
|
||||
|
||||
$this->configRepository->shouldReceive('setNode')->with($model)->once()->andReturnSelf()
|
||||
->shouldReceive('update')->withNoArgs()->once()->andReturn(new Response);
|
||||
$cloned = $updatedModel->replicate(['daemonSecret']);
|
||||
$cloned->daemonSecret = $model->daemonSecret;
|
||||
|
||||
$this->configRepository->shouldReceive('setNode')->with(m::on(function ($model) use ($updatedModel) {
|
||||
return $model->daemonSecret !== $updatedModel->daemonSecret;
|
||||
}))->once()->andReturnSelf();
|
||||
|
||||
$this->configRepository->shouldReceive('update')->with([
|
||||
'keys' => ['abcd1234'],
|
||||
])->once()->andReturn(new Response);
|
||||
|
||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||
|
||||
$response = $this->getService()->handle($model, ['name' => 'NewName', 'reset_secret' => true]);
|
||||
$response = $this->getService()->handle($model, ['name' => $updatedModel->name], true);
|
||||
$this->assertInstanceOf(Node::class, $response);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue