Skip to content

A free open source IT asset/license management system

Fixed tests because I’m a dumbass

snipe924b4b5c79ff
diff --git a/app/Http/Transformers/AcceptancesTransformer.php b/app/Http/Transformers/AcceptancesTransformer.php
index 56bb0ded09..b055612f4f 100644
--- a/app/Http/Transformers/AcceptancesTransformer.php
+++ b/app/Http/Transformers/AcceptancesTransformer.php
@@ -43,10 +43,10 @@ class AcceptancesTransformer
'id' => (int) $acceptance->id,
'created_at' => Helper::getFormattedDateObject($acceptance->created_at, 'datetime'),
'item' => $item ? [
- 'id' => (int) ($item instanceof LicenseSeat ? ($item->license?->id ?? 0) : $item->id),
+ 'id' => (int) ($item instanceof LicenseSeat ? $item->license?->id : $item->id),
'name' => e($item instanceof LicenseSeat
- ? ($item->license?->name ?? '')
- : ($item->display_name ?? $item->name ?? '')),
+ ? (string) $item->license?->name
+ : (string) ($item->display_name ?? $item->name)),
'type' => self::itemTypeKey($acceptance->checkoutable_type),
'deleted_at' => (method_exists($item, 'trashed') && $item->trashed())
? Helper::getFormattedDateObject($item->deleted_at, 'datetime')
diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon
index 8cb74eef43..2788ac8422 100644
--- a/phpstan-baseline.neon
+++ b/phpstan-baseline.neon
@@ -1446,6 +1446,12 @@ parameters:
count: 1
path: app/Http/Controllers/Api/SuppliersController.php
+ -
+ message: '#^Strict comparison using \!\=\= between Illuminate\\Database\\Eloquent\\Model and null will always evaluate to true\.$#'
+ identifier: notIdentical.alwaysTrue
+ count: 1
+ path: app/Http/Controllers/Api/UnacceptedAcceptancesController.php
+
-
message: '#^If condition is always true\.$#'
identifier: if.alwaysTrue
@@ -2376,12 +2382,6 @@ parameters:
count: 1
path: app/Http/Controllers/ReportsController.php
- -
- message: '#^Call to an undefined method Illuminate\\Database\\Eloquent\\Model\:\:checkouts\(\)\.$#'
- identifier: method.notFound
- count: 1
- path: app/Http/Controllers/ReportsController.php
-
-
message: '#^If condition is always true\.$#'
identifier: if.alwaysTrue
@@ -2412,12 +2412,6 @@ parameters:
count: 1
path: app/Http/Controllers/ReportsController.php
- -
- message: '#^Unknown parameter \$firstTimeSending in call to App\\Mail\\CheckoutComponentMail constructor\.$#'
- identifier: argument.unknown
- count: 1
- path: app/Http/Controllers/ReportsController.php
-
-
message: '#^Access to an undefined property App\\Models\\Setting\:\:\$label2_template_name\.$#'
identifier: property.notFound
@@ -2604,6 +2598,42 @@ parameters:
count: 1
path: app/Http/Requests/SettingsLdapRequest.php
+ -
+ message: '#^Access to an undefined property Illuminate\\Database\\Eloquent\\Model\:\:\$deleted_at\.$#'
+ identifier: property.notFound
+ count: 1
+ path: app/Http/Transformers/AcceptancesTransformer.php
+
+ -
+ message: '#^Access to an undefined property Illuminate\\Database\\Eloquent\\Model\:\:\$id\.$#'
+ identifier: property.notFound
+ count: 1
+ path: app/Http/Transformers/AcceptancesTransformer.php
+
+ -
+ message: '#^Access to an undefined property Illuminate\\Database\\Eloquent\\Model\:\:\$name\.$#'
+ identifier: property.notFound
+ count: 1
+ path: app/Http/Transformers/AcceptancesTransformer.php
+
+ -
+ message: '#^Call to an undefined method Illuminate\\Database\\Eloquent\\Model\:\:checkouts\(\)\.$#'
+ identifier: method.notFound
+ count: 1
+ path: app/Http/Transformers/AcceptancesTransformer.php
+
+ -
+ message: '#^Negated boolean expression is always false\.$#'
+ identifier: booleanNot.alwaysFalse
+ count: 1
+ path: app/Http/Transformers/AcceptancesTransformer.php
+
+ -
+ message: '#^Ternary operator condition is always true\.$#'
+ identifier: ternary.alwaysTrue
+ count: 1
+ path: app/Http/Transformers/AcceptancesTransformer.php
+
-
message: '#^Access to an undefined property Illuminate\\Database\\Eloquent\\Model\:\:\$display_name\.$#'
identifier: property.notFound
@@ -3750,24 +3780,6 @@ parameters:
count: 4
path: app/Mail/SendUpcomingAuditMail.php
- -
- message: '#^Access to an undefined property App\\Mail\\UnacceptedAssetReminderMail\:\:\$acceptance\.$#'
- identifier: property.notFound
- count: 1
- path: app/Mail/UnacceptedAssetReminderMail.php
-
- -
- message: '#^Access to an undefined property App\\Mail\\UnacceptedAssetReminderMail\:\:\$count\.$#'
- identifier: property.notFound
- count: 2
- path: app/Mail/UnacceptedAssetReminderMail.php
-
- -
- message: '#^Access to an undefined property App\\Mail\\UnacceptedAssetReminderMail\:\:\$target\.$#'
- identifier: property.notFound
- count: 2
- path: app/Mail/UnacceptedAssetReminderMail.php
-
-
message: '#^Access to an undefined property App\\Models\\Accessory\:\:\$license\.$#'
identifier: property.notFound
diff --git a/resources/views/layouts/default.blade.php b/resources/views/layouts/default.blade.php
index cf8e006544..0ea08f7aa0 100644
--- a/resources/views/layouts/default.blade.php
+++ b/resources/views/layouts/default.blade.php
@@ -831,11 +831,6 @@
{{ trans('general.asset_maintenance_report') }}
</a>
</li>
- <li {!! (request()->is('reports/unaccepted_assets') ? ' class="active" aria-current="page"' : '') !!}>
- <a href="{{ url('reports/unaccepted_assets') }}">
- {{ trans('general.unaccepted_asset_report') }}
- </a>
- </li>
<li {!! (request()->is('reports/accessories') ? ' class="active" aria-current="page"' : '') !!}>
<a href="{{ url('reports/accessories') }}">
{{ trans('general.accessory_report') }}
diff --git a/resources/views/reports/index.blade.php b/resources/views/reports/index.blade.php
index bd00026e4b..bd5c1f0b94 100755
--- a/resources/views/reports/index.blade.php
+++ b/resources/views/reports/index.blade.php
@@ -60,12 +60,6 @@
</a>
</div>
- <div class="col-md-3 col-sm-6">
- <a href="{{ url('reports/unaccepted_assets') }}" class="btn btn-theme btn-block" style="margin-bottom: 10px; white-space: normal; text-align: left; padding-left: 15px;">
- <x-icon type="assets" class="fa-fw"/> {{ trans('general.unaccepted_asset_report') }}
- </a>
- </div>
-
<div class="col-md-3 col-sm-6">
<a href="{{ url('reports/accessories') }}" class="btn btn-theme btn-block" style="margin-bottom: 10px; white-space: normal; text-align: left; padding-left: 15px;">
<x-icon type="accessories" class="fa-fw"/> {{ trans('general.accessory_report') }}
diff --git a/tests/Feature/Notifications/Email/AcceptanceReminderTest.php b/tests/Feature/Notifications/Email/AcceptanceReminderTest.php
index c3fd839b22..33e954c269 100644
--- a/tests/Feature/Notifications/Email/AcceptanceReminderTest.php
+++ b/tests/Feature/Notifications/Email/AcceptanceReminderTest.php
@@ -2,25 +2,30 @@
namespace Tests\Feature\Notifications\Email;
-use App\Mail\CheckoutAccessoryMail;
-use App\Mail\CheckoutAssetMail;
-use App\Mail\CheckoutConsumableMail;
-use App\Mail\CheckoutLicenseMail;
use App\Models\Accessory;
-use App\Models\AccessoryCheckout;
-use App\Models\Actionlog;
use App\Models\Asset;
use App\Models\CheckoutAcceptance;
use App\Models\Consumable;
-use App\Models\License;
use App\Models\LicenseSeat;
use App\Models\User;
+use App\Notifications\UnacceptedAssetReminderNotification;
use Generator;
use Illuminate\Database\Eloquent\Model;
-use Illuminate\Support\Facades\Mail;
+use Illuminate\Support\Facades\Notification;
use PHPUnit\Framework\Attributes\DataProvider;
use Tests\TestCase;
+/**
+ * Reminder-send coverage for the single-row path on
+ * /unaccepted-acceptances/send-reminder.
+ *
+ * Post-v8.9 refactor: every reminder flow (console command,
+ * per-user button, bulk UI, API) dispatches
+ * UnacceptedAssetReminderNotification. These tests pin that the
+ * per-row controller endpoint still fires a notification for each
+ * checkoutable type and bails cleanly on the empty-email + missing-
+ * acceptance edge cases.
+ */
class AcceptanceReminderTest extends TestCase
{
private User $admin;
@@ -31,9 +36,11 @@ class AcceptanceReminderTest extends TestCase
{
parent::setUp();
- Mail::fake();
+ Notification::fake();
- $this->admin = User::factory()->canViewReports()->create();
+ // Any checkout grant passes canCheckoutAtLeastOneItemType,
+ // which is what the moved endpoint gates on now.
+ $this->admin = User::factory()->checkoutAccessories()->create();
$this->assignee = User::factory()->create();
}
@@ -43,22 +50,22 @@ class AcceptanceReminderTest extends TestCase
$userWithoutPermission = User::factory()->create();
$this->actingAs($userWithoutPermission)
- ->post(route('reports/unaccepted_assets_sent_reminder', [
+ ->post(route('unaccepted-acceptances.send-reminder', [
'acceptance_id' => $checkoutAcceptance->id,
]))
->assertForbidden();
- Mail::assertNotSent(CheckoutAssetMail::class);
+ Notification::assertNothingSent();
}
public function test_reminder_not_sent_if_acceptance_does_not_exist()
{
$this->actingAs($this->admin)
- ->post(route('reports/unaccepted_assets_sent_reminder', [
+ ->post(route('unaccepted-acceptances.send-reminder', [
'acceptance_id' => 999999,
]));
- Mail::assertNotSent(CheckoutAssetMail::class);
+ Notification::assertNothingSent();
}
public function test_reminder_not_sent_if_acceptance_already_accepted()
@@ -66,11 +73,11 @@ class AcceptanceReminderTest extends TestCase
$checkoutAcceptanceAlreadyAccepted = CheckoutAcceptance::factory()->accepted()->create();
$this->actingAs($this->admin)
- ->post(route('reports/unaccepted_assets_sent_reminder', [
+ ->post(route('unaccepted-acceptances.send-reminder', [
'acceptance_id' => $checkoutAcceptanceAlreadyAccepted->id,
]));
- Mail::assertNotSent(CheckoutAssetMail::class);
+ Notification::assertNothingSent();
}
public static function checkoutAcceptancesToUsersWithoutEmailAddresses(): Generator
@@ -100,141 +107,69 @@ class AcceptanceReminderTest extends TestCase
$checkoutAcceptance = $callback();
$this->actingAs($this->admin)
- ->post(route('reports/unaccepted_assets_sent_reminder', [
+ ->post(route('unaccepted-acceptances.send-reminder', [
'acceptance_id' => $checkoutAcceptance->id,
]))
- // check we didn't crash...
+ // check we didn't crash
->assertRedirect();
- Mail::assertNotSent(CheckoutAssetMail::class);
+ Notification::assertNothingSent();
}
public function test_reminder_is_sent_to_user_for_accessory()
{
$accessory = Accessory::factory()->requiringAcceptance()->create();
-
$acceptance = $this->createCheckoutAcceptance($accessory, $this->assignee);
- $this->createActionLogEntry($accessory, $this->admin, $this->assignee, $acceptance);
-
- // Match the pivot's created_at to the acceptance's so the reminder
- // controller's `WHERE created_at = ?` join lands. Accessory::checkouts()
- // reads the accessories_checkouts pivot (unlike Asset/Consumable/License
- // which read action_logs), and DATETIME second precision means two
- // separate `now()` calls straddle a boundary often enough under PHP
- // 8.2 CI load to flake the equality check.
- AccessoryCheckout::factory()
- ->for($this->admin, 'adminuser')
- ->for($accessory)
- ->for($this->assignee, 'assignedTo')
- ->create(['created_at' => $acceptance->created_at]);
-
$this->actingAs($this->admin)
- ->post(route('reports/unaccepted_assets_sent_reminder', [
+ ->post(route('unaccepted-acceptances.send-reminder', [
'acceptance_id' => $acceptance->id,
]))
- ->assertRedirect(route('reports/unaccepted_assets'));
-
- Mail::assertSent(CheckoutAccessoryMail::class, 1);
-
- Mail::assertSent(CheckoutAccessoryMail::class, function (CheckoutAccessoryMail $mail) {
- return $mail->hasTo($this->assignee);
- });
-
- Mail::assertSent(CheckoutAccessoryMail::class, function (CheckoutAccessoryMail $mail) {
- return $mail->hasSubject(trans('mail.unaccepted_asset_reminder'));
- });
+ ->assertRedirect(route('unaccepted-acceptances.index'));
- Mail::assertSent(CheckoutAccessoryMail::class, function (CheckoutAccessoryMail $mail) {
- return str_contains($mail->render(), trans('mail.recent_item_checked'));
- });
+ Notification::assertSentTo($this->assignee, UnacceptedAssetReminderNotification::class);
}
public function test_reminder_is_sent_to_user_for_asset()
{
$asset = Asset::factory()->requiresAcceptance()->create();
-
$acceptance = $this->createCheckoutAcceptance($asset, $this->assignee);
- $this->createActionLogEntry($asset, $this->admin, $this->assignee, $acceptance);
-
$this->actingAs($this->admin)
- ->post(route('reports/unaccepted_assets_sent_reminder', [
+ ->post(route('unaccepted-acceptances.send-reminder', [
'acceptance_id' => $acceptance->id,
]))
- ->assertRedirect(route('reports/unaccepted_assets'));
-
- Mail::assertSent(CheckoutAssetMail::class, 1);
+ ->assertRedirect(route('unaccepted-acceptances.index'));
- Mail::assertSent(CheckoutAssetMail::class, function (CheckoutAssetMail $mail) {
- return $mail->hasTo($this->assignee);
- });
-
- Mail::assertSent(CheckoutAssetMail::class, function (CheckoutAssetMail $mail) {
- return $mail->hasSubject(trans('mail.unaccepted_asset_reminder'));
- });
-
- Mail::assertSent(CheckoutAssetMail::class, function (CheckoutAssetMail $mail) {
- return str_contains($mail->render(), trans('mail.recent_item_checked'));
- });
+ Notification::assertSentTo($this->assignee, UnacceptedAssetReminderNotification::class);
}
public function test_reminder_is_sent_to_user_for_consumable()
{
$consumable = Consumable::factory()->requiringAcceptance()->create();
-
$acceptance = $this->createCheckoutAcceptance($consumable, $this->assignee);
- $this->createActionLogEntry($consumable, $this->admin, $this->assignee, $acceptance);
-
$this->actingAs($this->admin)
- ->post(route('reports/unaccepted_assets_sent_reminder', [
+ ->post(route('unaccepted-acceptances.send-reminder', [
'acceptance_id' => $acceptance->id,
]))
- ->assertRedirect(route('reports/unaccepted_assets'));
-
- Mail::assertSent(CheckoutConsumableMail::class, 1);
-
- Mail::assertSent(CheckoutConsumableMail::class, function (CheckoutConsumableMail $mail) {
- return $mail->hasTo($this->assignee);
- });
+ ->assertRedirect(route('unaccepted-acceptances.index'));
- Mail::assertSent(CheckoutConsumableMail::class, function (CheckoutConsumableMail $mail) {
- return $mail->hasSubject(trans('mail.unaccepted_asset_reminder'));
- });
-
- Mail::assertSent(CheckoutConsumableMail::class, function (CheckoutConsumableMail $mail) {
- return str_contains($mail->render(), trans('mail.recent_item_checked'));
- });
+ Notification::assertSentTo($this->assignee, UnacceptedAssetReminderNotification::class);
}
public function test_reminder_is_sent_to_user_for_license_seat()
{
$licenseSeat = LicenseSeat::factory()->requiringAcceptance()->create();
-
$acceptance = $this->createCheckoutAcceptance($licenseSeat, $this->assignee);
- $this->createActionLogEntry($licenseSeat, $this->admin, $this->assignee, $acceptance);
-
$this->actingAs($this->admin)
- ->post(route('reports/unaccepted_assets_sent_reminder', [
+ ->post(route('unaccepted-acceptances.send-reminder', [
'acceptance_id' => $acceptance->id,
]))
- ->assertRedirect(route('reports/unaccepted_assets'));
+ ->assertRedirect(route('unaccepted-acceptances.index'));
- Mail::assertSent(CheckoutLicenseMail::class, 1);
-
- Mail::assertSent(CheckoutLicenseMail::class, function (CheckoutLicenseMail $mail) {
- return $mail->hasTo($this->assignee);
- });
-
- Mail::assertSent(CheckoutLicenseMail::class, function (CheckoutLicenseMail $mail) {
- return $mail->hasSubject(trans('mail.unaccepted_asset_reminder'));
- });
-
- Mail::assertSent(CheckoutLicenseMail::class, function (CheckoutLicenseMail $mail) {
- return str_contains($mail->render(), trans('mail.recent_item_checked'));
- });
+ Notification::assertSentTo($this->assignee, UnacceptedAssetReminderNotification::class);
}
private function createCheckoutAcceptance(Model $item, Model $assignee): CheckoutAcceptance
@@ -246,25 +181,4 @@ class AcceptanceReminderTest extends TestCase
->pending()
->create();
}
-
- private function createActionLogEntry(Model $item, Model $admin, Model $assignee, CheckoutAcceptance $acceptance): Actionlog
- {
- $itemId = $item->id;
- $itemType = get_class($item);
-
- if (get_class($item) === LicenseSeat::class) {
- $itemId = $item->license->id;
- $itemType = License::class;
- }
-
- return Actionlog::factory()
- ->for($admin, 'adminuser')
- ->for($assignee, 'target')
- ->create([
- 'action_type' => 'checkout',
- 'item_id' => $itemId,
- 'item_type' => $itemType,
- 'created_at' => $acceptance->created_at,
- ]);
- }
}