diff --git a/src/app/Entitlement.php b/src/app/Entitlement.php --- a/src/app/Entitlement.php +++ b/src/app/Entitlement.php @@ -94,13 +94,14 @@ } /** - * Principally entitleable objects such as 'Domain' or 'User'. + * Principally entitleable object such as Domain, User, Group. + * Note that it may be trashed (soft-deleted). * * @return mixed */ public function entitleable() { - return $this->morphTo(); + return $this->morphTo()->withTrashed(); // @phpstan-ignore-line } /** diff --git a/src/tests/Feature/EntitlementTest.php b/src/tests/Feature/EntitlementTest.php --- a/src/tests/Feature/EntitlementTest.php +++ b/src/tests/Feature/EntitlementTest.php @@ -8,6 +8,7 @@ use App\Sku; use App\User; use Carbon\Carbon; +use Illuminate\Support\Facades\Queue; use Tests\TestCase; class EntitlementTest extends TestCase @@ -131,10 +132,12 @@ } /** - * Test Entitlement::entitlementTitle() + * Test Entitlement::entitleableTitle() */ - public function testEntitlementTitle(): void + public function testEntitleableTitle(): void { + Queue::fake(); + $packageDomain = Package::withEnvTenantContext()->where('title', 'domain-hosting')->first(); $packageKolab = Package::withEnvTenantContext()->where('title', 'kolab')->first(); $user = $this->getTestUser('entitled-user@custom-domain.com'); @@ -171,5 +174,13 @@ ->where('sku_id', $sku_domain->id)->first(); $this->assertSame($domain->namespace, $entitlement->entitleableTitle()); + + // Make sure it still works if the entitleable is deleted + $domain->delete(); + + $entitlement->refresh(); + + $this->assertSame($domain->namespace, $entitlement->entitleableTitle()); + $this->assertNotNull($entitlement->entitleable); } }