A free open source IT asset/license management system
Lots of tests
snipe07fa51aa4c58
diff --git a/tests/Feature/CheckoutAcceptances/Ui/AssetAcceptanceTest.php b/tests/Feature/CheckoutAcceptances/Ui/AssetAcceptanceTest.phpindex 9263471f4d..0e4c9eda7b 100644--- a/tests/Feature/CheckoutAcceptances/Ui/AssetAcceptanceTest.php+++ b/tests/Feature/CheckoutAcceptances/Ui/AssetAcceptanceTest.php@@ -6,6 +6,7 @@ use App\Events\CheckoutAccepted;use App\Models\Actionlog;use App\Models\Asset;use App\Models\CheckoutAcceptance;+use App\Models\Setting;use App\Models\User;use Illuminate\Support\Facades\Event;use Tests\TestCase;@@ -88,6 +89,48 @@ class AssetAcceptanceTest extends TestCaseEvent::assertDispatched(CheckoutAccepted::class);}+ public function test_user_can_accept_asset_with_required_signature()+ {+ if (! function_exists('imagecreatetruecolor')) {+ $this->markTestSkipped('GD extension is required for signature image generation.');+ }++ $settings = Setting::query()->firstOrFail();+ $settings->require_accept_signature = 1;+ $settings->save();+ Setting::$_cache = null;++ $checkoutAcceptance = CheckoutAcceptance::factory()->pending()->create();++ $canvas = imagecreatetruecolor(24, 12);+ $transparent = imagecolorallocatealpha($canvas, 0, 0, 0, 127);+ imagefill($canvas, 0, 0, $transparent);+ imagesavealpha($canvas, true);+ $ink = imagecolorallocate($canvas, 25, 25, 25);+ imageline($canvas, 2, 10, 21, 2, $ink);++ ob_start();+ imagepng($canvas);+ $signaturePng = (string) ob_get_clean();+ imagedestroy($canvas);++ $signatureOutput = 'data:image/png;base64,'.base64_encode($signaturePng);++ $this->actingAs($checkoutAcceptance->assignedTo)+ ->post(route('account.store-acceptance', $checkoutAcceptance), [+ 'asset_acceptance' => 'accepted',+ 'note' => 'signed in test',+ 'signature_output' => $signatureOutput,+ ])+ ->assertRedirectToRoute('account.accept')+ ->assertSessionHas('success');++ $checkoutAcceptance->refresh();++ $this->assertNotNull($checkoutAcceptance->signature_filename);+ $this->assertNotNull($checkoutAcceptance->stored_eula_file);+ }+public function test_user_can_decline_asset(){Event::fake([CheckoutAccepted::class]);@@ -193,6 +236,58 @@ class AssetAcceptanceTest extends TestCaseEvent::assertDispatched(CheckoutAccepted::class);}+ public function test_stale_sign_in_place_post_on_already_accepted_item_redirects_to_intended_destination()+ {+ $assignee = User::factory()->create();+ $admin = User::factory()->admin()->create();+ $asset = Asset::factory()->create();++ $checkoutAcceptance = CheckoutAcceptance::factory()+ ->accepted()+ ->for($assignee, 'assignedTo')+ ->for($asset, 'checkoutable')+ ->create();++ $this->actingAs($admin)+ ->withSession([+ 'sign_in_place' => true,+ 'redirect_option' => 'target',+ 'checkout_to_type' => 'user',+ ])+ ->post(route('account.store-acceptance', $checkoutAcceptance), [+ 'asset_acceptance' => 'accepted',+ ])+ ->assertRedirect(route('users.show', $assignee));+ }++ public function test_stale_sign_in_place_post_with_missing_assignee_does_not_throw_route_error()+ {+ $admin = User::factory()->admin()->create();+ $asset = Asset::factory()->create();++ $assignee = User::factory()->create();++ $checkoutAcceptance = CheckoutAcceptance::factory()+ ->accepted()+ ->for($assignee, 'assignedTo')+ ->for($asset, 'checkoutable')+ ->create();++ CheckoutAcceptance::whereKey($checkoutAcceptance->id)->update(['assigned_to_id' => null]);++ $this->actingAs($admin)+ ->withSession([+ 'sign_in_place' => true,+ 'redirect_option' => 'target',+ 'checkout_to_type' => 'user',+ ])+ ->post(route('account.store-acceptance', $checkoutAcceptance), [+ 'asset_acceptance' => 'accepted',+ ])+ ->assertRedirectToRoute('account.accept')+ ->assertSessionHas('error');+ }+public function test_sign_in_place_acceptance_page_uses_checkout_flow_breadcrumbs(){$assignee = User::factory()->create();@@ -218,10 +313,11 @@ class AssetAcceptanceTest extends TestCasetrans('general.assets'),$asset->display_name,trans('general.checkout'),- trans('general.sign_in_place'),+ sprintf('%s for %s', trans('general.sign_in_place'), $assignee->display_name),], false)->assertSee(route('hardware.index'), false)->assertSee(route('hardware.show', $asset), false)+ ->assertDontSee(route('users.show', $assignee), false)->assertDontSee(route('hardware.checkout.create', $asset), false);}}