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\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\Signup; | use Tests\Browser\Pages\Signup; | ||||
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']); | |||||
} | } | ||||
/** | /** | ||||
* {@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']); | |||||
@unlink(storage_path('signup-tokens.txt')); | |||||
parent::tearDown(); | parent::tearDown(); | ||||
} | } | ||||
/** | /** | ||||
* Test signup code verification with a link | * Test signup code verification with a link | ||||
*/ | */ | ||||
public function testSignupCodeByLink(): void | public function testSignupCodeByLink(): void | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | public function testSignupStep0(): void | ||||
$step->assertVisible('button') | $step->assertVisible('button') | ||||
->assertSeeIn('button', 'Individual Account') | ->assertSeeIn('button', 'Individual Account') | ||||
->assertVisible('.plan-description') | ->assertVisible('.plan-description') | ||||
->click('button'); | ->click('button'); | ||||
}); | }); | ||||
$browser->waitForLocation('/signup/individual') | $browser->waitForLocation('/signup/individual') | ||||
->assertVisible('@step1') | ->assertVisible('@step1') | ||||
->assertSeeIn('.card-title', 'Sign Up - Step 1/3') | |||||
->assertMissing('@step0') | ->assertMissing('@step0') | ||||
->assertMissing('@step2') | ->assertMissing('@step2') | ||||
->assertMissing('@step3') | ->assertMissing('@step3') | ||||
->assertFocused('@step1 #signup_first_name'); | ->assertFocused('@step1 #signup_first_name'); | ||||
// Click Back button | // Click Back button | ||||
$browser->click('@step1 [type=button]') | $browser->click('@step1 [type=button]') | ||||
->waitForLocation('/signup') | ->waitForLocation('/signup') | ||||
Show All 21 Lines | class SignupTest extends TestCaseDusk | ||||
public function testSignupStep1(): void | public function testSignupStep1(): void | ||||
{ | { | ||||
$this->browse(function (Browser $browser) { | $this->browse(function (Browser $browser) { | ||||
$browser->visit('/signup/individual') | $browser->visit('/signup/individual') | ||||
->onWithoutAssert(new Signup()); | ->onWithoutAssert(new Signup()); | ||||
// Here we expect two text inputs and Back and Continue buttons | // Here we expect two text inputs and Back and Continue buttons | ||||
$browser->with('@step1', function ($step) { | $browser->with('@step1', function ($step) { | ||||
$step->assertVisible('#signup_last_name') | $step->waitFor('#signup_last_name') | ||||
->assertSeeIn('.card-title', 'Sign Up - Step 1/3') | |||||
->assertVisible('#signup_first_name') | ->assertVisible('#signup_first_name') | ||||
->assertFocused('#signup_first_name') | ->assertFocused('#signup_first_name') | ||||
->assertVisible('#signup_email') | ->assertVisible('#signup_email') | ||||
->assertVisible('[type=button]') | ->assertVisible('[type=button]') | ||||
->assertVisible('[type=submit]'); | ->assertVisible('[type=submit]'); | ||||
}); | }); | ||||
// Submit empty form | // Submit empty form | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | class SignupTest extends TestCaseDusk | ||||
* Test 2nd Step of the signup process | * Test 2nd Step of the signup process | ||||
* | * | ||||
* @depends testSignupStep1 | * @depends testSignupStep1 | ||||
*/ | */ | ||||
public function testSignupStep2(): void | public function testSignupStep2(): void | ||||
{ | { | ||||
$this->browse(function (Browser $browser) { | $this->browse(function (Browser $browser) { | ||||
$browser->assertVisible('@step2') | $browser->assertVisible('@step2') | ||||
->assertSeeIn('@step2 .card-title', 'Sign Up - Step 2/3') | |||||
->assertMissing('@step0') | ->assertMissing('@step0') | ||||
->assertMissing('@step1') | ->assertMissing('@step1') | ||||
->assertMissing('@step3'); | ->assertMissing('@step3'); | ||||
// Here we expect one text input, Back and Continue buttons | // Here we expect one text input, Back and Continue buttons | ||||
$browser->with('@step2', function ($step) { | $browser->with('@step2', function ($step) { | ||||
$step->assertVisible('#signup_short_code') | $step->assertVisible('#signup_short_code') | ||||
->assertFocused('#signup_short_code') | ->assertFocused('#signup_short_code') | ||||
▲ Show 20 Lines • Show All 272 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 token plan | |||||
*/ | |||||
public function testSignupToken(): void | |||||
{ | |||||
// Test the individual plan | |||||
Plan::where('title', 'individual')->update(['mode' => 'token']); | |||||
// Register some valid tokens | |||||
$tokens = ['1234567890', 'abcdefghijk']; | |||||
file_put_contents(storage_path('signup-tokens.txt'), implode("\n", $tokens)); | |||||
$this->browse(function (Browser $browser) use ($tokens) { | |||||
$browser->visit(new Signup()) | |||||
->waitFor('@step0 .plan-individual button') | |||||
->click('@step0 .plan-individual button') | |||||
// Step 1 | |||||
->whenAvailable('@step1', function ($browser) use ($tokens) { | |||||
$browser->assertSeeIn('.card-title', 'Sign Up - Step 1/2') | |||||
->type('#signup_first_name', 'Test') | |||||
->type('#signup_last_name', 'User') | |||||
->assertMissing('#signup_email') | |||||
->type('#signup_token', '1234') | |||||
// invalid token | |||||
->click('[type=submit]') | |||||
->waitFor('#signup_token.is-invalid') | |||||
->assertVisible('#signup_token + .invalid-feedback') | |||||
->assertFocused('#signup_token') | |||||
->assertToast(Toast::TYPE_ERROR, 'Form validation error') | |||||
// valid token | |||||
->type('#signup_token', $tokens[0]) | |||||
->click('[type=submit]'); | |||||
}) | |||||
// Step 2 | |||||
->whenAvailable('@step3', function ($browser) { | |||||
$domains = Domain::getPublicDomains(); | |||||
$domains_count = count($domains); | |||||
$browser->assertSeeIn('.card-title', 'Sign Up - Step 2/2') | |||||
->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 Dashboard()) | |||||
->within(new Menu(), function ($browser) { | |||||
$browser->clickMenuItem('logout'); | |||||
}); | |||||
}); | |||||
$user = User::where('email', 'signuptestdusk@' . \config('app.domain'))->first(); | |||||
$this->assertSame($tokens[0], $user->getSetting('signup_token')); | |||||
$this->assertSame(null, $user->getSetting('external_email')); | |||||
// Test the group plan | |||||
Plan::where('title', 'group')->update(['mode' => 'token']); | |||||
$this->browse(function (Browser $browser) use ($tokens) { | |||||
$browser->visit(new Signup()) | |||||
->waitFor('@step0 .plan-group button') | |||||
->click('@step0 .plan-group button') | |||||
// Step 1 | |||||
->whenAvailable('@step1', function ($browser) use ($tokens) { | |||||
$browser->assertSeeIn('.card-title', 'Sign Up - Step 1/2') | |||||
->type('#signup_first_name', 'Test') | |||||
->type('#signup_last_name', 'User') | |||||
->assertMissing('#signup_email') | |||||
->type('#signup_token', '1234') | |||||
// invalid token | |||||
->click('[type=submit]') | |||||
->waitFor('#signup_token.is-invalid') | |||||
->assertVisible('#signup_token + .invalid-feedback') | |||||
->assertFocused('#signup_token') | |||||
->assertToast(Toast::TYPE_ERROR, 'Form validation error') | |||||
// valid token | |||||
->type('#signup_token', $tokens[1]) | |||||
->click('[type=submit]'); | |||||
}) | |||||
// Step 2 | |||||
->whenAvailable('@step3', function ($browser) { | |||||
$browser->assertSeeIn('.card-title', 'Sign Up - Step 2/2') | |||||
->type('input#signup_domain', 'user-domain-signup.com') | |||||
->type('#signup_login', 'admin') | |||||
->type('#signup_password', '12345678') | |||||
->type('#signup_password_confirmation', '12345678') | |||||
->click('[type=submit]'); | |||||
}) | |||||
->waitUntilMissing('@step3') | |||||
->on(new Dashboard()) | |||||
->within(new Menu(), function ($browser) { | |||||
$browser->clickMenuItem('logout'); | |||||
}); | |||||
}); | |||||
$user = User::where('email', 'admin@user-domain-signup.com')->first(); | |||||
$this->assertSame($tokens[1], $user->getSetting('signup_token')); | |||||
$this->assertSame(null, $user->getSetting('external_email')); | |||||
} | |||||
/** | |||||
* Test signup with voucher | * Test signup with voucher | ||||
*/ | */ | ||||
public function testSignupVoucherLink(): void | public function testSignupVoucherLink(): void | ||||
{ | { | ||||
$this->browse(function (Browser $browser) { | $this->browse(function (Browser $browser) { | ||||
$browser->visit('/signup/voucher/TEST') | $browser->visit('/signup/voucher/TEST') | ||||
->onWithoutAssert(new Signup()) | ->onWithoutAssert(new Signup()) | ||||
->waitUntilMissing('.app-loader') | ->waitUntilMissing('.app-loader') | ||||
▲ Show 20 Lines • Show All 133 Lines • Show Last 20 Lines |