Phase 0: Fundament für Inhaus
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m14s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m7s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m19s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 1m32s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 1m22s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 1m32s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 1m35s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m7s

- Laravel 13 mit Filament 5 (Admin), Inertia 3 + Vue 3 + Vuetify 4 (Material 3)
- Anmeldung über Fortify (Login, Passwort vergessen/ändern), keine Selbstregistrierung
- Profil mit Profilbild (WebP in festen Größen), Personenseiten, Header mit Avatar-Menü
- Material-3-Farbschema aus der Primärfarbe, hell/dunkel/System pro Person
- Basis-Branding (Portalname, Logo, Primärfarbe) im Admin unter „Erscheinungsbild“
- Benutzerverwaltung im Admin, Zugang vorläufig über is_admin
- vendor/ (ohne Dev-Pakete) und Frontend-Build mitversioniert, Dev-Pakete in vendor-dev/
- PHPUnit-Tests gegen MySQL/MariaDB, Forgejo-CI-Matrix, Docker-Entwicklungsumgebung
- VERSION, CHANGELOG.md und CONTRIBUTING.md mit Release-Ablauf

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Friederich Loheide 2026-09-25 20:35:30 +00:00
parent 7197eaebf2
commit 9c0f8de791
15771 changed files with 1564103 additions and 5 deletions

View file

