Skip to content

A free open source IT asset/license management system

Split test case

Marcus Mooreea3364ab6815
diff --git a/tests/Feature/Notifications/Email/EmailNotificationsToAdminAlertEmailUponCheckout.php b/tests/Feature/Notifications/Email/EmailNotificationsToAdminAlertEmailUponCheckout.php
new file mode 100644
index 0000000000..930a1388f0
--- /dev/null
+++ b/tests/Feature/Notifications/Email/EmailNotificationsToAdminAlertEmailUponCheckout.php
@@ -0,0 +1,89 @@
+<?php
+
+namespace Tests\Feature\Notifications\Email;
+
+use App\Events\CheckoutableCheckedOut;
+use App\Mail\CheckoutAssetMail;
+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 EmailNotificationsToAdminAlertEmailUponCheckout extends TestCase
+{
+ private Asset $asset;
+ private AssetModel $assetModel;
+ private Category $category;
+ private User $user;
+
+ protected function setUp(): void
+ {
+ parent::setUp();
+
+ Mail::fake();
+
+ $this->category = Category::factory()->create([
+ 'checkin_email' => false,
+ 'eula_text' => null,
+ 'require_acceptance' => false,
+ 'use_default_eula' => false,
+ ]);
+
+ $this->assetModel = AssetModel::factory()->for($this->category)->create();
+ $this->asset = Asset::factory()->for($this->assetModel, 'model')->create();
+
+ $this->user = User::factory()->create();
+ }
+
+ public function test_admin_alert_email_sends()
+ {
+ $this->settings->enableAdminCC('[email protected]');
+
+ $this->category->update(['checkin_email' => true]);
+
+ $this->fireCheckoutEvent();
+
+ Mail::assertSent(CheckoutAssetMail::class, function (CheckoutAssetMail $mail) {
+ return $mail->hasCc('[email protected]');
+ });
+ }
+
+ public function test_admin_alert_email_still_sent_when_category_is_not_set_to_send_email_to_user()
+ {
+ $this->settings->enableAdminCC('[email protected]');
+
+ $this->fireCheckoutEvent();
+
+ Mail::assertSent(CheckoutAssetMail::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]');
+
+ $this->category->update(['checkin_email' => true]);
+ $this->user->update(['email' => null]);
+
+ $this->fireCheckoutEvent();
+
+ Mail::assertSent(CheckoutAssetMail::class, function ($mail) {
+ return $mail->hasTo('[email protected]');
+ });
+ }
+
+ private function fireCheckoutEvent(): void
+ {
+ event(new CheckoutableCheckedOut(
+ $this->asset,
+ $this->user,
+ User::factory()->superuser()->create(),
+ '',
+ ));
+ }
+}
diff --git a/tests/Feature/Notifications/Email/EmailNotificationsUponCheckoutTest.php b/tests/Feature/Notifications/Email/EmailNotificationsToUserUponCheckoutTest.php
similarity index 68%
rename from tests/Feature/Notifications/Email/EmailNotificationsUponCheckoutTest.php
rename to tests/Feature/Notifications/Email/EmailNotificationsToUserUponCheckoutTest.php
index e5a1a66cb6..e5741da8ec 100644
--- a/tests/Feature/Notifications/Email/EmailNotificationsUponCheckoutTest.php
+++ b/tests/Feature/Notifications/Email/EmailNotificationsToUserUponCheckoutTest.php
@@ -13,7 +13,7 @@ use PHPUnit\Framework\Attributes\Group;
use Tests\TestCase;
#[Group('notifications')]
-class EmailNotificationsUponCheckoutTest extends TestCase
+class EmailNotificationsToUserUponCheckoutTest extends TestCase
{
private Asset $asset;
private AssetModel $assetModel;
@@ -87,44 +87,6 @@ class EmailNotificationsUponCheckoutTest extends TestCase
Mail::assertNothingSent();
}
- public function test_admin_alert_email_sends()
- {
- $this->settings->enableAdminCC('[email protected]');
-
- $this->category->update(['checkin_email' => true]);
-
- $this->fireCheckoutEvent();
-
- Mail::assertSent(CheckoutAssetMail::class, function (CheckoutAssetMail $mail) {
- return $mail->hasCc('[email protected]');
- });
- }
-
- public function test_admin_alert_email_still_sent_when_category_is_not_set_to_send_email_to_user()
- {
- $this->settings->enableAdminCC('[email protected]');
-
- $this->fireCheckoutEvent();
-
- Mail::assertSent(CheckoutAssetMail::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]');
-
- $this->category->update(['checkin_email' => true]);
- $this->user->update(['email' => null]);
-
- $this->fireCheckoutEvent();
-
- Mail::assertSent(CheckoutAssetMail::class, function ($mail) {
- return $mail->hasTo('[email protected]');
- });
- }
-
private function fireCheckoutEvent(): void
{
event(new CheckoutableCheckedOut(