
Test resources with multi tenants
By: Lara Zeus
- Published: 30 Mar 2024 Updated: 04 May 2024
A starting point for testing filamentPHP with tenant aware resources.

test render tenant owned records
1beforeEach(function ((){
2 $this->company = Club::factory()->create();
3 $this->user = User::factory()->create();
4 $this->user->company()->attach($this->company);
5
6 actingAs($this->user);
7 Filament::setTenant($this->company);
8});
test listing the tenant records only
1use function Pest\Livewire\livewire;
2
3it('can only render tenant owned records', function () {
4 // Edit logic here ??
5 $posts = Post::factory()->count(4)->create();
6 $trashedPosts = Post::factory()
7 ->trashed()
8 ->count(6)
9 ->create();
10
11 livewire(PostResource\Pages\ListPosts::class)
12 ->assertCanSeeTableRecords($posts)
13 ->assertCanNotSeeTableRecords($trashedPosts)
14 ->assertCountTableRecords(4);
15});

Related Tricks:
Sticky Actions In Forms
Bring the sticky actions back form filament v2
Add a Language Switcher Under The User Menu
Integrate Language Switcher in User Menu for a Cleaner Top Bar
Globally Translate all Components
make all Field or any components translatable
Add new link to the panel topbar
add any link or actions to the topbar
Disabling the cancel button on the filament editing form
Usability: Knowing whether or not the record was saved.