@ -0,0 +1,421 @@
<?php
namespace Filament\Tables\Testing;
use BackedEnum;
use Closure;
use Filament\Actions\Action;
use Filament\Actions\Testing\TestsActions as BaseTestsActions;
use Filament\Tables\Contracts\HasTable;
use Illuminate\Support\Arr;
use Livewire\Component;
use Livewire\Features\SupportTesting\Testable;
/**
* @method Component&HasTable instance()
*
* @mixin Testable
* @mixin BaseTestsActions
*/
class TestsActions
{
public function mountTableAction(): Closure
{
return function (string | array $actions, $record = null): static {
/** @var array<array<string, mixed>> $actions */
/** @phpstan-ignore-next-line */
$actions = $this->parseNestedTableActions($actions, $record);
$this->mountAction($actions);
return $this;
};
}
public function unmountTableAction(): Closure
{
return function (): static {
$this->unmountAction();
return $this;
};
}
public function setTableActionData(): Closure
{
return function (array $data): static {
$this->fillForm($data);
return $this;
};
}
public function assertTableActionDataSet(): Closure
{
return function (array | Closure $data): static {
$this->assertSchemaStateSet($data);
return $this;
};
}
public function callTableAction(): Closure
{
return function (string | array $actions, $record = null, array $data = [], array $arguments = []): static {
/** @var array<array<string, mixed>> $actions */
/** @phpstan-ignore-next-line */
$actions = $this->parseNestedTableActions($actions, $record, $arguments);
$this->callAction($actions, $data);
return $this;
};
}
public function callMountedTableAction(): Closure
{
return function (array $arguments = []): static {
$this->callMountedAction($arguments);
return $this;
};
}
public function assertTableActionExists(): Closure
{
return function (string | array $actions, ?Closure $checkActionUsing = null, $record = null): static {
/** @var array<array<string, mixed>> $actions */
/** @phpstan-ignore-next-line */
$actions = $this->parseNestedTableActions($actions, $record);
$this->assertActionExists($actions, $checkActionUsing);
return $this;
};
}
public function assertTableActionDoesNotExist(): Closure
{
return function (string | array $actions, ?Closure $checkActionUsing = null, $record = null): static {
/** @var array<array<string, mixed>> $actions */
/** @phpstan-ignore-next-line */
$actions = $this->parseNestedTableActions($actions, $record);
$this->assertActionDoesNotExist($actions, $checkActionUsing);
return $this;
};
}
public function assertTableActionsExistInOrder(): Closure
{
return function (array $names): static {
$this->assertActionListInOrder(
$names,
$this->instance()->getTable()->getActions(),
'table',
Action::class,
);
return $this;
};
}
public function assertTableHeaderActionsExistInOrder(): Closure
{
return function (array $names): static {
$this->assertActionListInOrder(
$names,
$this->instance()->getTable()->getHeaderActions(),
'table header',
Action::class,
);
return $this;
};
}
public function assertTableEmptyStateActionsExistInOrder(): Closure
{
return function (array $names): static {
$this->assertActionListInOrder(
$names,
$this->instance()->getTable()->getEmptyStateActions(),
'table empty state',
Action::class,
);
return $this;
};
}
public function assertTableActionVisible(): Closure
{
return function (string | array $actions, $record = null): static {
/** @var array<array<string, mixed>> $actions */
/** @phpstan-ignore-next-line */
$actions = $this->parseNestedTableActions($actions, $record);
$this->assertActionVisible($actions);
return $this;
};
}
public function assertTableActionHidden(): Closure
{
return function (string | array $actions, $record = null): static {
/** @var array<array<string, mixed>> $actions */
/** @phpstan-ignore-next-line */
$actions = $this->parseNestedTableActions($actions, $record);
$this->assertActionHidden($actions);
return $this;
};
}
public function assertTableActionEnabled(): Closure
{
return function (string | array $actions, $record = null): static {
/** @var array<array<string, mixed>> $actions */
/** @phpstan-ignore-next-line */
$actions = $this->parseNestedTableActions($actions, $record);
$this->assertActionEnabled($actions);
return $this;
};
}
public function assertTableActionDisabled(): Closure
{
return function (string | array $actions, $record = null): static {
/** @var array<array<string, mixed>> $actions */
/** @phpstan-ignore-next-line */
$actions = $this->parseNestedTableActions($actions, $record);
$this->assertActionDisabled($actions);
return $this;
};
}
public function assertTableActionHasIcon(): Closure
{
return function (string | array $actions, string | BackedEnum $icon, $record = null): static {
/** @var array<array<string, mixed>> $actions */
/** @phpstan-ignore-next-line */
$actions = $this->parseNestedTableActions($actions, $record);
$this->assertActionHasIcon($actions, $icon);
return $this;
};
}
public function assertTableActionDoesNotHaveIcon(): Closure
{
return function (string | array $actions, string | BackedEnum $icon, $record = null): static {
/** @var array<array<string, mixed>> $actions */
/** @phpstan-ignore-next-line */
$actions = $this->parseNestedTableActions($actions, $record);
$this->assertActionDoesNotHaveIcon($actions, $icon);
return $this;
};
}
public function assertTableActionHasLabel(): Closure
{
return function (string | array $actions, string $label, $record = null): static {
/** @var array<array<string, mixed>> $actions */
/** @phpstan-ignore-next-line */
$actions = $this->parseNestedTableActions($actions, $record);
$this->assertActionHasLabel($actions, $label);
return $this;
};
}
public function assertTableActionDoesNotHaveLabel(): Closure
{
return function (string | array $actions, string $label, $record = null): static {
/** @var array<array<string, mixed>> $actions */
/** @phpstan-ignore-next-line */
$actions = $this->parseNestedTableActions($actions, $record);
$this->assertActionDoesNotHaveLabel($actions, $label);
return $this;
};
}
public function assertTableActionHasColor(): Closure
{
return function (string | array $actions, string | array $color, $record = null): static {
/** @var array<array<string, mixed>> $actions */
/** @phpstan-ignore-next-line */
$actions = $this->parseNestedTableActions($actions, $record);
$this->assertActionHasColor($actions, $color);
return $this;
};
}
public function assertTableActionDoesNotHaveColor(): Closure
{
return function (string | array $actions, string | array $color, $record = null): static {
/** @var array<array<string, mixed>> $actions */
/** @phpstan-ignore-next-line */
$actions = $this->parseNestedTableActions($actions, $record);
$this->assertActionDoesNotHaveColor($actions, $color);
return $this;
};
}
public function assertTableActionHasUrl(): Closure
{
return function (string | array $actions, string $url, $record = null): static {
/** @var array<array<string, mixed>> $actions */
/** @phpstan-ignore-next-line */
$actions = $this->parseNestedTableActions($actions, $record);
$this->assertActionHasUrl($actions, $url);
return $this;
};
}
public function assertTableActionDoesNotHaveUrl(): Closure
{
return function (string | array $actions, string $url, $record = null): static {
/** @var array<array<string, mixed>> $actions */
/** @phpstan-ignore-next-line */
$actions = $this->parseNestedTableActions($actions, $record);
$this->assertActionDoesNotHaveUrl($actions, $url);
return $this;
};
}
public function assertTableActionShouldOpenUrlInNewTab(): Closure
{
return function (string | array $actions, $record = null): static {
/** @var array<array<string, mixed>> $actions */
/** @phpstan-ignore-next-line */
$actions = $this->parseNestedTableActions($actions, $record);
$this->assertActionShouldOpenUrlInNewTab($actions);
return $this;
};
}
public function assertTableActionShouldNotOpenUrlInNewTab(): Closure
{
return function (string | array $actions, $record = null): static {
/** @var array<array<string, mixed>> $actions */
/** @phpstan-ignore-next-line */
$actions = $this->parseNestedTableActions($actions, $record);
$this->assertActionShouldNotOpenUrlInNewTab($actions);
return $this;
};
}
public function assertTableActionMounted(): Closure
{
return function (string | array $actions): static {
/** @var array<array<string, mixed>> $actions */
/** @phpstan-ignore-next-line */
$actions = $this->parseNestedTableActions($actions);
$this->assertActionMounted($actions);
return $this;
};
}
public function assertTableActionNotMounted(): Closure
{
return function (string | array $actions): static {
/** @var array<array<string, mixed>> $actions */
/** @phpstan-ignore-next-line */
$actions = $this->parseNestedTableActions($actions);
$this->assertActionNotMounted($actions);
return $this;
};
}
public function assertTableActionHalted(): Closure
{
return $this->assertTableActionMounted();
}
/**
* @deprecated Use `assertTableActionHalted()` instead.
*/
public function assertTableActionHeld(): Closure
{
return $this->assertTableActionHalted();
}
public function assertHasTableActionErrors(): Closure
{
return function (array $keys = []): static {
$this->assertHasFormErrors($keys);
return $this;
};
}
public function assertHasNoTableActionErrors(): Closure
{
return function (array $keys = []): static {
$this->assertHasNoFormErrors($keys);
return $this;
};
}
public function parseNestedTableActions(): Closure
{
return function (string | array $actions, $record = null, array $arguments = []): array {
/** @var array<array<string, mixed>> $actions */
$actions = $this->parseNestedActions($actions, $arguments);
$actions = array_map(
function (array $action): array {
$action['context']['table'] = true;
return $action;
},
$actions,
);
if (blank($record)) {
return $actions;
}
if (empty($actions)) {
return $actions;
}
$firstAction = Arr::first($actions);
$firstAction['context']['recordKey'] = $record;
$actions[array_key_first($actions)] = $firstAction;
return $actions;
};
}
}

View file

