mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -08:00
Implement test
This commit is contained in:
parent
82df7a66ec
commit
e5fb888d67
|
@ -68,14 +68,21 @@ class ReportTemplate extends Model
|
|||
return null;
|
||||
}
|
||||
|
||||
$value = $this->options[$property];
|
||||
|
||||
if (is_array($value)) {
|
||||
$value = $value[0];
|
||||
}
|
||||
|
||||
// If a model is provided then we should ensure we only return
|
||||
// the value if the model still exists.
|
||||
if ($model) {
|
||||
$foundModel = $model::find($this->options[$property]);
|
||||
$foundModel = $model::find($value);
|
||||
|
||||
return $foundModel ? $foundModel->id : null;
|
||||
}
|
||||
return $this->options[$property] ?? null;
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function selectValues(string $property, string $model = null): iterable
|
||||
|
|
|
@ -173,22 +173,24 @@ class ReportTemplateTest extends TestCase
|
|||
$this->assertContains($department->id, $templateWithModelId->selectValues('by_dept_id', Department::class));
|
||||
}
|
||||
|
||||
public function testGracefullyHandlesMultiSelectBecomingSingleSelect()
|
||||
public function testGracefullyHandlesMultiSelectBecomingSingleSelectBySelectingTheFirstValue()
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
|
||||
[$departmentA, $departmentB] = Department::factory()->count(2)->create();
|
||||
|
||||
// Given a report template saved with a property that is an array of values
|
||||
// Given report templates saved with a property that is an array of values
|
||||
$templateWithValuesInArray = ReportTemplate::factory()->create([
|
||||
'options' => ['array_of_values' => [1, 'a string']],
|
||||
'options' => ['array_of_values' => [3, 'a string']],
|
||||
]);
|
||||
|
||||
$templateWithModelIdsInArray = ReportTemplate::factory()->create([
|
||||
'options' => ['model_ids' => [$departmentA->id, $departmentB->id]],
|
||||
'options' => ['array_of_model_ids' => [$departmentA->id, $departmentB->id]],
|
||||
]);
|
||||
|
||||
// @todo: Determine behavior...shoudl we return the first value?
|
||||
$this->assertEquals(3, $templateWithValuesInArray->selectValue('array_of_values'));
|
||||
$this->assertEquals(
|
||||
$departmentA->id,
|
||||
$templateWithModelIdsInArray->selectValue('array_of_model_ids', Department::class)
|
||||
);
|
||||
}
|
||||
|
||||
public function testOldValuesStillWorkAfterTheseChanges()
|
||||
|
|
Loading…
Reference in a new issue