Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Browser/UsersTest.php
Show All 33 Lines | public function setUp(): void | ||||
$this->deleteTestUser('julia.roberts@kolab.org'); | $this->deleteTestUser('julia.roberts@kolab.org'); | ||||
$john = User::where('email', 'john@kolab.org')->first(); | $john = User::where('email', 'john@kolab.org')->first(); | ||||
$john->setSettings($this->profile); | $john->setSettings($this->profile); | ||||
UserAlias::where('user_id', $john->id) | UserAlias::where('user_id', $john->id) | ||||
->where('alias', 'john.test@kolab.org')->delete(); | ->where('alias', 'john.test@kolab.org')->delete(); | ||||
Sku::where('title', 'test')->delete(); | Entitlement::where('entitleable_id', $john->id)->whereIn('cost', [25, 100])->delete(); | ||||
$storage = Sku::where('title', 'storage')->first(); | |||||
Entitlement::where([ | |||||
['sku_id', $storage->id], | |||||
['entitleable_id', $john->id], | |||||
['cost', 25] | |||||
])->delete(); | |||||
} | } | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function tearDown(): void | public function tearDown(): void | ||||
{ | { | ||||
$this->deleteTestUser('julia.roberts@kolab.org'); | $this->deleteTestUser('julia.roberts@kolab.org'); | ||||
$john = User::where('email', 'john@kolab.org')->first(); | $john = User::where('email', 'john@kolab.org')->first(); | ||||
$john->setSettings($this->profile); | $john->setSettings($this->profile); | ||||
UserAlias::where('user_id', $john->id) | UserAlias::where('user_id', $john->id) | ||||
->where('alias', 'john.test@kolab.org')->delete(); | ->where('alias', 'john.test@kolab.org')->delete(); | ||||
Sku::where('title', 'test')->delete(); | Entitlement::where('entitleable_id', $john->id)->whereIn('cost', [25, 100])->delete(); | ||||
$storage = Sku::where('title', 'storage')->first(); | |||||
Entitlement::where([ | |||||
['sku_id', $storage->id], | |||||
['entitleable_id', $john->id], | |||||
['cost', 25] | |||||
])->delete(); | |||||
parent::tearDown(); | parent::tearDown(); | ||||
} | } | ||||
/** | /** | ||||
* Test user info page (unauthenticated) | * Test user info page (unauthenticated) | ||||
*/ | */ | ||||
public function testInfoUnauth(): void | public function testInfoUnauth(): void | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | class UsersTest extends TestCaseDusk | ||||
/** | /** | ||||
* Test user account editing page (not profile page) | * Test user account editing page (not profile page) | ||||
* | * | ||||
* @depends testList | * @depends testList | ||||
*/ | */ | ||||
public function testInfo(): void | public function testInfo(): void | ||||
{ | { | ||||
Sku::create([ | |||||
'title' => 'test', | |||||
'name' => 'Test SKU', | |||||
'description' => 'The SKU for testing', | |||||
'cost' => 666, | |||||
'units_free' => 0, | |||||
'period' => 'monthly', | |||||
'handler_class' => 'App\Handlers\Groupware', | |||||
'active' => true, | |||||
]); | |||||
$this->browse(function (Browser $browser) { | $this->browse(function (Browser $browser) { | ||||
$browser->on(new UserList()) | $browser->on(new UserList()) | ||||
->click('@table tr:nth-child(2) a') | ->click('@table tr:nth-child(2) a') | ||||
->on(new UserInfo()) | ->on(new UserInfo()) | ||||
->assertSeeIn('#user-info .card-title', 'User account') | ->assertSeeIn('#user-info .card-title', 'User account') | ||||
->with('@form', function (Browser $browser) { | ->with('@form', function (Browser $browser) { | ||||
// Assert form content | // Assert form content | ||||
$browser->assertSeeIn('div.row:nth-child(1) label', 'Status') | $browser->assertSeeIn('div.row:nth-child(1) label', 'Status') | ||||
▲ Show 20 Lines • Show All 87 Lines • ▼ Show 20 Lines | public function testInfo(): void | ||||
$alias = UserAlias::where('user_id', $john->id)->where('alias', 'john.test@kolab.org')->first(); | $alias = UserAlias::where('user_id', $john->id)->where('alias', 'john.test@kolab.org')->first(); | ||||
$this->assertTrue(!empty($alias)); | $this->assertTrue(!empty($alias)); | ||||
// Test subscriptions | // Test subscriptions | ||||
$browser->with('@form', function (Browser $browser) { | $browser->with('@form', function (Browser $browser) { | ||||
$browser->assertSeeIn('div.row:nth-child(8) label', 'Subscriptions') | $browser->assertSeeIn('div.row:nth-child(8) label', 'Subscriptions') | ||||
->assertVisible('@skus.row:nth-child(8)') | ->assertVisible('@skus.row:nth-child(8)') | ||||
->with('@skus', function ($browser) { | ->with('@skus', function ($browser) { | ||||
$browser->assertElementsCount('tbody tr', 4) | $browser->assertElementsCount('tbody tr', 5) | ||||
// groupware SKU | // Mailbox SKU | ||||
->assertSeeIn('tbody tr:nth-child(1) td.name', 'Groupware Features') | ->assertSeeIn('tbody tr:nth-child(1) td.name', 'User Mailbox') | ||||
->assertSeeIn('tbody tr:nth-child(1) td.price', '5,55 CHF/month') | ->assertSeeIn('tbody tr:nth-child(1) td.price', '4,44 CHF/month') | ||||
->assertChecked('tbody tr:nth-child(1) td.selection input') | ->assertChecked('tbody tr:nth-child(1) td.selection input') | ||||
->assertEnabled('tbody tr:nth-child(1) td.selection input') | ->assertDisabled('tbody tr:nth-child(1) td.selection input') | ||||
->assertTip( | ->assertTip( | ||||
'tbody tr:nth-child(1) td.buttons button', | 'tbody tr:nth-child(1) td.buttons button', | ||||
'Groupware functions like Calendar, Tasks, Notes, etc.' | 'Just a mailbox' | ||||
) | ) | ||||
// Mailbox SKU | // Storage SKU | ||||
->assertSeeIn('tbody tr:nth-child(2) td.name', 'User Mailbox') | ->assertSeeIn('tbody tr:nth-child(2) td.name', 'Storage Quota') | ||||
->assertSeeIn('tbody tr:nth-child(2) td.price', '4,44 CHF/month') | ->assertSeeIn('tr:nth-child(2) td.price', '0,00 CHF/month') | ||||
->assertChecked('tbody tr:nth-child(2) td.selection input') | ->assertChecked('tbody tr:nth-child(2) td.selection input') | ||||
->assertDisabled('tbody tr:nth-child(2) td.selection input') | ->assertDisabled('tbody tr:nth-child(2) td.selection input') | ||||
->assertTip( | ->assertTip( | ||||
'tbody tr:nth-child(2) td.buttons button', | 'tbody tr:nth-child(2) td.buttons button', | ||||
'Just a mailbox' | 'Some wiggle room' | ||||
) | ) | ||||
// Storage SKU | ->with(new QuotaInput('tbody tr:nth-child(2) .range-input'), function ($browser) { | ||||
->assertSeeIn('tbody tr:nth-child(3) td.name', 'Storage Quota') | $browser->assertQuotaValue(2)->setQuotaValue(3); | ||||
->assertSeeIn('tr:nth-child(3) td.price', '0,00 CHF/month') | }) | ||||
->assertSeeIn('tr:nth-child(2) td.price', '0,25 CHF/month') | |||||
// groupware SKU | |||||
->assertSeeIn('tbody tr:nth-child(3) td.name', 'Groupware Features') | |||||
->assertSeeIn('tbody tr:nth-child(3) td.price', '5,55 CHF/month') | |||||
->assertChecked('tbody tr:nth-child(3) td.selection input') | ->assertChecked('tbody tr:nth-child(3) td.selection input') | ||||
->assertDisabled('tbody tr:nth-child(3) td.selection input') | ->assertEnabled('tbody tr:nth-child(3) td.selection input') | ||||
->assertTip( | ->assertTip( | ||||
'tbody tr:nth-child(3) td.buttons button', | 'tbody tr:nth-child(3) td.buttons button', | ||||
'Some wiggle room' | 'Groupware functions like Calendar, Tasks, Notes, etc.' | ||||
) | ) | ||||
->with(new QuotaInput('tbody tr:nth-child(3) .range-input'), function ($browser) { | // 2FA SKU | ||||
$browser->assertQuotaValue(2)->setQuotaValue(3); | ->assertSeeIn('tbody tr:nth-child(4) td.name', '2-Factor Authentication') | ||||
}) | ->assertSeeIn('tbody tr:nth-child(4) td.price', '0,00 CHF/month') | ||||
->assertSeeIn('tr:nth-child(3) td.price', '0,25 CHF/month') | |||||
// Test SKU | |||||
->assertSeeIn('tbody tr:nth-child(4) td.name', 'Test SKU') | |||||
->assertSeeIn('tbody tr:nth-child(4) td.price', '6,66 CHF/month') | |||||
->assertNotChecked('tbody tr:nth-child(4) td.selection input') | ->assertNotChecked('tbody tr:nth-child(4) td.selection input') | ||||
->assertEnabled('tbody tr:nth-child(4) td.selection input') | ->assertEnabled('tbody tr:nth-child(4) td.selection input') | ||||
->assertTip( | ->assertTip( | ||||
'tbody tr:nth-child(4) td.buttons button', | 'tbody tr:nth-child(4) td.buttons button', | ||||
'The SKU for testing' | 'Two factor authentication for webmail and administration panel' | ||||
) | ) | ||||
->click('tbody tr:nth-child(4) td.selection input'); | // ActiveSync SKU | ||||
->assertSeeIn('tbody tr:nth-child(5) td.name', 'Activesync') | |||||
->assertSeeIn('tbody tr:nth-child(5) td.price', '1,00 CHF/month') | |||||
->assertNotChecked('tbody tr:nth-child(5) td.selection input') | |||||
->assertEnabled('tbody tr:nth-child(5) td.selection input') | |||||
->assertTip( | |||||
'tbody tr:nth-child(5) td.buttons button', | |||||
'Mobile synchronization' | |||||
) | |||||
->click('tbody tr:nth-child(5) td.selection input'); | |||||
}) | }) | ||||
->click('button[type=submit]'); | ->click('button[type=submit]'); | ||||
}) | }) | ||||
->with(new Toast(Toast::TYPE_SUCCESS), function (Browser $browser) { | ->with(new Toast(Toast::TYPE_SUCCESS), function (Browser $browser) { | ||||
$browser->assertToastTitle('') | $browser->assertToastTitle('') | ||||
->assertToastMessage('User data updated successfully') | ->assertToastMessage('User data updated successfully') | ||||
->closeToast(); | ->closeToast(); | ||||
}); | }); | ||||
$this->assertUserEntitlements($john, ['groupware', 'mailbox', 'storage', 'storage', 'storage', 'test']); | $expected = ['activesync', 'groupware', 'mailbox', 'storage', 'storage', 'storage']; | ||||
$this->assertUserEntitlements($john, $expected); | |||||
// Test subscriptions interaction | |||||
$browser->with('@form', function (Browser $browser) { | |||||
$browser->with('@skus', function ($browser) { | |||||
// Uncheck 'groupware', expect activesync unchecked | |||||
$browser->click('@sku-input-groupware') | |||||
->assertNotChecked('@sku-input-groupware') | |||||
->assertNotChecked('@sku-input-activesync') | |||||
->assertEnabled('@sku-input-activesync') | |||||
->assertNotReadonly('@sku-input-activesync') | |||||
// Check 'activesync', expect an alert | |||||
->click('@sku-input-activesync') | |||||
->assertDialogOpened('Activesync requires Groupware Features.') | |||||
->acceptDialog() | |||||
->assertNotChecked('@sku-input-activesync') | |||||
// Check '2FA', expect 'activesync' unchecked and readonly | |||||
->click('@sku-input-2fa') | |||||
->assertChecked('@sku-input-2fa') | |||||
->assertNotChecked('@sku-input-activesync') | |||||
->assertReadonly('@sku-input-activesync') | |||||
// Uncheck '2FA' | |||||
->click('@sku-input-2fa') | |||||
->assertNotChecked('@sku-input-2fa') | |||||
->assertNotReadonly('@sku-input-activesync'); | |||||
}); | |||||
}); | |||||
}); | }); | ||||
} | } | ||||
/** | /** | ||||
* Test user adding page | * Test user adding page | ||||
* | * | ||||
* @depends testList | * @depends testList | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 197 Lines • Show Last 20 Lines |