2017-10-05 04:42:04 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Pterodactyl - Panel
|
|
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
|
|
|
*
|
|
|
|
* This software is licensed under the terms of the MIT license.
|
|
|
|
* https://opensource.org/licenses/MIT
|
|
|
|
*/
|
|
|
|
|
2017-10-08 04:29:08 +00:00
|
|
|
namespace Tests\Unit\Services\Eggs\Sharing;
|
2017-10-05 04:42:04 +00:00
|
|
|
|
|
|
|
use Mockery as m;
|
|
|
|
use Carbon\Carbon;
|
|
|
|
use Tests\TestCase;
|
2017-10-07 04:57:53 +00:00
|
|
|
use Pterodactyl\Models\Egg;
|
|
|
|
use Pterodactyl\Models\EggVariable;
|
2017-10-05 04:42:04 +00:00
|
|
|
use Tests\Assertions\NestedObjectAssertionsTrait;
|
2017-10-08 04:29:08 +00:00
|
|
|
use Pterodactyl\Services\Eggs\Sharing\EggExporterService;
|
2017-10-07 04:57:53 +00:00
|
|
|
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
|
2017-10-05 04:42:04 +00:00
|
|
|
|
2017-10-08 04:29:08 +00:00
|
|
|
class EggExporterServiceTest extends TestCase
|
2017-10-05 04:42:04 +00:00
|
|
|
{
|
|
|
|
use NestedObjectAssertionsTrait;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Carbon\Carbon
|
|
|
|
*/
|
|
|
|
protected $carbon;
|
|
|
|
|
|
|
|
/**
|
2017-10-07 04:57:53 +00:00
|
|
|
* @var \Pterodactyl\Contracts\Repository\EggRepositoryInterface|\Mockery\Mock
|
2017-10-05 04:42:04 +00:00
|
|
|
*/
|
|
|
|
protected $repository;
|
|
|
|
|
|
|
|
/**
|
2017-10-08 04:29:08 +00:00
|
|
|
* @var \Pterodactyl\Services\Eggs\Sharing\EggExporterService
|
2017-10-05 04:42:04 +00:00
|
|
|
*/
|
|
|
|
protected $service;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup tests.
|
|
|
|
*/
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
Carbon::setTestNow(Carbon::now());
|
|
|
|
$this->carbon = new Carbon();
|
2017-10-07 04:57:53 +00:00
|
|
|
$this->repository = m::mock(EggRepositoryInterface::class);
|
2017-10-05 04:42:04 +00:00
|
|
|
|
2017-10-08 04:29:08 +00:00
|
|
|
$this->service = new EggExporterService($this->repository);
|
2017-10-05 04:42:04 +00:00
|
|
|
}
|
|
|
|
|
2017-10-05 04:52:25 +00:00
|
|
|
/**
|
|
|
|
* Test that a JSON structure is returned.
|
|
|
|
*/
|
2017-10-05 04:42:04 +00:00
|
|
|
public function testJsonStructureIsExported()
|
|
|
|
{
|
2017-10-08 04:29:08 +00:00
|
|
|
$egg = factory(Egg::class)->make();
|
|
|
|
$egg->variables = collect([$variable = factory(EggVariable::class)->make()]);
|
2017-10-05 04:42:04 +00:00
|
|
|
|
2017-10-08 04:29:08 +00:00
|
|
|
$this->repository->shouldReceive('getWithExportAttributes')->with($egg->id)->once()->andReturn($egg);
|
2017-10-05 04:42:04 +00:00
|
|
|
|
2017-10-08 04:29:08 +00:00
|
|
|
$response = $this->service->handle($egg->id);
|
2017-10-05 04:42:04 +00:00
|
|
|
$this->assertNotEmpty($response);
|
|
|
|
|
|
|
|
$data = json_decode($response);
|
|
|
|
$this->assertEquals(JSON_ERROR_NONE, json_last_error());
|
|
|
|
$this->assertObjectHasNestedAttribute('meta.version', $data);
|
|
|
|
$this->assertObjectNestedValueEquals('meta.version', 'PTDL_v1', $data);
|
2017-10-08 04:29:08 +00:00
|
|
|
$this->assertObjectHasNestedAttribute('author', $data);
|
|
|
|
$this->assertObjectNestedValueEquals('author', $egg->author, $data);
|
2017-10-05 04:42:04 +00:00
|
|
|
$this->assertObjectHasNestedAttribute('exported_at', $data);
|
|
|
|
$this->assertObjectNestedValueEquals('exported_at', Carbon::now()->toIso8601String(), $data);
|
|
|
|
$this->assertObjectHasNestedAttribute('scripts.installation.script', $data);
|
|
|
|
$this->assertObjectHasNestedAttribute('scripts.installation.container', $data);
|
|
|
|
$this->assertObjectHasNestedAttribute('scripts.installation.entrypoint', $data);
|
|
|
|
$this->assertObjectHasAttribute('variables', $data);
|
|
|
|
$this->assertArrayHasKey('0', $data->variables);
|
|
|
|
$this->assertObjectHasAttribute('name', $data->variables[0]);
|
|
|
|
$this->assertObjectNestedValueEquals('name', $variable->name, $data->variables[0]);
|
|
|
|
}
|
|
|
|
}
|