@ -0,0 +1,341 @@
<?php
namespace Filament\Tables\Testing;
use BackedEnum;
use Closure;
use Filament\Actions\BulkAction;
use Filament\Tables\Contracts\HasTable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
use Livewire\Component;
use Livewire\Features\SupportTesting\Testable;
/**
* @method Component&HasTable instance()
*
* @mixin Testable
*/
class TestsBulkActions
{
public function selectTableRecords(): Closure
{
return function (array | Collection $records): static {
$this->set('selectedTableRecords', array_map(
function ($record) {
if ($record instanceof Model) {
return $this->instance()->getTableRecordKey($record);
}
return $record;
},
$records instanceof Collection ? $records->all() : $records,
));
return $this;
};
}
public function mountTableBulkAction(): Closure
{
return function (string | array $actions, array | Collection $records): static {
/** @phpstan-ignore-next-line */
$this->selectTableRecords($records);
/** @var array<array<string, mixed>> $actions */
/** @phpstan-ignore-next-line */
$actions = $this->parseNestedTableBulkActions($actions);
$this->mountAction($actions);
return $this;
};
}
public function setTableBulkActionData(): Closure
{
return function (array $data): static {
$this->fillForm($data);
return $this;
};
}
public function assertTableBulkActionDataSet(): Closure
{
return function (array | Closure $data): static {
$this->assertSchemaStateSet($data);
return $this;
};
}
public function callTableBulkAction(): Closure
{
return function (string | array $actions, array | Collection $records, array $data = [], array $arguments = []): static {
/** @phpstan-ignore-next-line */
$this->selectTableRecords($records);
/** @var array<array<string, mixed>> $actions */
/** @phpstan-ignore-next-line */
$actions = $this->parseNestedTableBulkActions($actions);
$this->callAction($actions, $data, $arguments);
return $this;
};
}
public function callMountedTableBulkAction(): Closure
{
return function (array $arguments = []): static {
$this->callMountedAction($arguments);
return $this;
};
}
public function assertTableBulkActionExists(): Closure
{
return function (string | array $actions): static {
/** @var array<array<string, mixed>> $actions */
/** @phpstan-ignore-next-line */
$actions = $this->parseNestedTableBulkActions($actions);
$this->assertActionExists($actions);
return $this;
};
}
public function assertTableBulkActionDoesNotExist(): Closure
{
return function (string | array $actions): static {
/** @var array<array<string, mixed>> $actions */
/** @phpstan-ignore-next-line */
$actions = $this->parseNestedTableBulkActions($actions);
$this->assertActionDoesNotExist($actions);
return $this;
};
}
public function assertTableBulkActionsExistInOrder(): Closure
{
return function (array $names): static {
$this->assertActionListInOrder(
$names,
$this->instance()->getTable()->getBulkActions(),
'table bulk',
BulkAction::class,
);
return $this;
};
}
public function assertTableBulkActionVisible(): Closure
{
return function (string | array $actions): static {
/** @var array<array<string, mixed>> $actions */
/** @phpstan-ignore-next-line */
$actions = $this->parseNestedTableBulkActions($actions);
$this->assertActionVisible($actions);
return $this;
};
}
public function assertTableBulkActionHidden(): Closure
{
return function (string | array $actions): static {
/** @var array<array<string, mixed>> $actions */
/** @phpstan-ignore-next-line */
$actions = $this->parseNestedTableBulkActions($actions);
$this->assertActionHidden($actions);
return $this;
};
}
public function assertTableBulkActionEnabled(): Closure
{
return function (string | array $actions): static {
/** @var array<array<string, mixed>> $actions */
/** @phpstan-ignore-next-line */
$actions = $this->parseNestedTableBulkActions($actions);
$this->assertActionEnabled($actions);
return $this;
};
}
public function assertTableBulkActionDisabled(): Closure
{
return function (string | array $actions): static {
/** @var array<array<string, mixed>> $actions */
/** @phpstan-ignore-next-line */
$actions = $this->parseNestedTableBulkActions($actions);
$this->assertActionDisabled($actions);
return $this;
};
}
public function assertTableBulkActionHasIcon(): Closure
{
return function (string | array $actions, string | BackedEnum $icon): static {
/** @var array<array<string, mixed>> $actions */
/** @phpstan-ignore-next-line */
$actions = $this->parseNestedTableBulkActions($actions);
$this->assertActionHasIcon($actions, $icon);
return $this;
};
}
public function assertTableBulkActionDoesNotHaveIcon(): Closure
{
return function (string | array $actions, string | BackedEnum $icon): static {
/** @var array<array<string, mixed>> $actions */
/** @phpstan-ignore-next-line */
$actions = $this->parseNestedTableBulkActions($actions);
$this->assertActionDoesNotHaveIcon($actions, $icon);
return $this;
};
}
public function assertTableBulkActionHasLabel(): Closure
{
return function (string | array $actions, string $label): static {
/** @var array<array<string, mixed>> $actions */
/** @phpstan-ignore-next-line */
$actions = $this->parseNestedTableBulkActions($actions);
$this->assertActionHasLabel($actions, $label);
return $this;
};
}
public function assertTableBulkActionDoesNotHaveLabel(): Closure
{
return function (string | array $actions, string $label): static {
/** @var array<array<string, mixed>> $actions */
/** @phpstan-ignore-next-line */
$actions = $this->parseNestedTableBulkActions($actions);
$this->assertActionDoesNotHaveLabel($actions, $label);
return $this;
};
}
public function assertTableBulkActionHasColor(): Closure
{
return function (string | array $actions, string | array $color): static {
/** @var array<array<string, mixed>> $actions */
/** @phpstan-ignore-next-line */
$actions = $this->parseNestedTableBulkActions($actions);
$this->assertActionHasColor($actions, $color);
return $this;
};
}
public function assertTableBulkActionDoesNotHaveColor(): Closure
{
return function (string | array $actions, string | array $color): static {
/** @var array<array<string, mixed>> $actions */
/** @phpstan-ignore-next-line */
$actions = $this->parseNestedTableBulkActions($actions);
$this->assertActionDoesNotHaveColor($actions, $color);
return $this;
};
}
public function assertTableBulkActionMounted(): Closure
{
return function (string | array $actions): static {
/** @var array<array<string, mixed>> $actions */
/** @phpstan-ignore-next-line */
$actions = $this->parseNestedTableBulkActions($actions);
$this->assertActionMounted($actions);
return $this;
};
}
public function assertTableBulkActionNotMounted(): Closure
{
return function (string | array $actions): static {
/** @var array<array<string, mixed>> $actions */
/** @phpstan-ignore-next-line */
$actions = $this->parseNestedTableBulkActions($actions);
$this->assertActionNotMounted($actions);
return $this;
};
}
public function assertTableBulkActionHalted(): Closure
{
return $this->assertTableBulkActionMounted();
}
/**
* @deprecated Use `assertTableBulkActionHalted()` instead.
*/
public function assertTableBulkActionHeld(): Closure
{
return $this->assertTableBulkActionHalted();
}
public function assertHasTableBulkActionErrors(): Closure
{
return function (array $keys = []): static {
$this->assertHasFormErrors($keys);
return $this;
};
}
public function assertHasNoTableBulkActionErrors(): Closure
{
return function (array $keys = []): static {
$this->assertHasNoFormErrors($keys);
return $this;
};
}
public function parseNestedTableBulkActions(): Closure
{
return function (string | array $actions): array {
/** @var array<array<string, mixed>> $actions */
$actions = $this->parseNestedTableActions($actions);
return array_map(
function (array $action): array {
$action['context']['bulk'] = true;
return $action;
},
$actions,
);
};
}
}

