Skip to content

A free open source IT asset/license management system

Split test case

Marcus Moore8bc57f98a5a8
diff --git a/tests/Feature/Notifications/Email/EmailNotificationsToAdminAlertEmailUponCheckinTest.php b/tests/Feature/Notifications/Email/EmailNotificationsToAdminAlertEmailUponCheckinTest.php
new file mode 100644
index 0000000000..ec2481b59d
--- /dev/null
+++ b/tests/Feature/Notifications/Email/EmailNotificationsToAdminAlertEmailUponCheckinTest.php
@@ -0,0 +1,85 @@
+<?php
+
+namespace Tests\Feature\Notifications\Email;
+
+use App\Events\CheckoutableCheckedIn;
+use App\Mail\CheckinAssetMail;
+use App\Models\Asset;
+use App\Models\AssetModel;
+use App\Models\Category;
+use App\Models\User;
+use Illuminate\Support\Facades\Mail;
+use PHPUnit\Framework\Attributes\Group;
+use Tests\TestCase;
+
+#[Group('notifications')]
+class EmailNotificationsToAdminAlertEmailUponCheckinTest extends TestCase
+{
+ protected function setUp(): void
+ {
+ parent::setUp();
+
+ Mail::fake();
+ }
+
+ public function test_admin_alert_email_sends()
+ {
+ $this->settings->enableAdminCC('[email protected]');
+
+ $user = User::factory()->create();
+ $asset = Asset::factory()->assignedToUser($user)->create();
+
+ $asset->model->category->update(['checkin_email' => true]);
+
+ $this->fireCheckInEvent($asset, $user);
+
+ Mail::assertSent(CheckinAssetMail::class, function ($mail) use ($user) {
+ return $mail->hasTo($user->email) && $mail->hasCc('[email protected]');
+ });
+ }
+
+ public function test_admin_alert_email_still_sent_when_category_email_is_not_set_to_send_email_to_user()
+ {
+ $this->settings->enableAdminCC('[email protected]');
+
+ $category = Category::factory()->create([
+ 'checkin_email' => false,
+ 'eula_text' => null,
+ 'use_default_eula' => false,
+ ]);
+ $assetModel = AssetModel::factory()->create(['category_id' => $category->id]);
+ $asset = Asset::factory()->create(['model_id' => $assetModel->id]);
+
+ $this->fireCheckInEvent($asset, User::factory()->create());
+
+ Mail::assertSent(CheckinAssetMail::class, function ($mail) {
+ return $mail->hasTo('[email protected]');
+ });
+ }
+
+ public function test_admin_alert_email_still_sent_when_user_has_no_email_address()
+ {
+ $this->settings->enableAdminCC('[email protected]');
+
+ $user = User::factory()->create(['email' => null]);
+ $asset = Asset::factory()->assignedToUser($user)->create();
+
+ $asset->model->category->update(['checkin_email' => true]);
+
+ $this->fireCheckInEvent($asset, $user);
+
+ Mail::assertSent(CheckinAssetMail::class, function ($mail) {
+ return $mail->hasTo('[email protected]');
+ });
+ }
+
+ private function fireCheckInEvent($asset, $user): void
+ {
+ event(new CheckoutableCheckedIn(
+ $asset,
+ $user,
+ User::factory()->checkinAssets()->create(),
+ ''
+ ));
+ }
+}
diff --git a/tests/Feature/Notifications/Email/EmailNotificationsUponCheckinTest.php b/tests/Feature/Notifications/Email/EmailNotificationsToUserUponCheckinTest.php
similarity index 64%
rename from tests/Feature/Notifications/Email/EmailNotificationsUponCheckinTest.php
rename to tests/Feature/Notifications/Email/EmailNotificationsToUserUponCheckinTest.php
index 254e2e09ca..432ce88b4b 100644
--- a/tests/Feature/Notifications/Email/EmailNotificationsUponCheckinTest.php
+++ b/tests/Feature/Notifications/Email/EmailNotificationsToUserUponCheckinTest.php
@@ -4,8 +4,6 @@ namespace Tests\Feature\Notifications\Email;
use App\Mail\CheckinAssetMail;
use App\Models\Accessory;
-use App\Models\AssetModel;
-use App\Models\Category;
use App\Models\Consumable;
use App\Models\LicenseSeat;
use Illuminate\Support\Facades\Mail;
@@ -16,7 +14,7 @@ use App\Models\User;
use Tests\TestCase;
#[Group('notifications')]
-class EmailNotificationsUponCheckinTest extends TestCase
+class EmailNotificationsToUserUponCheckinTest extends TestCase
{
protected function setUp(): void
{
@@ -101,57 +99,6 @@ class EmailNotificationsUponCheckinTest extends TestCase
Mail::assertNothingSent();
}
- public function test_admin_alert_email_sends()
- {
- $this->settings->enableAdminCC('[email protected]');
-
- $user = User::factory()->create();
- $asset = Asset::factory()->assignedToUser($user)->create();
-
- $asset->model->category->update(['checkin_email' => true]);
-
- $this->fireCheckInEvent($asset, $user);
-
- Mail::assertSent(CheckinAssetMail::class, function ($mail) use ($user) {
- return $mail->hasTo($user->email) && $mail->hasCc('[email protected]');
- });
- }
-
- public function test_admin_alert_email_still_sent_when_category_email_is_not_set_to_send_email_to_user()
- {
- $this->settings->enableAdminCC('[email protected]');
-
- $category = Category::factory()->create([
- 'checkin_email' => false,
- 'eula_text' => null,
- 'use_default_eula' => false,
- ]);
- $assetModel = AssetModel::factory()->create(['category_id' => $category->id]);
- $asset = Asset::factory()->create(['model_id' => $assetModel->id]);
-
- $this->fireCheckInEvent($asset, User::factory()->create());
-
- Mail::assertSent(CheckinAssetMail::class, function ($mail) {
- return $mail->hasTo('[email protected]');
- });
- }
-
- public function test_admin_alert_email_still_sent_when_user_has_no_email_address()
- {
- $this->settings->enableAdminCC('[email protected]');
-
- $user = User::factory()->create(['email' => null]);
- $asset = Asset::factory()->assignedToUser($user)->create();
-
- $asset->model->category->update(['checkin_email' => true]);
-
- $this->fireCheckInEvent($asset, $user);
-
- Mail::assertSent(CheckinAssetMail::class, function ($mail) {
- return $mail->hasTo('[email protected]');
- });
- }
-
private function fireCheckInEvent($asset, $user): void
{
event(new CheckoutableCheckedIn(