Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Browser/SignupTest.php
<?php | <?php | ||||
namespace Tests\Browser; | namespace Tests\Browser; | ||||
use App\Discount; | use App\Discount; | ||||
use App\Domain; | use App\Domain; | ||||
use App\Plan; | use App\Plan; | ||||
use App\SignupCode; | use App\SignupCode; | ||||
use App\SignupInvitation; | use App\SignupInvitation; | ||||
use App\User; | use App\User; | ||||
use Tests\Browser; | use Tests\Browser; | ||||
use Tests\Browser\Components\Menu; | use Tests\Browser\Components\Menu; | ||||
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\Signup; | use Tests\Browser\Pages\Signup; | ||||
use Tests\Browser\Pages\Wallet; | |||||
use Tests\TestCaseDusk; | use Tests\TestCaseDusk; | ||||
use Illuminate\Foundation\Testing\DatabaseMigrations; | use Illuminate\Foundation\Testing\DatabaseMigrations; | ||||
class SignupTest extends TestCaseDusk | class SignupTest extends TestCaseDusk | ||||
{ | { | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function setUp(): void | public function setUp(): void | ||||
{ | { | ||||
parent::setUp(); | parent::setUp(); | ||||
$this->deleteTestUser('signuptestdusk@' . \config('app.domain')); | $this->deleteTestUser('signuptestdusk@' . \config('app.domain')); | ||||
$this->deleteTestUser('admin@user-domain-signup.com'); | $this->deleteTestUser('admin@user-domain-signup.com'); | ||||
$this->deleteTestDomain('user-domain-signup.com'); | $this->deleteTestDomain('user-domain-signup.com'); | ||||
Plan::where('mode', 'token')->update(['mode' => 'email']); | Plan::whereIn('mode', ['token', 'mandate'])->update(['mode' => 'email']); | ||||
} | } | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function tearDown(): void | public function tearDown(): void | ||||
{ | { | ||||
$this->deleteTestUser('signuptestdusk@' . \config('app.domain')); | $this->deleteTestUser('signuptestdusk@' . \config('app.domain')); | ||||
$this->deleteTestUser('admin@user-domain-signup.com'); | $this->deleteTestUser('admin@user-domain-signup.com'); | ||||
$this->deleteTestDomain('user-domain-signup.com'); | $this->deleteTestDomain('user-domain-signup.com'); | ||||
SignupInvitation::truncate(); | SignupInvitation::truncate(); | ||||
Plan::where('mode', 'token')->update(['mode' => 'email']); | Plan::whereIn('mode', ['token', 'mandate'])->update(['mode' => 'email']); | ||||
@unlink(storage_path('signup-tokens.txt')); | @unlink(storage_path('signup-tokens.txt')); | ||||
parent::tearDown(); | parent::tearDown(); | ||||
} | } | ||||
/** | /** | ||||
* Test signup code verification with a link | * Test signup code verification with a link | ||||
▲ Show 20 Lines • Show All 460 Lines • ▼ Show 20 Lines | public function testSignupGroup(): void | ||||
$browser->within(new Menu(), function ($browser) { | $browser->within(new Menu(), function ($browser) { | ||||
$browser->clickMenuItem('logout'); | $browser->clickMenuItem('logout'); | ||||
}); | }); | ||||
}); | }); | ||||
} | } | ||||
/** | /** | ||||
* Test signup with a mandate plan, also the wallet lock | |||||
*/ | |||||
public function testSignupMandate(): void | |||||
{ | |||||
// Test the individual plan | |||||
$plan = Plan::withEnvTenantContext()->where('title', 'individual')->first(); | |||||
$plan->mode = 'mandate'; | |||||
$plan->save(); | |||||
$this->browse(function (Browser $browser) { | |||||
$browser->visit(new Signup()) | |||||
->waitFor('@step0 .plan-individual button') | |||||
->click('@step0 .plan-individual button') | |||||
// Test Back button | |||||
->whenAvailable('@step3', function ($browser) { | |||||
$browser->click('button[type=button]'); | |||||
}) | |||||
->whenAvailable('@step0', function ($browser) { | |||||
$browser->click('.plan-individual button'); | |||||
}) | |||||
// Test submit | |||||
->whenAvailable('@step3', function ($browser) { | |||||
$domains = Domain::getPublicDomains(); | |||||
$domains_count = count($domains); | |||||
$browser->assertMissing('.card-title') | |||||
->assertElementsCount('select#signup_domain option', $domains_count, false) | |||||
->assertText('select#signup_domain option:nth-child(1)', $domains[0]) | |||||
->assertValue('select#signup_domain option:nth-child(1)', $domains[0]) | |||||
->type('#signup_login', 'signuptestdusk') | |||||
->type('#signup_password', '12345678') | |||||
->type('#signup_password_confirmation', '12345678') | |||||
->click('[type=submit]'); | |||||
}) | |||||
->waitUntilMissing('@step3') | |||||
->on(new Wallet()) | |||||
->assertSeeIn('#lock-alert', "The account is locked") | |||||
->within(new Menu(), function ($browser) { | |||||
$browser->clickMenuItem('logout'); | |||||
}); | |||||
}); | |||||
$user = User::where('email', 'signuptestdusk@' . \config('app.domain'))->first(); | |||||
$this->assertSame($plan->id, $user->getSetting('plan_id')); | |||||
// Login again and see that the account is still locked | |||||
$this->browse(function (Browser $browser) use ($user) { | |||||
$browser->on(new Home()) | |||||
->submitLogon($user->email, '12345678', false) | |||||
->waitForLocation('/wallet') | |||||
->on(new Wallet()) | |||||
->assertSeeIn('#lock-alert', "The account is locked") | |||||
->within(new Menu(), function ($browser) { | |||||
$browser->clickMenuItem('logout'); | |||||
}); | |||||
// TODO: Test automatic UI unlock after creating a valid auto-payment mandate | |||||
}); | |||||
} | |||||
/** | |||||
* Test signup with a token plan | * Test signup with a token plan | ||||
*/ | */ | ||||
public function testSignupToken(): void | public function testSignupToken(): void | ||||
{ | { | ||||
// Test the individual plan | // Test the individual plan | ||||
Plan::where('title', 'individual')->update(['mode' => 'token']); | Plan::where('title', 'individual')->update(['mode' => 'token']); | ||||
// Register some valid tokens | // Register some valid tokens | ||||
▲ Show 20 Lines • Show All 236 Lines • Show Last 20 Lines |