View file

@ -0,0 +1,667 @@
<?php
namespace Filament\Tables\Testing;
use Closure;
use Filament\Support\ArrayRecord;
use Filament\Tables\Columns\Column;
use Filament\Tables\Columns\SelectColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Contracts\HasTable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Testing\Assert;
use Livewire\Component;
use Livewire\Features\SupportTesting\Testable;
/**
* @method Component&HasTable instance()
*
* @mixin Testable
*/
class TestsColumns
{
public function assertCanRenderTableColumn(): Closure
{
return function (string $name): static {
/** @phpstan-ignore-next-line */
$this->assertTableColumnVisible($name);
$livewire = $this->instance();
$livewireId = $livewire->getId();
$html = array_map(
function ($record) use ($livewire, $livewireId, $name): string {
return "wire:key=\"{$livewireId}.table.record.{$livewire->getTableRecordKey($record)}.column.{$name}\"";
},
$this->instance()->getTableRecords()->all(),
);
$this->assertSeeHtml($html);
return $this;
};
}
public function assertCanNotRenderTableColumn(): Closure
{
return function (string $name): static {
/** @phpstan-ignore-next-line */
$this->assertTableColumnExists($name);
$livewire = $this->instance();
$livewireId = $livewire->getId();
$html = array_map(
function ($record) use ($livewire, $livewireId, $name): string {
return "wire:key=\"{$livewireId}.table.record.{$livewire->getTableRecordKey($record)}.column.{$name}\"";
},
$this->instance()->getTableRecords()->all(),
);
$this->assertDontSeeHtml($html);
return $this;
};
}
protected function assertTableRecordKeyExists(): Closure
{
return function (?string $recordKey): static {
$record = $this->instance()->getTableRecord($recordKey);
$livewireClass = $this->instance()::class;
Assert::assertNotEmpty(
$record,
"Failed asserting that a table row with key {$recordKey} exists on the [{$livewireClass}] component.",
);
return $this;
};
}
public function assertTableColumnExists(): Closure
{
return function (string $name, ?Closure $checkColumnUsing = null, $record = null): static {
$column = $this->instance()->getTable()->getColumn($name);
$livewireClass = $this->instance()::class;
Assert::assertInstanceOf(
Column::class,
$column,
"Failed asserting that a table column with name [{$name}] exists on the [{$livewireClass}] component.",
);
if ($record) {
if ($record instanceof Model) {
$recordKey = (string) $record->getKey();
} elseif (is_array($record)) {
$recordKey = (string) $record[ArrayRecord::getKeyName()];
} else {
$recordKey = (string) $record;
}
$record = $this->instance()->getTableRecord($recordKey);
$column->record($record);
}
if ($checkColumnUsing) {
Assert::assertTrue(
$checkColumnUsing($column),
"Failed asserting that a column with the name [{$name}] and provided configuration exists on the [{$livewireClass}] component."
);
}
return $this;
};
}
public function assertTableColumnDoesNotExist(): Closure
{
return function (string $name, ?Closure $checkColumnUsing = null, $record = null): static {
$column = $this->instance()->getTable()->getColumn($name);
$livewireClass = $this->instance()::class;
if (! $column) {
Assert::assertNull($column);
return $this;
}
if ($record) {
if ($record instanceof Model) {
$recordKey = (string) $record->getKey();
} elseif (is_array($record)) {
$recordKey = (string) $record[ArrayRecord::getKeyName()];
} else {
$recordKey = (string) $record;
}
$record = $this->instance()->getTableRecord($recordKey);
$column->record($record);
}
if ($checkColumnUsing) {
Assert::assertFalse(
$checkColumnUsing($column),
"Failed asserting that a column with the name [{$name}] and provided configuration does not exist on the [{$livewireClass}] component."
);
} else {
Assert::assertNotInstanceOf(
Column::class,
$column,
"Failed asserting that a table column with name [{$name}] does not exist on the [{$livewireClass}] component.",
);
}
return $this;
};
}
public function assertTableColumnVisible(): Closure
{
return function (string $name): static {
/** @phpstan-ignore-next-line */
$this->assertTableColumnExists($name);
$column = $this->instance()->getTable()->getColumn($name);
$livewireClass = $this->instance()::class;
Assert::assertFalse(
$column->isHidden(),
"Failed asserting that a table column with name [{$name}] is visible on the [{$livewireClass}] component.",
);
return $this;
};
}
public function assertTableColumnHidden(): Closure
{
return function (string $name): static {
/** @phpstan-ignore-next-line */
$this->assertTableColumnExists($name);
$column = $this->instance()->getTable()->getColumn($name);
$livewireClass = $this->instance()::class;
Assert::assertTrue(
$column->isHidden(),
"Failed asserting that a table column with name [{$name}] is hidden on the [{$livewireClass}] component.",
);
return $this;
};
}
public function assertTableColumnStateSet(): Closure
{
return function (string $name, $state, $record): static {
/** @phpstan-ignore-next-line */
$this->assertTableColumnExists($name);
$column = $this->instance()->getTable()->getColumn($name);
if ($record instanceof Model) {
$recordKey = (string) $record->getKey();
} elseif (is_array($record)) {
$recordKey = (string) $record[ArrayRecord::getKeyName()];
} else {
$recordKey = (string) $record;
}
/** @phpstan-ignore-next-line */
$this->assertTableRecordKeyExists($recordKey);
$record = $this->instance()->getTableRecord($recordKey);
$column->record($record);
$livewireClass = $this->instance()::class;
$column->clearCachedState();
$actualState = $column->getState();
if (is_array($actualState)) {
$actualState = json_encode($actualState);
}
if (is_array($state)) {
$state = json_encode($state);
}
$displayState = is_object($state) ? get_debug_type($state) : var_export($state, true);
Assert::assertEquals(
$state,
$actualState,
"Failed asserting that a table column with name [{$name}] has value of [{$displayState}] for record [{$recordKey}] on the [{$livewireClass}] component.",
);
return $this;
};
}
public function assertTableColumnStateNotSet(): Closure
{
return function (string $name, $state, $record): static {
/** @phpstan-ignore-next-line */
$this->assertTableColumnExists($name);
$column = $this->instance()->getTable()->getColumn($name);
if ($record instanceof Model) {
$recordKey = (string) $record->getKey();
} elseif (is_array($record)) {
$recordKey = (string) $record[ArrayRecord::getKeyName()];
} else {
$recordKey = (string) $record;
}
/** @phpstan-ignore-next-line */
$this->assertTableRecordKeyExists($recordKey);
$record = $this->instance()->getTableRecord($recordKey);
$column->record($record);
$livewireClass = $this->instance()::class;
$column->clearCachedState();
$actualState = $column->getState();
if (is_array($actualState)) {
$actualState = json_encode($actualState);
}
if (is_array($state)) {
$state = json_encode($state);
}
$displayState = is_object($state) ? get_debug_type($state) : var_export($state, true);
Assert::assertNotEquals(
$state,
$actualState,
"Failed asserting that a table column with name [{$name}] does not have a value of [{$displayState}] for record [{$recordKey}] on the [{$livewireClass}] component.",
);
return $this;
};
}
public function assertTableColumnFormattedStateSet(): Closure
{
return function (string $name, $state, $record): static {
/** @phpstan-ignore-next-line */
$this->assertTableColumnExists($name);
/** @var TextColumn $column */
$column = $this->instance()->getTable()->getColumn($name);
if ($record instanceof Model) {
$recordKey = (string) $record->getKey();
} elseif (is_array($record)) {
$recordKey = (string) $record[ArrayRecord::getKeyName()];
} else {
$recordKey = (string) $record;
}
/** @phpstan-ignore-next-line */
$this->assertTableRecordKeyExists($recordKey);
$record = $this->instance()->getTableRecord($recordKey);
$column->record($record);
$livewireClass = $this->instance()::class;
$column->clearCachedState();
Assert::assertEquals(
$state,
$column->formatState($column->getState()),
"Failed asserting that a table column with name [{$name}] has a formatted state of [{$state}] for record [{$recordKey}] on the [{$livewireClass}] component.",
);
return $this;
};
}
public function assertTableColumnFormattedStateNotSet(): Closure
{
return function (string $name, $state, $record): static {
/** @phpstan-ignore-next-line */
$this->assertTableColumnExists($name);
/** @var TextColumn $column */
$column = $this->instance()->getTable()->getColumn($name);
if ($record instanceof Model) {
$recordKey = (string) $record->getKey();
} elseif (is_array($record)) {
$recordKey = (string) $record[ArrayRecord::getKeyName()];
} else {
$recordKey = (string) $record;
}
/** @phpstan-ignore-next-line */
$this->assertTableRecordKeyExists($recordKey);
$record = $this->instance()->getTableRecord($recordKey);
$column->record($record);
$livewireClass = $this->instance()::class;
$column->clearCachedState();
Assert::assertNotEquals(
$state,
$column->formatState($column->getState()),
"Failed asserting that a table column with name [{$name}] does not have a formatted state of [{$state}] for record [{$recordKey}] on the [{$livewireClass}] component.",
);
return $this;
};
}
public function assertTableColumnHasExtraAttributes(): Closure
{
return function (string $name, array $attributes, $record) {
/** @phpstan-ignore-next-line */
$this->assertTableColumnExists($name);
$column = $this->instance()->getTable()->getColumn($name);
if ($record instanceof Model) {
$recordKey = (string) $record->getKey();
} elseif (is_array($record)) {
$recordKey = (string) $record[ArrayRecord::getKeyName()];
} else {
$recordKey = (string) $record;
}
/** @phpstan-ignore-next-line */
$this->assertTableRecordKeyExists($recordKey);
$record = $this->instance()->getTableRecord($recordKey);
$column->record($record);
$attributesString = print_r($attributes, true);
$livewireClass = $this->instance()::class;
Assert::assertEquals(
$attributes,
$column->getExtraAttributes(),
"Failed asserting that a table column with name [{$name}] has extra attributes [{$attributesString}] for record [{$recordKey}] on the [{$livewireClass}] component.",
);
return $this;
};
}
public function assertTableColumnDoesNotHaveExtraAttributes(): Closure
{
return function (string $name, array $attributes, $record) {
/** @phpstan-ignore-next-line */
$this->assertTableColumnExists($name);
$column = $this->instance()->getTable()->getColumn($name);
if ($record instanceof Model) {
$recordKey = (string) $record->getKey();
} elseif (is_array($record)) {
$recordKey = (string) $record[ArrayRecord::getKeyName()];
} else {
$recordKey = (string) $record;
}
/** @phpstan-ignore-next-line */
$this->assertTableRecordKeyExists($recordKey);
$record = $this->instance()->getTableRecord($recordKey);
$column->record($record);
$attributesString = print_r($attributes, true);
$livewireClass = $this->instance()::class;
Assert::assertNotEquals(
$attributes,
$column->getExtraAttributes(),
"Failed asserting that a table column with name [{$name}] does not have extra attributes [{$attributesString}] for record [{$recordKey}] on the [{$livewireClass}] component.",
);
return $this;
};
}
public function assertTableColumnHasDescription(): Closure
{
return function (string $name, $description, $record, string $position = 'below') {
/** @phpstan-ignore-next-line */
$this->assertTableColumnExists($name);
/** @var TextColumn $column */
$column = $this->instance()->getTable()->getColumn($name);
if ($record instanceof Model) {
$recordKey = (string) $record->getKey();
} elseif (is_array($record)) {
$recordKey = (string) $record[ArrayRecord::getKeyName()];
} else {
$recordKey = (string) $record;
}
/** @phpstan-ignore-next-line */
$this->assertTableRecordKeyExists($recordKey);
$record = $this->instance()->getTableRecord($recordKey);
$column->record($record);
$actualDescription = $position === 'above' ? $column->getDescriptionAbove() : $column->getDescriptionBelow();
$livewireClass = $this->instance()::class;
Assert::assertEquals(
$description,
$actualDescription,
"Failed asserting that a table column with name [{$name}] has description [{$description}] for record [{$recordKey}] on the [{$livewireClass}] component.",
);
return $this;
};
}
public function assertTableColumnDoesNotHaveDescription(): Closure
{
return function (string $name, $description, $record, string $position = 'below') {
/** @phpstan-ignore-next-line */
$this->assertTableColumnExists($name);
/** @var TextColumn $column */
$column = $this->instance()->getTable()->getColumn($name);
if ($record instanceof Model) {
$recordKey = (string) $record->getKey();
} elseif (is_array($record)) {
$recordKey = (string) $record[ArrayRecord::getKeyName()];
} else {
$recordKey = (string) $record;
}
/** @phpstan-ignore-next-line */
$this->assertTableRecordKeyExists($recordKey);
$record = $this->instance()->getTableRecord($recordKey);
$column->record($record);
$actualDescription = $position === 'above' ? $column->getDescriptionAbove() : $column->getDescriptionBelow();
$livewireClass = $this->instance()::class;
Assert::assertNotEquals(
$description,
$actualDescription,
"Failed asserting that a table column with name [{$name}] does not have description [{$description}] for record [{$recordKey}] on the [{$livewireClass}] component.",
);
return $this;
};
}
public function assertTableSelectColumnHasOptions(): Closure
{
return function (string $name, array $options, $record) {
/** @phpstan-ignore-next-line */
$this->assertTableColumnExists($name);
/** @var SelectColumn $column */
$column = $this->instance()->getTable()->getColumn($name);
if ($record instanceof Model) {
$recordKey = (string) $record->getKey();
} elseif (is_array($record)) {
$recordKey = (string) $record[ArrayRecord::getKeyName()];
} else {
$recordKey = (string) $record;
}
/** @phpstan-ignore-next-line */
$this->assertTableRecordKeyExists($recordKey);
$record = $this->instance()->getTableRecord($recordKey);
$column->record($record);
$optionsString = print_r($options, true);
$livewireClass = $this->instance()::class;
Assert::assertEquals(
$options,
$column->getOptions(),
"Failed asserting that a table column with name [{$name}] has options [{$optionsString}] for record [{$recordKey}] on the [{$livewireClass}] component.",
);
return $this;
};
}
public function assertTableSelectColumnDoesNotHaveOptions(): Closure
{
return function (string $name, array $options, $record) {
/** @phpstan-ignore-next-line */
$this->assertTableColumnExists($name);
/** @var SelectColumn $column */
$column = $this->instance()->getTable()->getColumn($name);
if ($record instanceof Model) {
$recordKey = (string) $record->getKey();
} elseif (is_array($record)) {
$recordKey = (string) $record[ArrayRecord::getKeyName()];
} else {
$recordKey = (string) $record;
}
/** @phpstan-ignore-next-line */
$this->assertTableRecordKeyExists($recordKey);
$record = $this->instance()->getTableRecord($recordKey);
$column->record($record);
$optionsString = print_r($options, true);
$livewireClass = $this->instance()::class;
Assert::assertNotEquals(
$options,
$column->getOptions(),
"Failed asserting that a table column with name [{$name}] does not have options [{$optionsString}] for record [{$recordKey}] on the [{$livewireClass}] component.",
);
return $this;
};
}
public function callTableColumnAction(): Closure
{
return function (string $name, $record = null): static {
/** @phpstan-ignore-next-line */
$this->assertTableColumnExists($name);
if ($record instanceof Model) {
$record = $this->instance()->getTableRecordKey($record);
}
$this->call('callTableColumnAction', $name, $record);
return $this;
};
}
public function sortTable(): Closure
{
return function (?string $name = null, ?string $direction = null): static {
$this->call('sortTable', $name, $direction);
return $this;
};
}
public function searchTable(): Closure
{
return function (?string $search = null): static {
$this->set('tableSearch', $search);
return $this;
};
}
public function searchTableColumns(): Closure
{
return function (array $searches): static {
$this->set('tableColumnSearches', $searches);
return $this;
};
}
public function toggleAllTableColumns(): Closure
{
return function (bool $condition = true): static {
/** @phpstan-ignore-next-line */
$tableColumns = $this->instance()->tableColumns;
foreach ($tableColumns as &$column) {
if (! $column['isToggleable']) {
continue;
}
$column['isToggled'] = $condition;
}
$this->set('tableColumns', $tableColumns);
$this->call('applyTableColumnManager');
return $this;
};
}
}

