Fix exception when empty default value is passed for an egg variable, closes #934

This commit is contained in:
Dane Everitt 2018-02-11 16:47:50 -06:00
parent bf537922a3
commit 3ecab82358
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
3 changed files with 19 additions and 20 deletions

View file

@ -46,29 +46,30 @@ class VariableUpdateServiceTest extends TestCase
public function testVariableIsUpdatedWhenNoEnvironmentVariableIsPassed()
{
$this->repository->shouldReceive('withoutFreshModel')->withNoArgs()->once()->andReturnSelf()
->shouldReceive('update')->with($this->model->id, [
->shouldReceive('update')->with($this->model->id, m::subset([
'user_viewable' => false,
'user_editable' => false,
'test-data' => 'test-value',
])->once()->andReturn(true);
]))->once()->andReturn(true);
$this->assertTrue($this->service->handle($this->model, ['test-data' => 'test-value']));
}
/**
* Test that a service variable ID can be passed in place of the model.
* Test that a null value passed in for the default is converted to a string.
*
* @see https://github.com/Pterodactyl/Panel/issues/934
*/
public function testVariableIdCanBePassedInPlaceOfModel()
public function testNullDefaultValue()
{
$this->repository->shouldReceive('find')->with($this->model->id)->once()->andReturn($this->model);
$this->repository->shouldReceive('withoutFreshModel')->withNoArgs()->once()->andReturnSelf()
->shouldReceive('update')->with($this->model->id, [
'user_viewable' => false,
'user_editable' => false,
'test-data' => 'test-value',
'default_value' => '',
])->once()->andReturn(true);
$this->assertTrue($this->service->handle($this->model->id, ['test-data' => 'test-value']));
$this->assertTrue($this->service->handle($this->model, ['default_value' => null]));
}
/**
@ -84,11 +85,11 @@ class VariableUpdateServiceTest extends TestCase
])->once()->andReturn(0);
$this->repository->shouldReceive('withoutFreshModel')->withNoArgs()->once()->andReturnSelf()
->shouldReceive('update')->with($this->model->id, [
->shouldReceive('update')->with($this->model->id, m::subset([
'user_viewable' => false,
'user_editable' => false,
'env_variable' => 'TEST_VAR_123',
])->once()->andReturn(true);
]))->once()->andReturn(true);
$this->assertTrue($this->service->handle($this->model, ['env_variable' => 'TEST_VAR_123']));
}
@ -102,11 +103,11 @@ class VariableUpdateServiceTest extends TestCase
public function testNullOptionValueIsPassedAsArray()
{
$this->repository->shouldReceive('withoutFreshModel')->withNoArgs()->once()->andReturnSelf()
->shouldReceive('update')->with($this->model->id, [
->shouldReceive('update')->with($this->model->id, m::subset([
'user_viewable' => false,
'user_editable' => false,
'options' => null,
])->once()->andReturn(true);
]))->once()->andReturn(true);
$this->assertTrue($this->service->handle($this->model, ['options' => null]));
}
@ -124,11 +125,11 @@ class VariableUpdateServiceTest extends TestCase
])->once()->andReturn(0);
$this->repository->shouldReceive('withoutFreshModel')->withNoArgs()->once()->andReturnSelf()
->shouldReceive('update')->with($this->model->id, [
->shouldReceive('update')->with($this->model->id, m::subset([
'user_viewable' => false,
'user_editable' => false,
'env_variable' => 'TEST_VAR_123',
])->once()->andReturn(true);
]))->once()->andReturn(true);
$this->assertTrue($this->service->handle($this->model, ['user_viewable' => 123456, 'env_variable' => 'TEST_VAR_123']));
}