Fix some data integrity issues

This commit is contained in:
Dane Everitt 2018-02-17 13:37:53 -06:00
parent d52f8d9215
commit 241f7d0125
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
6 changed files with 41 additions and 37 deletions

View file

@ -37,13 +37,14 @@ class VariableCreationServiceTest extends TestCase
*/
public function testVariableIsCreatedAndStored()
{
$data = ['env_variable' => 'TEST_VAR_123'];
$this->repository->shouldReceive('create')->with([
$data = ['env_variable' => 'TEST_VAR_123', 'default_value' => 'test'];
$this->repository->shouldReceive('create')->with(m::subset([
'egg_id' => 1,
'default_value' => 'test',
'user_viewable' => false,
'user_editable' => false,
'env_variable' => 'TEST_VAR_123',
])->once()->andReturn(new EggVariable);
]))->once()->andReturn(new EggVariable);
$this->assertInstanceOf(EggVariable::class, $this->service->handle(1, $data));
}
@ -54,33 +55,31 @@ class VariableCreationServiceTest extends TestCase
public function testOptionsPassedInArrayKeyAreParsedProperly()
{
$data = ['env_variable' => 'TEST_VAR_123', 'options' => ['user_viewable', 'user_editable']];
$this->repository->shouldReceive('create')->with([
'egg_id' => 1,
$this->repository->shouldReceive('create')->with(m::subset([
'default_value' => '',
'user_viewable' => true,
'user_editable' => true,
'env_variable' => 'TEST_VAR_123',
'options' => ['user_viewable', 'user_editable'],
])->once()->andReturn(new EggVariable);
]))->once()->andReturn(new EggVariable);
$this->assertInstanceOf(EggVariable::class, $this->service->handle(1, $data));
}
/**
* Test that an empty (null) value passed in the option key is handled
* properly as an array.
* properly as an array. Also tests the same case aganist the default_value.
*
* @see https://github.com/Pterodactyl/Panel/issues/841
* @see https://github.com/Pterodactyl/Panel/issues/943
*/
public function testNullOptionValueIsPassedAsArray()
{
$data = ['env_variable' => 'TEST_VAR_123', 'options' => null];
$this->repository->shouldReceive('create')->with([
'egg_id' => 1,
$data = ['env_variable' => 'TEST_VAR_123', 'options' => null, 'default_value' => null];
$this->repository->shouldReceive('create')->with(m::subset([
'default_value' => '',
'user_viewable' => false,
'user_editable' => false,
'env_variable' => 'TEST_VAR_123',
'options' => null,
])->once()->andReturn(new EggVariable);
]))->once()->andReturn(new EggVariable);
$this->assertInstanceOf(EggVariable::class, $this->service->handle(1, $data));
}
@ -103,12 +102,9 @@ class VariableCreationServiceTest extends TestCase
public function testEggIdPassedInDataIsNotApplied()
{
$data = ['egg_id' => 123456, 'env_variable' => 'TEST_VAR_123'];
$this->repository->shouldReceive('create')->with([
$this->repository->shouldReceive('create')->with(m::subset([
'egg_id' => 1,
'user_viewable' => false,
'user_editable' => false,
'env_variable' => 'TEST_VAR_123',
])->once()->andReturn(new EggVariable);
]))->once()->andReturn(new EggVariable);
$this->assertInstanceOf(EggVariable::class, $this->service->handle(1, $data));
}

View file

@ -49,10 +49,9 @@ class VariableUpdateServiceTest extends TestCase
->shouldReceive('update')->with($this->model->id, m::subset([
'user_viewable' => false,
'user_editable' => false,
'test-data' => 'test-value',
]))->once()->andReturn(true);
$this->assertTrue($this->service->handle($this->model, ['test-data' => 'test-value']));
$this->assertTrue($this->service->handle($this->model, []));
}
/**
@ -62,12 +61,11 @@ class VariableUpdateServiceTest extends TestCase
*/
public function testNullDefaultValue()
{
$this->repository->shouldReceive('withoutFreshModel')->withNoArgs()->once()->andReturnSelf()
->shouldReceive('update')->with($this->model->id, [
'user_viewable' => false,
'user_editable' => false,
'default_value' => '',
])->once()->andReturn(true);
$this->repository->shouldReceive('withoutFreshModel->update')->with($this->model->id, m::subset([
'user_viewable' => false,
'user_editable' => false,
'default_value' => '',
]))->once()->andReturn(true);
$this->assertTrue($this->service->handle($this->model, ['default_value' => null]));
}
@ -96,7 +94,7 @@ class VariableUpdateServiceTest extends TestCase
/**
* Test that an empty (null) value passed in the option key is handled
* properly as an array.
* properly as an array. Also tests that a null description is handled.
*
* @see https://github.com/Pterodactyl/Panel/issues/841
*/
@ -106,10 +104,10 @@ class VariableUpdateServiceTest extends TestCase
->shouldReceive('update')->with($this->model->id, m::subset([
'user_viewable' => false,
'user_editable' => false,
'options' => null,
'description' => '',
]))->once()->andReturn(true);
$this->assertTrue($this->service->handle($this->model, ['options' => null]));
$this->assertTrue($this->service->handle($this->model, ['options' => null, 'description' => null]));
}
/**