View file

@ -0,0 +1,153 @@
<?php
namespace Filament\Tables\Testing;
use BackedEnum;
use Closure;
use Filament\Tables\Contracts\HasTable;
use Filament\Tables\Filters\BaseFilter;
use Filament\Tables\Filters\SelectFilter;
use Filament\Tables\Filters\TernaryFilter;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
use Illuminate\Testing\Assert;
use Livewire\Component;
use Livewire\Features\SupportTesting\Testable;
/**
* @method Component&HasTable instance()
*
* @mixin Testable
*/
class TestsFilters
{
public function filterTable(): Closure
{
return function (string $name, $data = null): static {
$name = $this->instance()->parseTableFilterName($name);
/** @phpstan-ignore-next-line */
$this->assertTableFilterExists($name);
$filter = $this->instance()->getTable()->getFilter($name);
if ($filter instanceof TernaryFilter) {
if ($data === true || ($data === null && func_num_args() === 1)) {
$data = ['value' => true];
} else {
$data = ['value' => $data];
}
} elseif ($filter instanceof SelectFilter) {
if ($filter->isMultiple()) {
$data = ['values' => array_map(
fn ($data) => $data instanceof Model ? $data->getKey() : ($data instanceof BackedEnum ? $data->value : $data),
Arr::wrap($data ?? []),
)];
} else {
$data = ['value' => $data instanceof Model ? $data->getKey() : ($data instanceof BackedEnum ? $data->value : $data)];
}
} elseif (! is_array($data)) {
$data = ['isActive' => $data === true || $data === null];
}
$this->set("tableFilters.{$filter->getName()}", $data);
return $this;
};
}
public function resetTableFilters(): Closure
{
return function (): static {
$this->call('resetTableFiltersForm');
return $this;
};
}
public function removeTableFilter(): Closure
{
return function (string $filter, ?string $field = null): static {
$this->call('removeTableFilter', $this->instance()->parseTableFilterName($filter), $field);
return $this;
};
}
public function removeTableFilters(): Closure
{
return function (): static {
$this->call('removeTableFilters');
return $this;
};
}
public function assertTableFilterExists(): Closure
{
return function (string $name, ?Closure $checkFilterUsing = null): static {
$name = $this->instance()->parseTableFilterName($name);
$filter = $this->instance()->getTable()->getFilter($name);
$livewireClass = $this->instance()::class;
Assert::assertInstanceOf(
BaseFilter::class,
$filter,
"Failed asserting that a table filter with name [{$name}] exists on the [{$livewireClass}] component.",
);
if ($checkFilterUsing) {
Assert::assertTrue(
$checkFilterUsing($filter),
"Failed asserting that a table filter with name [{$name}] and provided configuration exists on the [{$livewireClass}] component.",
);
}
return $this;
};
}
public function assertTableFilterVisible(): Closure
{
return function (string $name): static {
$name = $this->instance()->parseTableFilterName($name);
$filter = $this->instance()->getTable()->getFilter(
name: $name,
withHidden: true,
);
$livewireClass = $this->instance()::class;
Assert::assertTrue(
$filter->isVisible(),
"Failed asserting that a table filter with name [{$name}] is visible on the [{$livewireClass}] component."
);
return $this;
};
}
public function assertTableFilterHidden(): Closure
{
return function (string $name): static {
$name = $this->instance()->parseTableFilterName($name);
$filter = $this->instance()->getTable()->getFilter(
name: $name,
withHidden: true,
);
$livewireClass = $this->instance()::class;
Assert::assertTrue(
$filter->isHidden(),
"Failed asserting that a table filter with name [{$name}] is hidden on the [{$livewireClass}] component."
);
return $this;
};
}
}

View file

@ -0,0 +1,87 @@
<?php
namespace Filament\Tables\Testing;
use Closure;
use Filament\Tables\Contracts\HasTable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
use Illuminate\Testing\Assert;
use Livewire\Component;
use Livewire\Features\SupportTesting\Testable;
/**
* @method Component&HasTable instance()
*
* @mixin Testable
*/
class TestsRecords
{
public function assertCanSeeTableRecords(): Closure
{
return function (array | Collection $records, bool $inOrder = false): static {
$html = array_map(
function ($record) {
if ($record instanceof Model) {
$record = $this->instance()->getTableRecordKey($record);
}
return "{$this->instance()->getId()}.table.records.{$record}";
},
$records instanceof Collection ? $records->all() : $records,
);
if ($inOrder) {
$this->assertSeeHtmlInOrder($html);
} else {
$this->assertSeeHtml($html);
}
return $this;
};
}
public function assertCanNotSeeTableRecords(): Closure
{
return function (array | Collection $records): static {
$html = array_map(
function ($record) {
if ($record instanceof Model) {
$record = $this->instance()->getTableRecordKey($record);
}
return "wire:key=\"{$this->instance()->getId()}.table.records.{$record}\"";
},
$records instanceof Collection ? $records->all() : $records,
);
$this->assertDontSeeHtml($html);
return $this;
};
}
public function assertCountTableRecords(): Closure
{
return function (int $count): static {
$livewireClass = $this->instance()::class;
Assert::assertSame(
$count,
$this->instance()->getAllTableRecordsCount(),
"Failed asserting that the [{$livewireClass}] table has [{$count}] records in total.",
);
return $this;
};
}
public function loadTable(): Closure
{
return function (): static {
$this->call('loadTable');
return $this;
};
}
}

