mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-24 21:24:13 -08:00
fixed assetcheckin test, created redirect option test
This commit is contained in:
parent
9f02be0823
commit
69c2cf2c4f
|
@ -1463,21 +1463,24 @@ class Helper
|
|||
|
||||
static public function getRedirectOption($request, $id, $table)
|
||||
{
|
||||
$redirect_option = session::get('redirect_option');
|
||||
$checkout_to_type = session::get('checkout_to_type');
|
||||
$redirect_option = Session::get('redirect_option');
|
||||
$checkout_to_type = Session::get('checkout_to_type');
|
||||
|
||||
//return to index
|
||||
if ($redirect_option == '0') {
|
||||
switch ($table) {
|
||||
case "Assets":
|
||||
return redirect()->route('hardware.index')->with('success', trans('admin/hardware/message.checkout.success'));
|
||||
}
|
||||
}
|
||||
//return to thing being assigned
|
||||
if ($redirect_option == '1') {
|
||||
switch ($table) {
|
||||
case "Assets":
|
||||
return redirect()->route('hardware.show', $id)->with('success', trans('admin/hardware/message.checkout.success'));
|
||||
}
|
||||
}
|
||||
//return to thing being assigned to
|
||||
if ($redirect_option == '2') {
|
||||
switch ($checkout_to_type) {
|
||||
case 'user':
|
||||
|
|
|
@ -51,14 +51,13 @@ class AssetCheckinTest extends TestCase
|
|||
|
||||
$this->actingAs(User::factory()->checkinAssets()->create())
|
||||
->post(
|
||||
route('hardware.checkin.store', ['assetId' => $asset->id, 'backto' => 'user']),
|
||||
route('hardware.checkin.store', ['assetId' => $asset->id]),
|
||||
[
|
||||
'name' => 'Changed Name',
|
||||
'status_id' => $status->id,
|
||||
'location_id' => $location->id,
|
||||
],
|
||||
)
|
||||
->assertRedirect(route('users.show', $user));
|
||||
);
|
||||
|
||||
$this->assertNull($asset->refresh()->assignedTo);
|
||||
$this->assertNull($asset->expected_checkin);
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
namespace Tests\Unit\Helpers;
|
||||
|
||||
use App\Helpers\Helper;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Tests\TestCase;
|
||||
|
||||
class HelperTest extends TestCase
|
||||
|
@ -25,4 +28,64 @@ class HelperTest extends TestCase
|
|||
$this->settings->set(['digit_separator' => '1.234,56']);
|
||||
$this->assertSame(12.34, Helper::ParseCurrency('12,34'));
|
||||
}
|
||||
public function testGetRedirectOptionMethod(){
|
||||
$test_data = [
|
||||
[
|
||||
'request' =>(object) ['assigned_user' => 22],
|
||||
'id' => 1,
|
||||
'checkout_to_type' => 'user',
|
||||
'redirect_option' => 2,
|
||||
'table' => 'Assets',
|
||||
'route' => route('users.show', 22),
|
||||
'message' => 'redirect option 2 for user assigned to failed.'
|
||||
],
|
||||
[
|
||||
'request' =>(object) ['assigned_location' => 10],
|
||||
'id' => 2,
|
||||
'checkout_to_type' => 'location',
|
||||
'redirect_option' => 2,
|
||||
'table' => 'Locations',
|
||||
'route' => route('locations.show', 10),
|
||||
'message' => 'redirect option 2 location assigned to failed.'
|
||||
],
|
||||
[
|
||||
'request' =>(object) ['assigned_asset' => 101],
|
||||
'id' => 3,
|
||||
'checkout_to_type' => 'asset',
|
||||
'redirect_option' => 2,
|
||||
'table' => 'Assets',
|
||||
'route' => route('hardware.show', 101),
|
||||
'message' => 'redirect option 2 back to asset assigned to failed.'
|
||||
],
|
||||
[
|
||||
'request' =>(object) ['assigned_asset' => null],
|
||||
'id' => 999,
|
||||
'checkout_to_type' => null,
|
||||
'redirect_option' => 1,
|
||||
'table' => 'Assets',
|
||||
'route' => route('hardware.show', 999),
|
||||
'message' => 'redirect option 1 back to asset failed.'
|
||||
],
|
||||
[
|
||||
'request' =>(object) ['assigned_asset' => null],
|
||||
'id' => null,
|
||||
'checkout_to_type' => null,
|
||||
'redirect_option' => 0,
|
||||
'table' => 'Assets',
|
||||
'route' => route('hardware.index'),
|
||||
'message' => 'redirect option 0 back to index failed.'
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($test_data as $data) {
|
||||
|
||||
Session::put('redirect_option', $data['redirect_option']);
|
||||
Session::put('checkout_to_type', $data['checkout_to_type']);
|
||||
|
||||
$redirect = Helper::getRedirectOption($data['request'],$data['id'], $data['table']);
|
||||
|
||||
$this->assertInstanceOf(RedirectResponse::class, $redirect);
|
||||
$this->assertEquals($data['route'], $redirect->getTargetUrl(), $data['message']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue