Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/EntitlementTest.php
<?php | <?php | ||||
namespace Tests\Feature; | namespace Tests\Feature; | ||||
use App\Domain; | use App\Domain; | ||||
use App\Entitlement; | use App\Entitlement; | ||||
use App\Package; | |||||
use App\Sku; | use App\Sku; | ||||
use App\User; | use App\User; | ||||
use Carbon\Carbon; | |||||
use Tests\TestCase; | use Tests\TestCase; | ||||
class EntitlementTest extends TestCase | class EntitlementTest extends TestCase | ||||
{ | { | ||||
public function setUp(): void | public function setUp(): void | ||||
{ | { | ||||
parent::setUp(); | parent::setUp(); | ||||
Show All 10 Lines | public function tearDown(): void | ||||
parent::tearDown(); | parent::tearDown(); | ||||
} | } | ||||
/** | /** | ||||
* Tests for User::AddEntitlement() | * Tests for User::AddEntitlement() | ||||
*/ | */ | ||||
public function testUserAddEntitlement(): void | public function testUserAddEntitlement(): void | ||||
{ | { | ||||
$sku_domain = Sku::firstOrCreate(['title' => 'domain']); | $package_domain = Package::where('title', 'domain-hosting')->first(); | ||||
$sku_mailbox = Sku::firstOrCreate(['title' => 'mailbox']); | $package_kolab = Package::where('title', 'kolab')->first(); | ||||
$sku_domain = Sku::where('title', 'domain-hosting')->first(); | |||||
$sku_mailbox = Sku::where('title', 'mailbox')->first(); | |||||
$owner = $this->getTestUser('entitlement-test@kolabnow.com'); | $owner = $this->getTestUser('entitlement-test@kolabnow.com'); | ||||
$user = $this->getTestUser('entitled-user@custom-domain.com'); | $user = $this->getTestUser('entitled-user@custom-domain.com'); | ||||
$domain = $this->getTestDomain( | $domain = $this->getTestDomain( | ||||
'custom-domain.com', | 'custom-domain.com', | ||||
[ | [ | ||||
'status' => Domain::STATUS_NEW, | 'status' => Domain::STATUS_NEW, | ||||
'type' => Domain::TYPE_EXTERNAL, | 'type' => Domain::TYPE_EXTERNAL, | ||||
] | ] | ||||
); | ); | ||||
$wallet = $owner->wallets()->first(); | $domain->assignPackage($package_domain, $owner); | ||||
$entitlement_own_mailbox = new Entitlement( | $owner->assignPackage($package_kolab); | ||||
[ | $owner->assignPackage($package_kolab, $user); | ||||
'owner_id' => $owner->id, | |||||
'entitleable_id' => $owner->id, | |||||
'entitleable_type' => User::class, | |||||
'wallet_id' => $wallet->id, | |||||
'sku_id' => $sku_mailbox->id, | |||||
'description' => "Owner Mailbox Entitlement Test" | |||||
] | |||||
); | |||||
$entitlement_domain = new Entitlement( | $wallet = $owner->wallets->first(); | ||||
[ | |||||
'owner_id' => $owner->id, | |||||
'entitleable_id' => $domain->id, | |||||
'entitleable_type' => Domain::class, | |||||
'wallet_id' => $wallet->id, | |||||
'sku_id' => $sku_domain->id, | |||||
'description' => "User Domain Entitlement Test" | |||||
] | |||||
); | |||||
$entitlement_mailbox = new Entitlement( | $this->assertCount(4, $owner->entitlements()->get()); | ||||
[ | $this->assertCount(1, $sku_domain->entitlements()->where('owner_id', $owner->id)->get()); | ||||
'owner_id' => $owner->id, | $this->assertCount(2, $sku_mailbox->entitlements()->where('owner_id', $owner->id)->get()); | ||||
'entitleable_id' => $user->id, | $this->assertCount(9, $wallet->entitlements); | ||||
'entitleable_type' => User::class, | |||||
'wallet_id' => $wallet->id, | $this->backdateEntitlements($owner->entitlements, Carbon::now()->subMonths(1)); | ||||
'sku_id' => $sku_mailbox->id, | |||||
'description' => "User Mailbox Entitlement Test" | $wallet->chargeEntitlements(); | ||||
] | |||||
); | |||||
$owner->addEntitlement($entitlement_own_mailbox); | $this->assertTrue($wallet->fresh()->balance < 0); | ||||
$owner->addEntitlement($entitlement_domain); | |||||
$owner->addEntitlement($entitlement_mailbox); | |||||
$this->assertTrue($owner->entitlements()->count() == 3); | |||||
$this->assertTrue($sku_domain->entitlements()->where('owner_id', $owner->id)->count() == 1); | |||||
$this->assertTrue($sku_mailbox->entitlements()->where('owner_id', $owner->id)->count() == 2); | |||||
$this->assertTrue($wallet->entitlements()->count() == 3); | |||||
$this->assertTrue($wallet->fresh()->balance < 0.00); | |||||
} | } | ||||
public function testAddExistingEntitlement(): void | public function testAddExistingEntitlement(): void | ||||
{ | { | ||||
$this->markTestIncomplete(); | $this->markTestIncomplete(); | ||||
} | } | ||||
public function testEntitlementFunctions(): void | public function testEntitlementFunctions(): void | ||||
Show All 30 Lines |