Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Browser/Admin/UserTest.php
<?php | <?php | ||||
namespace Tests\Browser\Admin; | namespace Tests\Browser\Admin; | ||||
use App\Auth\SecondFactor; | use App\Auth\SecondFactor; | ||||
use App\Discount; | use App\Discount; | ||||
use App\Entitlement; | |||||
use App\Sku; | use App\Sku; | ||||
use App\User; | use App\User; | ||||
use Tests\Browser; | use Tests\Browser; | ||||
use Tests\Browser\Components\Dialog; | use Tests\Browser\Components\Dialog; | ||||
use Tests\Browser\Components\Toast; | use Tests\Browser\Components\Toast; | ||||
use Tests\Browser\Pages\Admin\User as UserPage; | use Tests\Browser\Pages\Admin\User as UserPage; | ||||
use Tests\Browser\Pages\Dashboard; | use Tests\Browser\Pages\Dashboard; | ||||
use Tests\Browser\Pages\Home; | use Tests\Browser\Pages\Home; | ||||
Show All 17 Lines | public function setUp(): void | ||||
]); | ]); | ||||
if ($john->isSuspended()) { | if ($john->isSuspended()) { | ||||
User::where('email', $john->email)->update(['status' => $john->status - User::STATUS_SUSPENDED]); | User::where('email', $john->email)->update(['status' => $john->status - User::STATUS_SUSPENDED]); | ||||
} | } | ||||
$wallet = $john->wallets()->first(); | $wallet = $john->wallets()->first(); | ||||
$wallet->discount()->dissociate(); | $wallet->discount()->dissociate(); | ||||
$wallet->save(); | $wallet->save(); | ||||
Entitlement::where('cost', '>=', 5000)->delete(); | |||||
$this->clearMeetEntitlements(); | $this->clearMeetEntitlements(); | ||||
} | } | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function tearDown(): void | public function tearDown(): void | ||||
{ | { | ||||
$john = $this->getTestUser('john@kolab.org'); | $john = $this->getTestUser('john@kolab.org'); | ||||
$john->setSettings([ | $john->setSettings([ | ||||
'phone' => null, | 'phone' => null, | ||||
'external_email' => 'john.doe.external@gmail.com', | 'external_email' => 'john.doe.external@gmail.com', | ||||
]); | ]); | ||||
if ($john->isSuspended()) { | if ($john->isSuspended()) { | ||||
User::where('email', $john->email)->update(['status' => $john->status - User::STATUS_SUSPENDED]); | User::where('email', $john->email)->update(['status' => $john->status - User::STATUS_SUSPENDED]); | ||||
} | } | ||||
$wallet = $john->wallets()->first(); | $wallet = $john->wallets()->first(); | ||||
$wallet->discount()->dissociate(); | $wallet->discount()->dissociate(); | ||||
$wallet->save(); | $wallet->save(); | ||||
Entitlement::where('cost', '>=', 5000)->delete(); | |||||
$this->clearMeetEntitlements(); | $this->clearMeetEntitlements(); | ||||
parent::tearDown(); | parent::tearDown(); | ||||
} | } | ||||
/** | /** | ||||
* Test user info page (unauthenticated) | * Test user info page (unauthenticated) | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 193 Lines • ▼ Show 20 Lines | public function testUserInfo2(): void | ||||
->assertVisible('tbody tr:nth-child(4) td:first-child svg.text-success') | ->assertVisible('tbody tr:nth-child(4) td:first-child svg.text-success') | ||||
->assertMissing('tfoot'); | ->assertMissing('tfoot'); | ||||
}); | }); | ||||
}); | }); | ||||
// Now we go to Ned's info page, he's a controller on John's wallet | // Now we go to Ned's info page, he's a controller on John's wallet | ||||
$this->browse(function (Browser $browser) { | $this->browse(function (Browser $browser) { | ||||
$ned = $this->getTestUser('ned@kolab.org'); | $ned = $this->getTestUser('ned@kolab.org'); | ||||
$beta_sku = Sku::where('title', 'beta')->first(); | |||||
$storage_sku = Sku::where('title', 'storage')->first(); | |||||
$wallet = $ned->wallet(); | |||||
// Add an extra storage and beta entitlement with different prices | |||||
Entitlement::create([ | |||||
'wallet_id' => $wallet->id, | |||||
'sku_id' => $beta_sku->id, | |||||
'cost' => 5010, | |||||
'entitleable_id' => $ned->id, | |||||
'entitleable_type' => User::class | |||||
]); | |||||
Entitlement::create([ | |||||
'wallet_id' => $wallet->id, | |||||
'sku_id' => $storage_sku->id, | |||||
'cost' => 5000, | |||||
'entitleable_id' => $ned->id, | |||||
'entitleable_type' => User::class | |||||
]); | |||||
$page = new UserPage($ned->id); | $page = new UserPage($ned->id); | ||||
$browser->click('@user-users tbody tr:nth-child(4) td:first-child a') | $browser->click('@user-users tbody tr:nth-child(4) td:first-child a') | ||||
->on($page); | ->on($page); | ||||
// Assert main info box content | // Assert main info box content | ||||
$browser->assertSeeIn('@user-info .card-title', $ned->email) | $browser->assertSeeIn('@user-info .card-title', $ned->email) | ||||
->with('@user-info form', function (Browser $browser) use ($ned) { | ->with('@user-info form', function (Browser $browser) use ($ned) { | ||||
Show All 12 Lines | public function testUserInfo2(): void | ||||
$browser->assertSeeIn('@nav #tab-aliases', 'Aliases (0)') | $browser->assertSeeIn('@nav #tab-aliases', 'Aliases (0)') | ||||
->click('@nav #tab-aliases') | ->click('@nav #tab-aliases') | ||||
->whenAvailable('@user-aliases', function (Browser $browser) { | ->whenAvailable('@user-aliases', function (Browser $browser) { | ||||
$browser->assertElementsCount('table tbody tr', 0) | $browser->assertElementsCount('table tbody tr', 0) | ||||
->assertSeeIn('table tfoot tr td', 'This user has no email aliases.'); | ->assertSeeIn('table tfoot tr td', 'This user has no email aliases.'); | ||||
}); | }); | ||||
// Assert Subscriptions tab, we expect John's discount here | // Assert Subscriptions tab, we expect John's discount here | ||||
$browser->assertSeeIn('@nav #tab-subscriptions', 'Subscriptions (5)') | $browser->assertSeeIn('@nav #tab-subscriptions', 'Subscriptions (6)') | ||||
->click('@nav #tab-subscriptions') | ->click('@nav #tab-subscriptions') | ||||
->with('@user-subscriptions', function (Browser $browser) { | ->with('@user-subscriptions', function (Browser $browser) { | ||||
$browser->assertElementsCount('table tbody tr', 5) | $browser->assertElementsCount('table tbody tr', 6) | ||||
->assertSeeIn('table tbody tr:nth-child(1) td:first-child', 'User Mailbox') | ->assertSeeIn('table tbody tr:nth-child(1) td:first-child', 'User Mailbox') | ||||
->assertSeeIn('table tbody tr:nth-child(1) td:last-child', '3,99 CHF/month¹') | ->assertSeeIn('table tbody tr:nth-child(1) td:last-child', '3,99 CHF/month¹') | ||||
->assertSeeIn('table tbody tr:nth-child(2) td:first-child', 'Storage Quota 2 GB') | ->assertSeeIn('table tbody tr:nth-child(2) td:first-child', 'Storage Quota 3 GB') | ||||
->assertSeeIn('table tbody tr:nth-child(2) td:last-child', '0,00 CHF/month¹') | ->assertSeeIn('table tbody tr:nth-child(2) td:last-child', '45,00 CHF/month¹') | ||||
->assertSeeIn('table tbody tr:nth-child(3) td:first-child', 'Groupware Features') | ->assertSeeIn('table tbody tr:nth-child(3) td:first-child', 'Groupware Features') | ||||
->assertSeeIn('table tbody tr:nth-child(3) td:last-child', '4,99 CHF/month¹') | ->assertSeeIn('table tbody tr:nth-child(3) td:last-child', '4,99 CHF/month¹') | ||||
->assertSeeIn('table tbody tr:nth-child(4) td:first-child', 'Activesync') | ->assertSeeIn('table tbody tr:nth-child(4) td:first-child', 'Activesync') | ||||
->assertSeeIn('table tbody tr:nth-child(4) td:last-child', '0,90 CHF/month¹') | ->assertSeeIn('table tbody tr:nth-child(4) td:last-child', '0,90 CHF/month¹') | ||||
->assertSeeIn('table tbody tr:nth-child(5) td:first-child', '2-Factor Authentication') | ->assertSeeIn('table tbody tr:nth-child(5) td:first-child', '2-Factor Authentication') | ||||
->assertSeeIn('table tbody tr:nth-child(5) td:last-child', '0,00 CHF/month¹') | ->assertSeeIn('table tbody tr:nth-child(5) td:last-child', '0,00 CHF/month¹') | ||||
->assertSeeIn('table tbody tr:nth-child(6) td:first-child', 'Private Beta (invitation only)') | |||||
->assertSeeIn('table tbody tr:nth-child(6) td:last-child', '45,09 CHF/month¹') | |||||
->assertMissing('table tfoot') | ->assertMissing('table tfoot') | ||||
->assertSeeIn('table + .hint', '¹ applied discount: 10% - Test voucher') | ->assertSeeIn('table + .hint', '¹ applied discount: 10% - Test voucher') | ||||
->assertSeeIn('#reset2fa', 'Reset 2-Factor Auth'); | ->assertSeeIn('#reset2fa', 'Reset 2-Factor Auth'); | ||||
}); | }); | ||||
// We don't expect John's domains here | // We don't expect John's domains here | ||||
$browser->assertSeeIn('@nav #tab-domains', 'Domains (0)') | $browser->assertSeeIn('@nav #tab-domains', 'Domains (0)') | ||||
->click('@nav #tab-domains') | ->click('@nav #tab-domains') | ||||
▲ Show 20 Lines • Show All 125 Lines • Show Last 20 Lines |