Skip to main content
You are currently viewing the documentation for Filament 2.x, which is a previous version of Filament.Looking for the current stable version? Visit the 5.x documentation.
All examples in this guide will be written using Pest. However, you can easily adapt this to a PHPUnit. Since all pages in the admin panel are Livewire components, we’re just using Livewire testing helpers everywhere. If you’ve never tested Livewire components before, please read this guide from the Livewire docs.

Getting started

Ensure that you are authenticated to access the admin panel in your TestCase:

Resources

Pages

List

Routing & render
To ensure that the List page for the PostResource is able to render successfully, generate a page URL, perform a request to this URL and ensure that it is successful:
Table
Filament includes a selection of helpers for testing tables. A full guide to testing tables can be found in the Table Builder documentation. To use a table testing helper, make assertions on the resource’s List page class, which holds the table:

Create

Routing & render
To ensure that the Create page for the PostResource is able to render successfully, generate a page URL, perform a request to this URL and ensure that it is successful:
Creating
You may check that data is correctly saved into the database by calling fillForm() with your form data, and then asserting that the database contains a matching record:
Validation
Use assertHasFormErrors() to ensure that data is properly validated in a form:

Edit

Routing & render
To ensure that the Edit page for the PostResource is able to render successfully, generate a page URL, perform a request to this URL and ensure that it is successful:
Filling existing data
To check that the form is filled with the correct data from the database, you may assertFormSet() that the data in the form matches that of the record:
Saving
You may check that data is correctly saved into the database by calling fillForm() with your form data, and then asserting that the database contains a matching record:
Validation
Use assertHasFormErrors() to ensure that data is properly validated in a form:
Deleting
You can test the DeleteAction using callPageAction():
You can ensure that a particular user is not able to see a DeleteAction using assertPageActionHidden():

View

Routing & render
To ensure that the View page for the PostResource is able to render successfully, generate a page URL, perform a request to this URL and ensure that it is successful:
Filling existing data
To check that the form is filled with the correct data from the database, you may assertSet() that the data in the form matches that of the record:

Relation managers

Render
To ensure that a relation manager is able to render successfully, mount the Livewire component:
Table
Filament includes a selection of helpers for testing tables. A full guide to testing tables can be found in the Table Builder documentation. To use a table testing helper, make assertions on the relation manager class, which holds the table:

Page actions

Calling actions

You can call a page action by passing its name or class to callPageAction():
To pass an array of data into an action, use the data parameter:
If you ever need to only set a page action’s data without immediately calling it, you can use setPageActionData():

Execution

To check if an action has been halted, you can use assertPageActionHalted():

Errors

assertHasNoPageActionErrors() is used to assert that no validation errors occurred when submitting the action form. To check if a validation error has occurred with the data, use assertHasPageActionErrors(), similar to assertHasErrors() in Livewire:

Pre-filled data

To check if a page action is pre-filled with data, you can use the assertPageActionDataSet() method:

Action State

To ensure that an action exists or doesn’t in a table, you can use the assertPageActionExists() or assertPageActionDoesNotExist() method:
To ensure a page action is hidden or visible for a user, you can use the assertPageActionHidden() or assertPageActionVisible() methods:
To ensure a page action is enabled or disabled for a user, you can use the assertPageActionEnabled() or assertPageActionDisabled() methods:
To ensure sets of actions exist in the correct order, you can use assertPageActionsExistInOrder():

Button appearance

To ensure an action has the correct label, you can use assertPageActionHasLabel() and assertPageActionDoesNotHaveLabel():
To ensure an action’s button is showing the correct icon, you can use assertPageActionHasIcon() or assertPageActionDoesNotHaveIcon():
To ensure an action’s button is displaying the right color, you can use assertPageActionHasColor() or assertPageActionDoesNotHaveColor():

URL

To ensure an action has the correct URL, you can use assertPageActionHasUrl(), assertPageActionDoesNotHaveUrl(), assertPageActionShouldOpenUrlInNewTab(), and assertPageActionShouldNotOpenUrlInNewTab():