A free open source IT asset/license management system
Implement test
Marcus Mooree5fb888d677f
diff --git a/app/Models/ReportTemplate.php b/app/Models/ReportTemplate.phpindex 73909d0454..b1da5d8d18 100644--- a/app/Models/ReportTemplate.php+++ b/app/Models/ReportTemplate.php@@ -68,14 +68,21 @@ class ReportTemplate extends Modelreturn 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): iterablediff --git a/tests/Unit/ReportTemplateTest.php b/tests/Unit/ReportTemplateTest.phpindex 216e2d3fbb..ab4573f9d1 100644--- a/tests/Unit/ReportTemplateTest.php+++ b/tests/Unit/ReportTemplateTest.php@@ -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()