Mister Nicolaz
Mister Nicolaz
FFilament
Created by Mister Nicolaz on 4/16/2024 in #❓┊help
Test authentication with Pest
I could of course also omit the return false, but phpstan actually expects that there is a return value in any case
21 replies
FFilament
Created by Mister Nicolaz on 4/16/2024 in #❓┊help
Test authentication with Pest
In the filament repository I came across a test that would best suit this:
test('unauthenticated user cannot login admin panel', function () {
Filament::setCurrentPanel(Filament::getPanel('admin'));

livewire(Login::class)
->fillForm([
'email' => $this->user->email,
'password' => 'password',
])
->call('authenticate')
->assertHasFormErrors(['email']);

$this->assertGuest();
});
test('unauthenticated user cannot login admin panel', function () {
Filament::setCurrentPanel(Filament::getPanel('admin'));

livewire(Login::class)
->fillForm([
'email' => $this->user->email,
'password' => 'password',
])
->call('authenticate')
->assertHasFormErrors(['email']);

$this->assertGuest();
});
As a test it passes, but it does not ensure that I get code coverage on the return false; 🤔
21 replies
FFilament
Created by Mister Nicolaz on 4/16/2024 in #❓┊help
Test authentication with Pest
How could I test that a normal user with the role user does not have access to the panel?
21 replies
FFilament
Created by Mister Nicolaz on 4/16/2024 in #❓┊help
Test authentication with Pest
Given this function in the User model:
public function canAccessPanel(Panel $panel): bool
{
if ($panel->getId() === 'admin') {
return $this->hasRole(['Super Admin', 'Moderator']);
}
return false;
}
public function canAccessPanel(Panel $panel): bool
{
if ($panel->getId() === 'admin') {
return $this->hasRole(['Super Admin', 'Moderator']);
}
return false;
}
21 replies
FFilament
Created by Mister Nicolaz on 4/16/2024 in #❓┊help
Test authentication with Pest
Still a question about testing authentication with pest
21 replies
FFilament
Created by Mister Nicolaz on 4/16/2024 in #❓┊help
Test authentication with Pest
Is there a useful CI/CD workflow that I could use on Github, so that I can run the tests at each PR?
21 replies
FFilament
Created by Mister Nicolaz on 4/16/2024 in #❓┊help
Test authentication with Pest
I've now managed to make some specific tests with livewire 🙂
21 replies
FFilament
Created by Mister Nicolaz on 4/16/2024 in #❓┊help
Test authentication with Pest
Filament is still quite new to me, but I have worked with Laravel before in the past. What I mainly miss are good guidelines on how you should/shouldn't set up tests (from A to Z).
21 replies
FFilament
Created by Mister Nicolaz on 4/16/2024 in #❓┊help
Test authentication with Pest
You have a good point there 😅
21 replies
FFilament
Created by Mister Nicolaz on 4/16/2024 in #❓┊help
Test authentication with Pest
Yes, I understand that, but I only see examples for a PostResource and I specifically want to test the authentication. So logging in, registering and logging out.
21 replies
FFilament
Created by Mister Nicolaz on 4/16/2024 in #❓┊help
Test authentication with Pest
That raises more questions for me than answers
21 replies