tipo: modificación del cpanel y gitignore de la carpeta vendor

This commit is contained in:
2026-07-07 11:35:09 -06:00
parent a0c91dc567
commit 676ef0d506
8510 changed files with 1132803 additions and 4 deletions
@@ -0,0 +1,32 @@
<?php
use App\Models\User;
test('login screen can be rendered', function () {
$response = $this->get('/login');
$response->assertStatus(200);
});
test('users can authenticate using the login screen', function () {
$user = User::factory()->create();
$response = $this->post('/login', [
'email' => $user->email,
'password' => 'password',
]);
$this->assertAuthenticated();
$response->assertRedirect(route('dashboard', absolute: false));
});
test('users cannot authenticate with invalid password', function () {
$user = User::factory()->create();
$this->post('/login', [
'email' => $user->email,
'password' => 'wrong-password',
]);
$this->assertGuest();
});
@@ -0,0 +1,60 @@
<?php
use App\Models\User;
use Illuminate\Auth\Events\Verified;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\URL;
use Laravel\Fortify\Features;
test('email verification screen can be rendered', function () {
$user = User::factory()->withPersonalTeam()->create([
'email_verified_at' => null,
]);
$response = $this->actingAs($user)->get('/email/verify');
$response->assertStatus(200);
})->skip(function () {
return ! Features::enabled(Features::emailVerification());
}, 'Email verification not enabled.');
test('email can be verified', function () {
Event::fake(Verified::class);
$user = User::factory()->create([
'email_verified_at' => null,
]);
$verificationUrl = URL::temporarySignedRoute(
'verification.verify',
now()->addMinutes(60),
['id' => $user->id, 'hash' => sha1($user->email)]
);
$response = $this->actingAs($user)->get($verificationUrl);
Event::assertDispatched(Verified::class);
expect($user->fresh()->hasVerifiedEmail())->toBeTrue();
$response->assertRedirect(route('dashboard', absolute: false).'?verified=1');
})->skip(function () {
return ! Features::enabled(Features::emailVerification());
}, 'Email verification not enabled.');
test('email can not verified with invalid hash', function () {
$user = User::factory()->create([
'email_verified_at' => null,
]);
$verificationUrl = URL::temporarySignedRoute(
'verification.verify',
now()->addMinutes(60),
['id' => $user->id, 'hash' => sha1('wrong-email')]
);
$this->actingAs($user)->get($verificationUrl);
expect($user->fresh()->hasVerifiedEmail())->toBeFalse();
})->skip(function () {
return ! Features::enabled(Features::emailVerification());
}, 'Email verification not enabled.');
@@ -0,0 +1,7 @@
<?php
it('returns a successful response', function () {
$response = $this->get('/');
$response->assertStatus(200);
});
@@ -0,0 +1,5 @@
<?php
test('that true is true', function () {
expect(true)->toBeTrue();
});
@@ -0,0 +1,35 @@
<?php
use App\Models\User;
use Laravel\Jetstream\Features;
test('confirm password screen can be rendered', function () {
$user = Features::hasTeamFeatures()
? User::factory()->withPersonalTeam()->create()
: User::factory()->create();
$response = $this->actingAs($user)->get('/user/confirm-password');
$response->assertStatus(200);
});
test('password can be confirmed', function () {
$user = User::factory()->create();
$response = $this->actingAs($user)->post('/user/confirm-password', [
'password' => 'password',
]);
$response->assertRedirect();
$response->assertSessionHasNoErrors();
});
test('password is not confirmed with invalid password', function () {
$user = User::factory()->create();
$response = $this->actingAs($user)->post('/user/confirm-password', [
'password' => 'wrong-password',
]);
$response->assertSessionHasErrors();
});
@@ -0,0 +1,73 @@
<?php
use App\Models\User;
use Illuminate\Auth\Notifications\ResetPassword;
use Illuminate\Support\Facades\Notification;
use Laravel\Fortify\Features;
test('reset password link screen can be rendered', function () {
$response = $this->get('/forgot-password');
$response->assertStatus(200);
})->skip(function () {
return ! Features::enabled(Features::resetPasswords());
}, 'Password updates are not enabled.');
test('reset password link can be requested', function () {
Notification::fake();
$user = User::factory()->create();
$response = $this->post('/forgot-password', [
'email' => $user->email,
]);
Notification::assertSentTo($user, ResetPassword::class);
})->skip(function () {
return ! Features::enabled(Features::resetPasswords());
}, 'Password updates are not enabled.');
test('reset password screen can be rendered', function () {
Notification::fake();
$user = User::factory()->create();
$response = $this->post('/forgot-password', [
'email' => $user->email,
]);
Notification::assertSentTo($user, ResetPassword::class, function (object $notification) {
$response = $this->get('/reset-password/'.$notification->token);
$response->assertStatus(200);
return true;
});
})->skip(function () {
return ! Features::enabled(Features::resetPasswords());
}, 'Password updates are not enabled.');
test('password can be reset with valid token', function () {
Notification::fake();
$user = User::factory()->create();
$response = $this->post('/forgot-password', [
'email' => $user->email,
]);
Notification::assertSentTo($user, ResetPassword::class, function (object $notification) use ($user) {
$response = $this->post('/reset-password', [
'token' => $notification->token,
'email' => $user->email,
'password' => 'password',
'password_confirmation' => 'password',
]);
$response->assertSessionHasNoErrors();
return true;
});
})->skip(function () {
return ! Features::enabled(Features::resetPasswords());
}, 'Password updates are not enabled.');
+47
View File
@@ -0,0 +1,47 @@
<?php
/*
|--------------------------------------------------------------------------
| Test Case
|--------------------------------------------------------------------------
|
| The closure you provide to your test functions is always bound to a specific PHPUnit test
| case class. By default, that class is "PHPUnit\Framework\TestCase". Of course, you may
| need to change it using the "pest()" function to bind a different classes or traits.
|
*/
pest()->extend(Tests\TestCase::class)
->use(Illuminate\Foundation\Testing\RefreshDatabase::class)
->in('Feature');
/*
|--------------------------------------------------------------------------
| Expectations
|--------------------------------------------------------------------------
|
| When you're writing tests, you often need to check that values meet certain conditions. The
| "expect()" function gives you access to a set of "expectations" methods that you can use
| to assert different things. Of course, you may extend the Expectation API at any time.
|
*/
expect()->extend('toBeOne', function () {
return $this->toBe(1);
});
/*
|--------------------------------------------------------------------------
| Functions
|--------------------------------------------------------------------------
|
| While Pest is very powerful out-of-the-box, you may have some testing code specific to your
| project that you don't want to repeat in every file. Here you can also expose helpers as
| global functions to help you to reduce the number of lines of code in your test files.
|
*/
function something()
{
// ..
}
@@ -0,0 +1,35 @@
<?php
use Laravel\Fortify\Features;
use Laravel\Jetstream\Jetstream;
test('registration screen can be rendered', function () {
$response = $this->get('/register');
$response->assertStatus(200);
})->skip(function () {
return ! Features::enabled(Features::registration());
}, 'Registration support is not enabled.');
test('registration screen cannot be rendered if support is disabled', function () {
$response = $this->get('/register');
$response->assertStatus(404);
})->skip(function () {
return Features::enabled(Features::registration());
}, 'Registration support is enabled.');
test('new users can register', function () {
$response = $this->post('/register', [
'name' => 'Test User',
'email' => 'test@example.com',
'password' => 'password',
'password_confirmation' => 'password',
'terms' => Jetstream::hasTermsAndPrivacyPolicyFeature(),
]);
$this->assertAuthenticated();
$response->assertRedirect(route('dashboard', absolute: false));
})->skip(function () {
return ! Features::enabled(Features::registration());
}, 'Registration support is not enabled.');
@@ -0,0 +1,34 @@
<?php
use App\Models\User;
use Illuminate\Support\Str;
use Laravel\Jetstream\Features;
test('api token permissions can be updated', function () {
if (Features::hasTeamFeatures()) {
$this->actingAs($user = User::factory()->withPersonalTeam()->create());
} else {
$this->actingAs($user = User::factory()->create());
}
$token = $user->tokens()->create([
'name' => 'Test Token',
'token' => Str::random(40),
'abilities' => ['create', 'read'],
]);
$this->put('/user/api-tokens/'.$token->id, [
'name' => $token->name,
'permissions' => [
'delete',
'missing-permission',
],
]);
expect($user->fresh()->tokens->first())
->can('delete')->toBeTrue()
->can('read')->toBeFalse()
->can('missing-permission')->toBeFalse();
})->skip(function () {
return ! Features::hasApiFeatures();
}, 'API support is not enabled.');
@@ -0,0 +1,13 @@
<?php
use App\Models\User;
test('other browser sessions can be logged out', function () {
$this->actingAs(User::factory()->create());
$response = $this->delete('/user/other-browser-sessions', [
'password' => 'password',
]);
$response->assertSessionHasNoErrors();
});
@@ -0,0 +1,28 @@
<?php
use App\Models\User;
use Laravel\Jetstream\Features;
test('api tokens can be created', function () {
if (Features::hasTeamFeatures()) {
$this->actingAs($user = User::factory()->withPersonalTeam()->create());
} else {
$this->actingAs($user = User::factory()->create());
}
$this->post('/user/api-tokens', [
'name' => 'Test Token',
'permissions' => [
'read',
'update',
],
]);
expect($user->fresh()->tokens)->toHaveCount(1);
expect($user->fresh()->tokens->first())
->name->toEqual('Test Token')
->can('read')->toBeTrue()
->can('delete')->toBeFalse();
})->skip(function () {
return ! Features::hasApiFeatures();
}, 'API support is not enabled.');
@@ -0,0 +1,14 @@
<?php
use App\Models\User;
test('teams can be created', function () {
$this->actingAs($user = User::factory()->withPersonalTeam()->create());
$this->post('/teams', [
'name' => 'Test Team',
]);
expect($user->fresh()->ownedTeams)->toHaveCount(2);
expect($user->fresh()->ownedTeams()->latest('id')->first()->name)->toEqual('Test Team');
});
@@ -0,0 +1,28 @@
<?php
use App\Models\User;
use Laravel\Jetstream\Features;
test('user accounts can be deleted', function () {
$this->actingAs($user = User::factory()->create());
$this->delete('/user', [
'password' => 'password',
]);
expect($user->fresh())->toBeNull();
})->skip(function () {
return ! Features::hasAccountDeletionFeatures();
}, 'Account deletion is not enabled.');
test('correct password must be provided before account can be deleted', function () {
$this->actingAs($user = User::factory()->create());
$this->delete('/user', [
'password' => 'wrong-password',
]);
expect($user->fresh())->not->toBeNull();
})->skip(function () {
return ! Features::hasAccountDeletionFeatures();
}, 'Account deletion is not enabled.');
@@ -0,0 +1,25 @@
<?php
use App\Models\User;
use Illuminate\Support\Str;
use Laravel\Jetstream\Features;
test('api tokens can be deleted', function () {
if (Features::hasTeamFeatures()) {
$this->actingAs($user = User::factory()->withPersonalTeam()->create());
} else {
$this->actingAs($user = User::factory()->create());
}
$token = $user->tokens()->create([
'name' => 'Test Token',
'token' => Str::random(40),
'abilities' => ['create', 'read'],
]);
$this->delete('/user/api-tokens/'.$token->id);
expect($user->fresh()->tokens)->toHaveCount(0);
})->skip(function () {
return ! Features::hasApiFeatures();
}, 'API support is not enabled.');
@@ -0,0 +1,29 @@
<?php
use App\Models\Team;
use App\Models\User;
test('teams can be deleted', function () {
$this->actingAs($user = User::factory()->withPersonalTeam()->create());
$user->ownedTeams()->save($team = Team::factory()->make([
'personal_team' => false,
]));
$team->users()->attach(
$otherUser = User::factory()->create(), ['role' => 'test-role']
);
$this->delete('/teams/'.$team->id);
expect($team->fresh())->toBeNull();
expect($otherUser->fresh()->teams)->toHaveCount(0);
});
test('personal teams cant be deleted', function () {
$this->actingAs($user = User::factory()->withPersonalTeam()->create());
$this->delete('/teams/'.$user->currentTeam->id);
expect($user->currentTeam->fresh())->not->toBeNull();
});
@@ -0,0 +1,40 @@
<?php
use App\Models\User;
use Illuminate\Support\Facades\Mail;
use Laravel\Jetstream\Features;
use Laravel\Jetstream\Mail\TeamInvitation;
test('team members can be invited to team', function () {
Mail::fake();
$this->actingAs($user = User::factory()->withPersonalTeam()->create());
$this->post('/teams/'.$user->currentTeam->id.'/members', [
'email' => 'test@example.com',
'role' => 'admin',
]);
Mail::assertSent(TeamInvitation::class);
expect($user->currentTeam->fresh()->teamInvitations)->toHaveCount(1);
})->skip(function () {
return ! Features::sendsTeamInvitations();
}, 'Team invitations not enabled.');
test('team member invitations can be cancelled', function () {
Mail::fake();
$this->actingAs($user = User::factory()->withPersonalTeam()->create());
$invitation = $user->currentTeam->teamInvitations()->create([
'email' => 'test@example.com',
'role' => 'admin',
]);
$this->delete('/team-invitations/'.$invitation->id);
expect($user->currentTeam->fresh()->teamInvitations)->toHaveCount(0);
})->skip(function () {
return ! Features::sendsTeamInvitations();
}, 'Team invitations not enabled.');
@@ -0,0 +1,27 @@
<?php
use App\Models\User;
test('users can leave teams', function () {
$user = User::factory()->withPersonalTeam()->create();
$user->currentTeam->users()->attach(
$otherUser = User::factory()->create(), ['role' => 'admin']
);
$this->actingAs($otherUser);
$this->delete('/teams/'.$user->currentTeam->id.'/members/'.$otherUser->id);
expect($user->currentTeam->fresh()->users)->toHaveCount(0);
});
test('team owners cant leave their own team', function () {
$this->actingAs($user = User::factory()->withPersonalTeam()->create());
$response = $this->delete('/teams/'.$user->currentTeam->id.'/members/'.$user->id);
$response->assertSessionHasErrorsIn('removeTeamMember', ['team']);
expect($user->currentTeam->fresh())->not->toBeNull();
});
@@ -0,0 +1,16 @@
<?php
use App\Models\User;
test('profile information can be updated', function () {
$this->actingAs($user = User::factory()->create());
$this->put('/user/profile-information', [
'name' => 'Test Name',
'email' => 'test@example.com',
]);
expect($user->fresh())
->name->toEqual('Test Name')
->email->toEqual('test@example.com');
});
@@ -0,0 +1,29 @@
<?php
use App\Models\User;
test('team members can be removed from teams', function () {
$this->actingAs($user = User::factory()->withPersonalTeam()->create());
$user->currentTeam->users()->attach(
$otherUser = User::factory()->create(), ['role' => 'admin']
);
$this->delete('/teams/'.$user->currentTeam->id.'/members/'.$otherUser->id);
expect($user->currentTeam->fresh()->users)->toHaveCount(0);
});
test('only team owner can remove team members', function () {
$user = User::factory()->withPersonalTeam()->create();
$user->currentTeam->users()->attach(
$otherUser = User::factory()->create(), ['role' => 'admin']
);
$this->actingAs($otherUser);
$response = $this->delete('/teams/'.$user->currentTeam->id.'/members/'.$user->id);
$response->assertStatus(403);
});
@@ -0,0 +1,51 @@
<?php
use App\Models\User;
use Laravel\Fortify\Features;
test('two factor authentication can be enabled', function () {
$this->actingAs($user = User::factory()->create());
$this->withSession(['auth.password_confirmed_at' => time()]);
$this->post('/user/two-factor-authentication');
expect($user->fresh()->two_factor_secret)->not->toBeNull();
expect($user->fresh()->recoveryCodes())->toHaveCount(8);
})->skip(function () {
return ! Features::canManageTwoFactorAuthentication();
}, 'Two factor authentication is not enabled.');
test('recovery codes can be regenerated', function () {
$this->actingAs($user = User::factory()->create());
$this->withSession(['auth.password_confirmed_at' => time()]);
$this->post('/user/two-factor-authentication');
$this->post('/user/two-factor-recovery-codes');
$user = $user->fresh();
$this->post('/user/two-factor-recovery-codes');
expect($user->recoveryCodes())->toHaveCount(8);
expect(array_diff($user->recoveryCodes(), $user->fresh()->recoveryCodes()))->toHaveCount(8);
})->skip(function () {
return ! Features::canManageTwoFactorAuthentication();
}, 'Two factor authentication is not enabled.');
test('two factor authentication can be disabled', function () {
$this->actingAs($user = User::factory()->create());
$this->withSession(['auth.password_confirmed_at' => time()]);
$this->post('/user/two-factor-authentication');
$this->assertNotNull($user->fresh()->two_factor_secret);
$this->delete('/user/two-factor-authentication');
expect($user->fresh()->two_factor_secret)->toBeNull();
})->skip(function () {
return ! Features::canManageTwoFactorAuthentication();
}, 'Two factor authentication is not enabled.');
@@ -0,0 +1,44 @@
<?php
use App\Models\User;
use Illuminate\Support\Facades\Hash;
test('password can be updated', function () {
$this->actingAs($user = User::factory()->create());
$this->put('/user/password', [
'current_password' => 'password',
'password' => 'new-password',
'password_confirmation' => 'new-password',
]);
expect(Hash::check('new-password', $user->fresh()->password))->toBeTrue();
});
test('current password must be correct', function () {
$this->actingAs($user = User::factory()->create());
$response = $this->put('/user/password', [
'current_password' => 'wrong-password',
'password' => 'new-password',
'password_confirmation' => 'new-password',
]);
$response->assertSessionHasErrors();
expect(Hash::check('password', $user->fresh()->password))->toBeTrue();
});
test('new passwords must match', function () {
$this->actingAs($user = User::factory()->create());
$response = $this->put('/user/password', [
'current_password' => 'password',
'password' => 'new-password',
'password_confirmation' => 'wrong-password',
]);
$response->assertSessionHasErrors();
expect(Hash::check('password', $user->fresh()->password))->toBeTrue();
});
@@ -0,0 +1,37 @@
<?php
use App\Models\User;
test('team member roles can be updated', function () {
$this->actingAs($user = User::factory()->withPersonalTeam()->create());
$user->currentTeam->users()->attach(
$otherUser = User::factory()->create(), ['role' => 'admin']
);
$this->put('/teams/'.$user->currentTeam->id.'/members/'.$otherUser->id, [
'role' => 'editor',
]);
expect($otherUser->fresh()->hasTeamRole(
$user->currentTeam->fresh(), 'editor'
))->toBeTrue();
});
test('only team owner can update team member roles', function () {
$user = User::factory()->withPersonalTeam()->create();
$user->currentTeam->users()->attach(
$otherUser = User::factory()->create(), ['role' => 'admin']
);
$this->actingAs($otherUser);
$this->put('/teams/'.$user->currentTeam->id.'/members/'.$otherUser->id, [
'role' => 'editor',
]);
expect($otherUser->fresh()->hasTeamRole(
$user->currentTeam->fresh(), 'admin'
))->toBeTrue();
});
@@ -0,0 +1,14 @@
<?php
use App\Models\User;
test('team names can be updated', function () {
$this->actingAs($user = User::factory()->withPersonalTeam()->create());
$this->put('/teams/'.$user->currentTeam->id, [
'name' => 'Test Team',
]);
expect($user->fresh()->ownedTeams)->toHaveCount(1);
expect($user->currentTeam->fresh()->name)->toEqual('Test Team');
});
@@ -0,0 +1,38 @@
<?php
use App\Models\User;
use Illuminate\Support\Str;
use Laravel\Jetstream\Features;
use Laravel\Jetstream\Http\Livewire\ApiTokenManager;
use Livewire\Livewire;
test('api token permissions can be updated', function () {
if (Features::hasTeamFeatures()) {
$this->actingAs($user = User::factory()->withPersonalTeam()->create());
} else {
$this->actingAs($user = User::factory()->create());
}
$token = $user->tokens()->create([
'name' => 'Test Token',
'token' => Str::random(40),
'abilities' => ['create', 'read'],
]);
Livewire::test(ApiTokenManager::class)
->set(['managingPermissionsFor' => $token])
->set(['updateApiTokenForm' => [
'permissions' => [
'delete',
'missing-permission',
],
]])
->call('updateApiToken');
expect($user->fresh()->tokens->first())
->can('delete')->toBeTrue()
->can('read')->toBeFalse()
->can('missing-permission')->toBeFalse();
})->skip(function () {
return ! Features::hasApiFeatures();
}, 'API support is not enabled.');
@@ -0,0 +1,14 @@
<?php
use App\Models\User;
use Laravel\Jetstream\Http\Livewire\LogoutOtherBrowserSessionsForm;
use Livewire\Livewire;
test('other browser sessions can be logged out', function () {
$this->actingAs(User::factory()->create());
Livewire::test(LogoutOtherBrowserSessionsForm::class)
->set('password', 'password')
->call('logoutOtherBrowserSessions')
->assertSuccessful();
});
@@ -0,0 +1,32 @@
<?php
use App\Models\User;
use Laravel\Jetstream\Features;
use Laravel\Jetstream\Http\Livewire\ApiTokenManager;
use Livewire\Livewire;
test('api tokens can be created', function () {
if (Features::hasTeamFeatures()) {
$this->actingAs($user = User::factory()->withPersonalTeam()->create());
} else {
$this->actingAs($user = User::factory()->create());
}
Livewire::test(ApiTokenManager::class)
->set(['createApiTokenForm' => [
'name' => 'Test Token',
'permissions' => [
'read',
'update',
],
]])
->call('createApiToken');
expect($user->fresh()->tokens)->toHaveCount(1);
expect($user->fresh()->tokens->first())
->name->toEqual('Test Token')
->can('read')->toBeTrue()
->can('delete')->toBeFalse();
})->skip(function () {
return ! Features::hasApiFeatures();
}, 'API support is not enabled.');
@@ -0,0 +1,16 @@
<?php
use App\Models\User;
use Laravel\Jetstream\Http\Livewire\CreateTeamForm;
use Livewire\Livewire;
test('teams can be created', function () {
$this->actingAs($user = User::factory()->withPersonalTeam()->create());
Livewire::test(CreateTeamForm::class)
->set(['state' => ['name' => 'Test Team']])
->call('createTeam');
expect($user->fresh()->ownedTeams)->toHaveCount(2);
expect($user->fresh()->ownedTeams()->latest('id')->first()->name)->toEqual('Test Team');
});
@@ -0,0 +1,31 @@
<?php
use App\Models\User;
use Laravel\Jetstream\Features;
use Laravel\Jetstream\Http\Livewire\DeleteUserForm;
use Livewire\Livewire;
test('user accounts can be deleted', function () {
$this->actingAs($user = User::factory()->create());
Livewire::test(DeleteUserForm::class)
->set('password', 'password')
->call('deleteUser');
expect($user->fresh())->toBeNull();
})->skip(function () {
return ! Features::hasAccountDeletionFeatures();
}, 'Account deletion is not enabled.');
test('correct password must be provided before account can be deleted', function () {
$this->actingAs($user = User::factory()->create());
Livewire::test(DeleteUserForm::class)
->set('password', 'wrong-password')
->call('deleteUser')
->assertHasErrors(['password']);
expect($user->fresh())->not->toBeNull();
})->skip(function () {
return ! Features::hasAccountDeletionFeatures();
}, 'Account deletion is not enabled.');
@@ -0,0 +1,29 @@
<?php
use App\Models\User;
use Illuminate\Support\Str;
use Laravel\Jetstream\Features;
use Laravel\Jetstream\Http\Livewire\ApiTokenManager;
use Livewire\Livewire;
test('api tokens can be deleted', function () {
if (Features::hasTeamFeatures()) {
$this->actingAs($user = User::factory()->withPersonalTeam()->create());
} else {
$this->actingAs($user = User::factory()->create());
}
$token = $user->tokens()->create([
'name' => 'Test Token',
'token' => Str::random(40),
'abilities' => ['create', 'read'],
]);
Livewire::test(ApiTokenManager::class)
->set(['apiTokenIdBeingDeleted' => $token->id])
->call('deleteApiToken');
expect($user->fresh()->tokens)->toHaveCount(0);
})->skip(function () {
return ! Features::hasApiFeatures();
}, 'API support is not enabled.');
@@ -0,0 +1,34 @@
<?php
use App\Models\Team;
use App\Models\User;
use Laravel\Jetstream\Http\Livewire\DeleteTeamForm;
use Livewire\Livewire;
test('teams can be deleted', function () {
$this->actingAs($user = User::factory()->withPersonalTeam()->create());
$user->ownedTeams()->save($team = Team::factory()->make([
'personal_team' => false,
]));
$team->users()->attach(
$otherUser = User::factory()->create(), ['role' => 'test-role']
);
Livewire::test(DeleteTeamForm::class, ['team' => $team->fresh()])
->call('deleteTeam');
expect($team->fresh())->toBeNull();
expect($otherUser->fresh()->teams)->toHaveCount(0);
});
test('personal teams cant be deleted', function () {
$this->actingAs($user = User::factory()->withPersonalTeam()->create());
Livewire::test(DeleteTeamForm::class, ['team' => $user->currentTeam])
->call('deleteTeam')
->assertHasErrors(['team']);
expect($user->currentTeam->fresh())->not->toBeNull();
});
@@ -0,0 +1,48 @@
<?php
use App\Models\User;
use Illuminate\Support\Facades\Mail;
use Laravel\Jetstream\Features;
use Laravel\Jetstream\Http\Livewire\TeamMemberManager;
use Laravel\Jetstream\Mail\TeamInvitation;
use Livewire\Livewire;
test('team members can be invited to team', function () {
Mail::fake();
$this->actingAs($user = User::factory()->withPersonalTeam()->create());
Livewire::test(TeamMemberManager::class, ['team' => $user->currentTeam])
->set('addTeamMemberForm', [
'email' => 'test@example.com',
'role' => 'admin',
])->call('addTeamMember');
Mail::assertSent(TeamInvitation::class);
expect($user->currentTeam->fresh()->teamInvitations)->toHaveCount(1);
})->skip(function () {
return ! Features::sendsTeamInvitations();
}, 'Team invitations not enabled.');
test('team member invitations can be cancelled', function () {
Mail::fake();
$this->actingAs($user = User::factory()->withPersonalTeam()->create());
// Add the team member...
$component = Livewire::test(TeamMemberManager::class, ['team' => $user->currentTeam])
->set('addTeamMemberForm', [
'email' => 'test@example.com',
'role' => 'admin',
])->call('addTeamMember');
$invitationId = $user->currentTeam->fresh()->teamInvitations->first()->id;
// Cancel the team invitation...
$component->call('cancelTeamInvitation', $invitationId);
expect($user->currentTeam->fresh()->teamInvitations)->toHaveCount(0);
})->skip(function () {
return ! Features::sendsTeamInvitations();
}, 'Team invitations not enabled.');
@@ -0,0 +1,30 @@
<?php
use App\Models\User;
use Laravel\Jetstream\Http\Livewire\TeamMemberManager;
use Livewire\Livewire;
test('users can leave teams', function () {
$user = User::factory()->withPersonalTeam()->create();
$user->currentTeam->users()->attach(
$otherUser = User::factory()->create(), ['role' => 'admin']
);
$this->actingAs($otherUser);
Livewire::test(TeamMemberManager::class, ['team' => $user->currentTeam])
->call('leaveTeam');
expect($user->currentTeam->fresh()->users)->toHaveCount(0);
});
test('team owners cant leave their own team', function () {
$this->actingAs($user = User::factory()->withPersonalTeam()->create());
Livewire::test(TeamMemberManager::class, ['team' => $user->currentTeam])
->call('leaveTeam')
->assertHasErrors(['team']);
expect($user->currentTeam->fresh())->not->toBeNull();
});
@@ -0,0 +1,26 @@
<?php
use App\Models\User;
use Laravel\Jetstream\Http\Livewire\UpdateProfileInformationForm;
use Livewire\Livewire;
test('current profile information is available', function () {
$this->actingAs($user = User::factory()->create());
$component = Livewire::test(UpdateProfileInformationForm::class);
expect($component->state['name'])->toEqual($user->name);
expect($component->state['email'])->toEqual($user->email);
});
test('profile information can be updated', function () {
$this->actingAs($user = User::factory()->create());
Livewire::test(UpdateProfileInformationForm::class)
->set('state', ['name' => 'Test Name', 'email' => 'test@example.com'])
->call('updateProfileInformation');
expect($user->fresh())
->name->toEqual('Test Name')
->email->toEqual('test@example.com');
});
@@ -0,0 +1,34 @@
<?php
use App\Models\User;
use Laravel\Jetstream\Http\Livewire\TeamMemberManager;
use Livewire\Livewire;
test('team members can be removed from teams', function () {
$this->actingAs($user = User::factory()->withPersonalTeam()->create());
$user->currentTeam->users()->attach(
$otherUser = User::factory()->create(), ['role' => 'admin']
);
Livewire::test(TeamMemberManager::class, ['team' => $user->currentTeam])
->set('teamMemberIdBeingRemoved', $otherUser->id)
->call('removeTeamMember');
expect($user->currentTeam->fresh()->users)->toHaveCount(0);
});
test('only team owner can remove team members', function () {
$user = User::factory()->withPersonalTeam()->create();
$user->currentTeam->users()->attach(
$otherUser = User::factory()->create(), ['role' => 'admin']
);
$this->actingAs($otherUser);
Livewire::test(TeamMemberManager::class, ['team' => $user->currentTeam])
->set('teamMemberIdBeingRemoved', $user->id)
->call('removeTeamMember')
->assertStatus(403);
});
@@ -0,0 +1,58 @@
<?php
use App\Models\User;
use Laravel\Fortify\Features;
use Laravel\Jetstream\Http\Livewire\TwoFactorAuthenticationForm;
use Livewire\Livewire;
test('two factor authentication can be enabled', function () {
$this->actingAs($user = User::factory()->create()->fresh());
$this->withSession(['auth.password_confirmed_at' => time()]);
Livewire::test(TwoFactorAuthenticationForm::class)
->call('enableTwoFactorAuthentication');
$user = $user->fresh();
expect($user->two_factor_secret)->not->toBeNull();
expect($user->recoveryCodes())->toHaveCount(8);
})->skip(function () {
return ! Features::canManageTwoFactorAuthentication();
}, 'Two factor authentication is not enabled.');
test('recovery codes can be regenerated', function () {
$this->actingAs($user = User::factory()->create()->fresh());
$this->withSession(['auth.password_confirmed_at' => time()]);
$component = Livewire::test(TwoFactorAuthenticationForm::class)
->call('enableTwoFactorAuthentication')
->call('regenerateRecoveryCodes');
$user = $user->fresh();
$component->call('regenerateRecoveryCodes');
expect($user->recoveryCodes())->toHaveCount(8);
expect(array_diff($user->recoveryCodes(), $user->fresh()->recoveryCodes()))->toHaveCount(8);
})->skip(function () {
return ! Features::canManageTwoFactorAuthentication();
}, 'Two factor authentication is not enabled.');
test('two factor authentication can be disabled', function () {
$this->actingAs($user = User::factory()->create()->fresh());
$this->withSession(['auth.password_confirmed_at' => time()]);
$component = Livewire::test(TwoFactorAuthenticationForm::class)
->call('enableTwoFactorAuthentication');
$this->assertNotNull($user->fresh()->two_factor_secret);
$component->call('disableTwoFactorAuthentication');
expect($user->fresh()->two_factor_secret)->toBeNull();
})->skip(function () {
return ! Features::canManageTwoFactorAuthentication();
}, 'Two factor authentication is not enabled.');
@@ -0,0 +1,50 @@
<?php
use App\Models\User;
use Illuminate\Support\Facades\Hash;
use Laravel\Jetstream\Http\Livewire\UpdatePasswordForm;
use Livewire\Livewire;
test('password can be updated', function () {
$this->actingAs($user = User::factory()->create());
Livewire::test(UpdatePasswordForm::class)
->set('state', [
'current_password' => 'password',
'password' => 'new-password',
'password_confirmation' => 'new-password',
])
->call('updatePassword');
expect(Hash::check('new-password', $user->fresh()->password))->toBeTrue();
});
test('current password must be correct', function () {
$this->actingAs($user = User::factory()->create());
Livewire::test(UpdatePasswordForm::class)
->set('state', [
'current_password' => 'wrong-password',
'password' => 'new-password',
'password_confirmation' => 'new-password',
])
->call('updatePassword')
->assertHasErrors(['current_password']);
expect(Hash::check('password', $user->fresh()->password))->toBeTrue();
});
test('new passwords must match', function () {
$this->actingAs($user = User::factory()->create());
Livewire::test(UpdatePasswordForm::class)
->set('state', [
'current_password' => 'password',
'password' => 'new-password',
'password_confirmation' => 'wrong-password',
])
->call('updatePassword')
->assertHasErrors(['password']);
expect(Hash::check('password', $user->fresh()->password))->toBeTrue();
});
@@ -0,0 +1,42 @@
<?php
use App\Models\User;
use Laravel\Jetstream\Http\Livewire\TeamMemberManager;
use Livewire\Livewire;
test('team member roles can be updated', function () {
$this->actingAs($user = User::factory()->withPersonalTeam()->create());
$user->currentTeam->users()->attach(
$otherUser = User::factory()->create(), ['role' => 'admin']
);
Livewire::test(TeamMemberManager::class, ['team' => $user->currentTeam])
->set('managingRoleFor', $otherUser)
->set('currentRole', 'editor')
->call('updateRole');
expect($otherUser->fresh()->hasTeamRole(
$user->currentTeam->fresh(), 'editor'
))->toBeTrue();
});
test('only team owner can update team member roles', function () {
$user = User::factory()->withPersonalTeam()->create();
$user->currentTeam->users()->attach(
$otherUser = User::factory()->create(), ['role' => 'admin']
);
$this->actingAs($otherUser);
Livewire::test(TeamMemberManager::class, ['team' => $user->currentTeam])
->set('managingRoleFor', $otherUser)
->set('currentRole', 'editor')
->call('updateRole')
->assertStatus(403);
expect($otherUser->fresh()->hasTeamRole(
$user->currentTeam->fresh(), 'admin'
))->toBeTrue();
});
@@ -0,0 +1,16 @@
<?php
use App\Models\User;
use Laravel\Jetstream\Http\Livewire\UpdateTeamNameForm;
use Livewire\Livewire;
test('team names can be updated', function () {
$this->actingAs($user = User::factory()->withPersonalTeam()->create());
Livewire::test(UpdateTeamNameForm::class, ['team' => $user->currentTeam])
->set(['state' => ['name' => 'Test Team']])
->call('updateTeamName');
expect($user->fresh()->ownedTeams)->toHaveCount(1);
expect($user->currentTeam->fresh()->name)->toEqual('Test Team');
});