mirror of
https://github.com/snipe/snipe-it.git
synced 2025-02-02 08:21:09 -08:00
Merge pull request #14581 from marcusmoore/bug/sc-25237
Fixed assigned to field in new label engine
This commit is contained in:
commit
da21424416
|
@ -18,8 +18,14 @@ class FieldOption {
|
||||||
// assignedTo directly on the asset is a special case where
|
// assignedTo directly on the asset is a special case where
|
||||||
// we want to avoid returning the property directly
|
// we want to avoid returning the property directly
|
||||||
// and instead return the entity's presented name.
|
// and instead return the entity's presented name.
|
||||||
if ($dataPath[0] === 'assignedTo'){
|
if ($dataPath[0] === 'assignedTo') {
|
||||||
return $asset->assignedTo ? $asset->assignedTo->present()->fullName() : null;
|
if ($asset->relationLoaded('assignedTo')) {
|
||||||
|
// If the "assignedTo" relationship was eager loaded then the way to get the
|
||||||
|
// relationship changes from $asset->assignedTo to $asset->assigned.
|
||||||
|
return $asset->assigned ? $asset->assigned->present()->fullName() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $asset->assignedTo ? $asset->assignedTo->present()->fullName() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $dataPath->reduce(function ($myValue, $path) {
|
return $dataPath->reduce(function ($myValue, $path) {
|
||||||
|
|
26
tests/Unit/Models/Labels/FieldOptionTest.php
Normal file
26
tests/Unit/Models/Labels/FieldOptionTest.php
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Unit\Models\Labels;
|
||||||
|
|
||||||
|
use App\Models\Asset;
|
||||||
|
use App\Models\Labels\FieldOption;
|
||||||
|
use App\Models\User;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class FieldOptionTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testItDisplaysAssignedToProperly()
|
||||||
|
{
|
||||||
|
// "assignedTo" is a "special" value that can be used in the new label engine
|
||||||
|
$fieldOption = FieldOption::fromString('Assigned To=assignedTo');
|
||||||
|
|
||||||
|
$asset = Asset::factory()
|
||||||
|
->assignedToUser(User::factory()->create(['first_name' => 'Luke', 'last_name' => 'Skywalker']))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$this->assertEquals('Luke Skywalker', $fieldOption->getValue($asset));
|
||||||
|
// If the "assignedTo" relationship was eager loaded then the way to get the
|
||||||
|
// relationship changes from $asset->assignedTo to $asset->assigned.
|
||||||
|
$this->assertEquals('Luke Skywalker', $fieldOption->getValue(Asset::with('assignedTo')->find($asset->id)));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue