74 lines
3.2 KiB
PHP
74 lines
3.2 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace Tests\Browser;
|
||
|
|
|
||
|
|
use Laravel\Dusk\Browser;
|
||
|
|
use Tests\DuskTestCase;
|
||
|
|
use App\Models\Planner;
|
||
|
|
|
||
|
|
class RegistrationTest extends DuskTestCase
|
||
|
|
{
|
||
|
|
public function testUserRegistration(): void
|
||
|
|
{
|
||
|
|
// Generate unique test data with timestamp to avoid conflicts
|
||
|
|
$timestamp = now()->format('YmdHis');
|
||
|
|
$testData = [
|
||
|
|
'name' => "Test User {$timestamp}",
|
||
|
|
'email' => "test.{$timestamp}@example.com",
|
||
|
|
'password' => 'SecurePassword123!',
|
||
|
|
];
|
||
|
|
|
||
|
|
$this->browse(function (Browser $browser) use ($testData) {
|
||
|
|
$browser->visit('http://dishplanner_app:8000/register')
|
||
|
|
->waitFor('input[id="name"]', 5)
|
||
|
|
->type('input[id="name"]', $testData['name'])
|
||
|
|
->type('input[id="email"]', $testData['email'])
|
||
|
|
->type('input[id="password"]', $testData['password'])
|
||
|
|
->type('input[id="password_confirmation"]', $testData['password'])
|
||
|
|
->screenshot('filled-form')
|
||
|
|
->click('button[type="submit"]')
|
||
|
|
->pause(3000) // Give more time for processing
|
||
|
|
->screenshot('after-submit')
|
||
|
|
->assertSee("Welcome {$testData['name']}!") // Verify successful registration and login
|
||
|
|
->assertPathIs('/dashboard'); // Should be on dashboard
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
public function testRegistrationWithExistingEmail(): void
|
||
|
|
{
|
||
|
|
$this->browse(function (Browser $browser) {
|
||
|
|
$browser->driver->manage()->deleteAllCookies();
|
||
|
|
$browser->visit('http://dishplanner_app:8000/register')
|
||
|
|
->waitFor('input[id="name"]', 5)
|
||
|
|
->type('input[id="name"]', 'Another User')
|
||
|
|
->type('input[id="email"]', 'test.20251228124357@example.com') // Use existing test email
|
||
|
|
->type('input[id="password"]', 'SecurePassword123!')
|
||
|
|
->type('input[id="password_confirmation"]', 'SecurePassword123!')
|
||
|
|
->click('button[type="submit"]')
|
||
|
|
->pause(2000)
|
||
|
|
->assertPathIs('/register')
|
||
|
|
->assertSee('The email has already been taken')
|
||
|
|
->assertGuest();
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
public function testRegistrationWithMismatchedPasswords(): void
|
||
|
|
{
|
||
|
|
$this->browse(function (Browser $browser) {
|
||
|
|
$browser->driver->manage()->deleteAllCookies();
|
||
|
|
$browser->visit('http://dishplanner_app:8000/register')
|
||
|
|
->waitFor('input[id="name"]', 5)
|
||
|
|
->type('input[id="name"]', 'Test User')
|
||
|
|
->type('input[id="email"]', 'testmismatch@example.com')
|
||
|
|
->type('input[id="password"]', 'SecurePassword123!')
|
||
|
|
->type('input[id="password_confirmation"]', 'DifferentPassword123!')
|
||
|
|
->click('button[type="submit"]')
|
||
|
|
->pause(2000)
|
||
|
|
->screenshot('password-mismatch-error')
|
||
|
|
->assertPathIs('/register')
|
||
|
|
->assertSee('password') // Look for any password-related error
|
||
|
|
->assertGuest();
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|