2018-02-11 23:32:45 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Unit\Services\Servers;
|
|
|
|
|
|
|
|
use Mockery as m;
|
|
|
|
use Tests\TestCase;
|
|
|
|
use Pterodactyl\Models\Server;
|
|
|
|
use Pterodactyl\Models\Allocation;
|
|
|
|
use Pterodactyl\Models\EggVariable;
|
2020-08-22 22:43:28 +00:00
|
|
|
use Pterodactyl\Services\Servers\StartupCommandService;
|
2018-02-11 23:32:45 +00:00
|
|
|
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
|
|
|
|
|
|
|
class StartupCommandViewServiceTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface|\Mockery\Mock
|
|
|
|
*/
|
|
|
|
private $repository;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup tests.
|
|
|
|
*/
|
2020-05-09 16:00:52 +00:00
|
|
|
public function setUp(): void
|
2018-02-11 23:32:45 +00:00
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->repository = m::mock(ServerRepositoryInterface::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that the correct startup string is returned.
|
|
|
|
*/
|
|
|
|
public function testServiceResponse()
|
|
|
|
{
|
2020-10-06 04:54:29 +00:00
|
|
|
|
2018-02-11 23:32:45 +00:00
|
|
|
$server = factory(Server::class)->make([
|
2020-10-06 04:54:29 +00:00
|
|
|
'id' => 123,
|
2018-02-11 23:32:45 +00:00
|
|
|
'startup' => 'example {{SERVER_MEMORY}} {{SERVER_IP}} {{SERVER_PORT}} {{TEST_VARIABLE}} {{TEST_VARIABLE_HIDDEN}} {{UNKNOWN}}',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$variables = collect([
|
2020-10-06 04:54:29 +00:00
|
|
|
factory(EggVariable::class)->make([
|
|
|
|
'env_variable' => 'TEST_VARIABLE',
|
|
|
|
'server_value' => 'Test Value',
|
|
|
|
'user_viewable' => 1,
|
|
|
|
]),
|
|
|
|
factory(EggVariable::class)->make([
|
|
|
|
'env_variable' => 'TEST_VARIABLE_HIDDEN',
|
|
|
|
'server_value' => 'Hidden Value',
|
|
|
|
'user_viewable' => 0,
|
|
|
|
]),
|
2018-02-11 23:32:45 +00:00
|
|
|
]);
|
|
|
|
|
2020-10-06 04:54:29 +00:00
|
|
|
$server->setRelation('variables', $variables);
|
|
|
|
$server->setRelation('allocation', $allocation = factory(Allocation::class)->make());
|
2018-02-11 23:32:45 +00:00
|
|
|
|
2020-10-06 04:54:29 +00:00
|
|
|
$response = $this->getService()->handle($server);
|
2018-02-11 23:32:45 +00:00
|
|
|
$this->assertSame(
|
|
|
|
sprintf('example %s %s %s %s %s {{UNKNOWN}}', $server->memory, $allocation->ip, $allocation->port, 'Test Value', '[hidden]'),
|
2020-10-06 04:54:29 +00:00
|
|
|
$response
|
2018-02-11 23:32:45 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return an instance of the service with mocked dependencies.
|
|
|
|
*
|
2020-08-22 22:43:28 +00:00
|
|
|
* @return \Pterodactyl\Services\Servers\StartupCommandService
|
2018-02-11 23:32:45 +00:00
|
|
|
*/
|
2020-08-22 22:43:28 +00:00
|
|
|
private function getService(): StartupCommandService
|
2018-02-11 23:32:45 +00:00
|
|
|
{
|
2020-10-06 04:54:29 +00:00
|
|
|
return new StartupCommandService;
|
2018-02-11 23:32:45 +00:00
|
|
|
}
|
|
|
|
}
|