Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Browser/UsersTest.php
<?php | <?php | ||||
namespace Tests\Browser; | namespace Tests\Browser; | ||||
use App\Discount; | use App\Discount; | ||||
use App\Entitlement; | use App\Entitlement; | ||||
use App\Sku; | use App\Sku; | ||||
use App\User; | use App\User; | ||||
use App\UserAlias; | use App\UserAlias; | ||||
use Tests\Browser; | use Tests\Browser; | ||||
use Tests\Browser\Components\CountrySelect; | |||||
use Tests\Browser\Components\Dialog; | use Tests\Browser\Components\Dialog; | ||||
use Tests\Browser\Components\ListInput; | use Tests\Browser\Components\ListInput; | ||||
use Tests\Browser\Components\QuotaInput; | use Tests\Browser\Components\QuotaInput; | ||||
use Tests\Browser\Components\Toast; | use Tests\Browser\Components\Toast; | ||||
use Tests\Browser\Pages\Dashboard; | use Tests\Browser\Pages\Dashboard; | ||||
use Tests\Browser\Pages\Home; | use Tests\Browser\Pages\Home; | ||||
use Tests\Browser\Pages\UserInfo; | use Tests\Browser\Pages\UserInfo; | ||||
use Tests\Browser\Pages\UserList; | use Tests\Browser\Pages\UserList; | ||||
▲ Show 20 Lines • Show All 352 Lines • ▼ Show 20 Lines | class UsersTest extends TestCaseDusk | ||||
* Test user settings tab | * Test user settings tab | ||||
* | * | ||||
* @depends testInfo | * @depends testInfo | ||||
*/ | */ | ||||
public function testUserSettings(): void | public function testUserSettings(): void | ||||
{ | { | ||||
$john = $this->getTestUser('john@kolab.org'); | $john = $this->getTestUser('john@kolab.org'); | ||||
$john->setSetting('greylist_enabled', null); | $john->setSetting('greylist_enabled', null); | ||||
$john->setSetting('limit_geo', null); | |||||
$this->browse(function (Browser $browser) use ($john) { | $this->browse(function (Browser $browser) use ($john) { | ||||
$browser->visit('/user/' . $john->id) | $browser->visit('/user/' . $john->id) | ||||
->on(new UserInfo()) | ->on(new UserInfo()) | ||||
->assertElementsCount('@nav a', 2) | ->assertElementsCount('@nav a', 2) | ||||
->assertSeeIn('@nav #tab-general', 'General') | ->assertSeeIn('@nav #tab-general', 'General') | ||||
->assertSeeIn('@nav #tab-settings', 'Settings') | ->assertSeeIn('@nav #tab-settings', 'Settings') | ||||
->click('@nav #tab-settings') | ->click('@nav #tab-settings') | ||||
->with('#settings form', function (Browser $browser) { | ->with('#settings form', function (Browser $browser) { | ||||
$browser->assertSeeIn('div.row:nth-child(1) label', 'Greylisting') | $browser->assertSeeIn('div.row:nth-child(1) label', 'Greylisting') | ||||
->assertMissing('div.row:nth-child(2)') // geo-lockin setting is hidden | |||||
->click('div.row:nth-child(1) input[type=checkbox]:checked') | ->click('div.row:nth-child(1) input[type=checkbox]:checked') | ||||
->click('button[type=submit]') | ->click('button[type=submit]') | ||||
->assertToast(Toast::TYPE_SUCCESS, 'User settings updated successfully.'); | ->assertToast(Toast::TYPE_SUCCESS, 'User settings updated successfully.'); | ||||
}); | }); | ||||
}); | }); | ||||
$this->assertSame('false', $john->fresh()->getSetting('greylist_enabled')); | $this->assertSame('false', $john->getSetting('greylist_enabled')); | ||||
$this->addBetaEntitlement($john); | |||||
$this->browse(function (Browser $browser) use ($john) { | |||||
$browser->refresh() | |||||
->on(new UserInfo()) | |||||
->click('@nav #tab-settings') | |||||
->with('#settings form', function (Browser $browser) use ($john) { | |||||
$browser->assertSeeIn('div.row:nth-child(1) label', 'Greylisting') | |||||
->assertSeeIn('div.row:nth-child(2) label', 'Geo-lockin') | |||||
->with(new CountrySelect('#limit_geo'), function ($browser) { | |||||
$browser->assertCountries([]) | |||||
->setCountries(['PL', 'DE']) | |||||
->assertCountries(['PL', 'DE']); | |||||
}) | |||||
->click('button[type=submit]') | |||||
->assertToast(Toast::TYPE_SUCCESS, 'User settings updated successfully.'); | |||||
$this->assertSame('["PL","DE"]', $john->getSetting('limit_geo')); | |||||
$browser | |||||
->with(new CountrySelect('#limit_geo'), function ($browser) { | |||||
$browser->setCountries([]) | |||||
->assertCountries([]); | |||||
}) | |||||
->click('button[type=submit]') | |||||
->assertToast(Toast::TYPE_SUCCESS, 'User settings updated successfully.'); | |||||
$this->assertSame(null, $john->getSetting('limit_geo')); | |||||
}); | |||||
}); | |||||
} | } | ||||
/** | /** | ||||
* Test user adding page | * Test user adding page | ||||
* | * | ||||
* @depends testInfo | * @depends testInfo | ||||
*/ | */ | ||||
public function testNewUser(): void | public function testNewUser(): void | ||||
▲ Show 20 Lines • Show All 502 Lines • Show Last 20 Lines |