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\Discount; | use App\Discount; | ||||
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; | ||||
use Tests\TestCaseDusk; | use Tests\TestCaseDusk; | ||||
use Illuminate\Foundation\Testing\DatabaseMigrations; | use Illuminate\Foundation\Testing\DatabaseMigrations; | ||||
class UserTest extends TestCaseDusk | class UserTest extends TestCaseDusk | ||||
{ | { | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function setUp(): void | public function setUp(): void | ||||
{ | { | ||||
parent::setUp(); | parent::setUp(); | ||||
self::useAdminUrl(); | self::useAdminUrl(); | ||||
$john = $this->getTestUser('john@kolab.org'); | $john = $this->getTestUser('john@kolab.org'); | ||||
$john->update(['status' => $john->status ^= User::STATUS_SUSPENDED]); | |||||
$john->setSettings([ | $john->setSettings([ | ||||
'phone' => '+48123123123', | 'phone' => '+48123123123', | ||||
'external_email' => 'john.doe.external@gmail.com', | 'external_email' => 'john.doe.external@gmail.com', | ||||
]); | ]); | ||||
$wallet = $john->wallets()->first(); | $wallet = $john->wallets()->first(); | ||||
$wallet->discount()->dissociate(); | $wallet->discount()->dissociate(); | ||||
$wallet->balance = 0; | $wallet->balance = 0; | ||||
$wallet->save(); | $wallet->save(); | ||||
} | } | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function tearDown(): void | public function tearDown(): void | ||||
{ | { | ||||
$john = $this->getTestUser('john@kolab.org'); | $john = $this->getTestUser('john@kolab.org'); | ||||
$john->update(['status' => $john->status ^= User::STATUS_SUSPENDED]); | |||||
$john->setSettings([ | $john->setSettings([ | ||||
'phone' => null, | 'phone' => null, | ||||
'external_email' => 'john.doe.external@gmail.com', | 'external_email' => 'john.doe.external@gmail.com', | ||||
]); | ]); | ||||
$wallet = $john->wallets()->first(); | $wallet = $john->wallets()->first(); | ||||
$wallet->discount()->dissociate(); | $wallet->discount()->dissociate(); | ||||
$wallet->balance = 0; | $wallet->balance = 0; | ||||
▲ Show 20 Lines • Show All 351 Lines • ▼ Show 20 Lines | public function testExternalEmail(): void | ||||
// $john->getSetting() may not work here as it uses internal cache | // $john->getSetting() may not work here as it uses internal cache | ||||
// read the value form database | // read the value form database | ||||
$current_ext_email = $john->settings()->where('key', 'external_email')->first()->value; | $current_ext_email = $john->settings()->where('key', 'external_email')->first()->value; | ||||
$this->assertSame('test@test.com', $current_ext_email); | $this->assertSame('test@test.com', $current_ext_email); | ||||
}); | }); | ||||
} | } | ||||
/** | /** | ||||
* Test suspending/unsuspending the user | |||||
*/ | |||||
public function testSuspendAndUnsuspend(): void | |||||
{ | |||||
$this->browse(function (Browser $browser) { | |||||
$john = $this->getTestUser('john@kolab.org'); | |||||
$browser->visit(new UserPage($john->id)) | |||||
->assertVisible('@user-info #button-suspend') | |||||
->assertMissing('@user-info #button-unsuspend') | |||||
->click('@user-info #button-suspend') | |||||
->assertToast(Toast::TYPE_SUCCESS, 'User suspended successfully.') | |||||
->assertSeeIn('@user-info #status span.text-warning', 'Suspended') | |||||
->assertMissing('@user-info #button-suspend') | |||||
->click('@user-info #button-unsuspend') | |||||
->assertToast(Toast::TYPE_SUCCESS, 'User unsuspended successfully.') | |||||
->assertSeeIn('@user-info #status span.text-success', 'Active') | |||||
->assertVisible('@user-info #button-suspend') | |||||
->assertMissing('@user-info #button-unsuspend'); | |||||
}); | |||||
} | |||||
/** | |||||
* Test editing wallet discount | * Test editing wallet discount | ||||
* | * | ||||
* @depends testUserInfo2 | * @depends testUserInfo2 | ||||
*/ | */ | ||||
public function testWalletDiscount(): void | public function testWalletDiscount(): void | ||||
{ | { | ||||
$this->browse(function (Browser $browser) { | $this->browse(function (Browser $browser) { | ||||
$john = $this->getTestUser('john@kolab.org'); | $john = $this->getTestUser('john@kolab.org'); | ||||
▲ Show 20 Lines • Show All 51 Lines • Show Last 20 Lines |