diff --git a/app/Models/Asset.php b/app/Models/Asset.php index dd2f1c8e2..aff06b668 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -950,11 +950,12 @@ class Asset extends Depreciable { if (($this->model) && ($this->model->category)) { - if ($this->model->category->eula_text) { + if (($this->model->category->eula_text) && ($this->model->category->use_default_eula === 0)) { return Helper::parseEscapedMarkedown($this->model->category->eula_text); - } elseif ($this->model->category->use_default_eula == '1') { + } elseif ($this->model->category->use_default_eula === 1) { return Helper::parseEscapedMarkedown(Setting::getSettings()->default_eula_text); } else { + return false; } } diff --git a/tests/Support/Settings.php b/tests/Support/Settings.php index 2d499838c..e171c0ab9 100644 --- a/tests/Support/Settings.php +++ b/tests/Support/Settings.php @@ -121,6 +121,10 @@ class Settings 'ldap_basedn' => 'CN=Users,DC=ad,DC=example,Dc=com' ]); } + public function setEula($text = 'Default EULA text') + { + return $this->update(['default_eula_text' => $text]); + } /** * @param array $attributes Attributes to modify in the application's settings. diff --git a/tests/Unit/NotificationTest.php b/tests/Unit/NotificationTest.php index 8005759a1..86177c303 100644 --- a/tests/Unit/NotificationTest.php +++ b/tests/Unit/NotificationTest.php @@ -33,4 +33,28 @@ class NotificationTest extends TestCase $asset->checkOut($user, $admin->id); Notification::assertSentTo($user, CheckoutAssetNotification::class); } + public function testDefaultEulaIsSentWhenSetInCategory() + { + Notification::fake(); + + $this->settings->setEula('My Custom EULA Text'); + + $user = User::factory()->create(); + + $category = Category::factory()->create([ + 'use_default_eula' => 1, + 'eula_text' => 'EULA Text that should not be used', + ]); + + $model = AssetModel::factory()->for($category)->create(); + $asset = Asset::factory()->for($model, 'model')->create(); + + $asset->checkOut($user, User::factory()->superuser()->create()->id); + + Notification::assertSentTo($user, CheckoutAssetNotification::class, function ($notification) { + $content = $notification->toMail()->render(); + + return str_contains($content, 'My Custom EULA Text') && !str_contains($content, 'EULA Text that should not be used'); + }); + } }