View file

@ -0,0 +1,107 @@
<?php
namespace Filament\Tables\Testing;
use Closure;
use Filament\Tables\Columns\Summarizers\Summarizer;
use Filament\Tables\Contracts\HasTable;
use Illuminate\Testing\Assert;
use Livewire\Component;
use Livewire\Features\SupportTesting\Testable;
/**
* @method Component&HasTable instance()
*
* @mixin Testable
*/
class TestsSummaries
{
public function assertTableColumnSummarySet(): Closure
{
return function (string $columnName, string $summarizerId, $state, bool $isCurrentPaginationPageOnly = false): static {
/** @phpstan-ignore-next-line */
$this->assertTableColumnSummarizerExists($columnName, $summarizerId);
$normalizeState = fn ($state): string => strval(
is_numeric($state) ? round(floatval($state), 4) : $state,
);
$state = is_array($state) ? array_map($normalizeState, $state) : $normalizeState($state);
$summarizer = $this->instance()->getTable()->getColumn($columnName)->getSummarizer($summarizerId);
$query = $isCurrentPaginationPageOnly ?
$this->instance()->getPageTableSummaryQuery() :
$this->instance()->getAllTableSummaryQuery();
$actualState = $summarizer->query($query)->selectedState([])->getState();
$actualState = is_array($actualState) ? array_map($normalizeState, $actualState) : $normalizeState($actualState);
$livewireClass = $this->instance()::class;
Assert::assertEqualsCanonicalizing(
$state,
$actualState,
"Failed asserting that summarizer [$summarizerId], for column [{$columnName}], on the [{$livewireClass}] component, is set.",
);
return $this;
};
}
public function assertTableColumnSummaryNotSet(): Closure
{
return function (string $columnName, string $summarizerId, $state, bool $isCurrentPaginationPageOnly = false): static {
/** @phpstan-ignore-next-line */
$this->assertTableColumnSummarizerExists($columnName, $summarizerId);
$normalizeState = fn ($state): string => strval(
is_numeric($state) ? round(floatval($state), 4) : $state,
);
$state = is_array($state) ? array_map($normalizeState, $state) : $normalizeState($state);
$summarizer = $this->instance()->getTable()->getColumn($columnName)->getSummarizer($summarizerId);
$query = $isCurrentPaginationPageOnly ?
$this->instance()->getPageTableSummaryQuery() :
$this->instance()->getAllTableSummaryQuery();
$actualState = $summarizer->query($query)->getState();
$actualState = is_array($actualState) ? array_map($normalizeState, $actualState) : $normalizeState($actualState);
$livewireClass = $this->instance()::class;
Assert::assertNotEqualsCanonicalizing(
$state,
$actualState,
"Failed asserting that summarizer [$summarizerId], for column [{$columnName}], on the [{$livewireClass}] component, is not set.",
);
return $this;
};
}
public function assertTableColumnSummarizerExists(): Closure
{
return function (string $columnName, string $summarizerId): static {
$this->assertTableColumnExists($columnName);
$column = $this->instance()->getTable()->getColumn($columnName);
$summarizer = $column->getSummarizer($summarizerId);
$livewireClass = $this->instance()::class;
Assert::assertInstanceOf(
Summarizer::class,
$summarizer,
"Failed asserting that a table column with name [{$columnName}] has a summarizer with ID [{$summarizerId}] on the [{$livewireClass}] component. Please ensure that the ID is passed to the summarizer with [Summarizer::make('{$summarizerId}')].",
);
return $this;
};
}
}