TabletopDOCS
API Reference

Testing

The testing API: tbtop(Page::class, $params) (or $this->tbtop() with the InteractsWithTbtop trait) visits a page through its real endpoints and asserts on the wire. Guide in testing.md.

The testing API: tbtop(Page::class, $params) (or $this->tbtop() with the InteractsWithTbtop trait) visits a page through its real endpoints and asserts on the wire. Guide in testing.md.

PageTester

Tbtop\Admin\Testing\PageTester

MethodWhat it does
assertActionHidden(string $name): selfThe action is off the wire (authorize(), when()) or hidden().
assertActionVisible(string $name): selfThe action is on the wire — authorize() and when() kept it — and not hidden().
assertFieldDisabled(string $name): selfThe field is on the wire with disabled() set.
assertFieldEnabled(string $name): selfThe field is on the wire without disabled().
assertFieldHidden(string $name): selfThe field is off the wire (when(), authorize()) or hidden().
assertFieldValue(string $name, mixed $value): selfThe value the field is prefilled with, from its form's record. Dotted names reach into arrays.
assertFieldVisible(string $name): selfThe field is on the wire — when() and authorize() kept it — and not hidden().
assertForbidden(): self403 from the page gate (can()).
assertOk(): selfThe page rendered: 200.
assertStatus(int $status): selfThe page visit answered this HTTP status.
assertTitle(string $title): selfThe page's title() as the header shows it.
callAction(string $name, array $form = [], Model|array|null $row = null, iterable $selection = []): ResultRun an action the way a click does. A server action posts to its endpoint; a modal action opens, takes $form and submits through its one form action; a submit action submits its form.
fill(array $data): FormTesterFill the page's only form: form()->fill($data).
form(?string $name = null): FormTesterA form on the page, outside any modal. The name may be left out when there is only one.
openAction(string $name, Model|array|null $row = null, iterable $selection = []): ModalTesterOpen a modal action without submitting it: its query() runs, and its form can be checked, filled and submitted.
response(): TestResponseThe page visit's raw response, for a check the tester does not cover.
table(?string $name = null): TableTesterA table on the page. The name may be left out when there is only one.
url(?string $endpoint = null, ?string $name = null): stringThe page's URL, or one of its endpoints for the ones the tester does not wrap yet: url('table', 'posts'), url('liveRegion', 'preview').

FormTester

Tbtop\Admin\Testing\FormTester

MethodWhat it does
callAction(string $name): ResultRun an action inside this form with the filled values, the way a footer button sends them.
fill(array $data): selfSet field values over the prefilled record. Dotted keys reach into repeaters and nested arrays; an unknown field fails.
submit(): ResultPost the form to its submit handler.

ModalTester

Tbtop\Admin\Testing\ModalTester

MethodWhat it does
assertForbidden(): selfThe query() was refused: 403 from the page gate or an authorize() check.
assertFormData(array $expected): selfThe modal opens with these values — a subset of its query() data, or of its form's default record.
callAction(string $name): ResultRun one of the modal's own actions — Cancel, a second submit — with its current values.
fill(array $data): selfSet form values over what the modal opened with.
response(): ?TestResponseThe query() response, when the modal has one.
submit(): ResultSubmit through the modal's one action that takes the form.

TableTester

Tbtop\Admin\Testing\TableTester

MethodWhat it does
assertCanNotSeeRecords(Traversable|Model|array|string|int $records): selfNone of these records are on the current page of rows.
assertCanSeeRecords(Traversable|Model|array|string|int $records, bool $inOrder = false): selfThese records are on the current page of rows — in this order with $inOrder.
assertCell(mixed $record, string $column, mixed $value): selfOne cell as the server formatted it for the client.
assertColumnHidden(string $name): selfThe column is off the wire: hidden(), visible() or never declared.
assertColumnVisible(string $name): selfThe column ships to the client: declared, and kept by when() and visibility checks.
assertCountRecords(int $count): selfRows on the current page.
assertForbidden(): selfThe table endpoint refused the fetch: 403 from the page gate.
assertTabCount(string $tab, int $count): selfA count-enabled tab's badge number.
assertTotal(int $total): selfThe total across all pages. A simplePagination() table has none: use assertCountRecords().
callAction(string $name, array $form = []): ResultRun one of the table's header actions.
callBulkAction(string $name, Traversable|Model|array|string|int $records, array $form = []): ResultRun a bulk action on the selected records.
callRowAction(string $name, mixed $record, array $form = []): ResultRun a row action on a record, sending its row as the table shows it. The record must be on the current page.
filter(string $name, mixed $value): selfSet a declared filter, as the filter bar or modal would.
openRowAction(string $name, mixed $record): ModalTesterOpen a row's modal action: its query() runs with that row.
page(int $page): selfGo to a page of rows.
perPage(int $perPage): selfPick a page size; the server falls back to the default for one the table does not offer.
response(): TestResponseThe last table fetch's raw response.
rows(): arrayThe current page of rows, as the client receives them.
search(string $text): selfTable-wide search over the searchable columns.
searchColumn(string $column, string $text): selfOne column's own search box.
sort(string $column, string $direction = 'asc'): selfSort by a visible column, as a header click does.
tab(string $name): selfSwitch to a declared filter tab.

Result

Tbtop\Admin\Testing\Result

MethodWhat it does
assertEffect(string $kind, array $fields = []): selfAn effect of this kind arrived, its fields including $fields.
assertForbidden(): self403 from the page gate or an authorize() check.
assertHalted(?string $message = null): selfThe modal stayed open with a message — haltModal.
assertHasErrors(array|string $keys = []): selfValidation failed for these fields. A list names fields; a map also checks the failure — a rule ('required', 'max:200') matched by the message it renders, or the message itself.
assertHasNoErrors(array|string $keys = []): selfValidation passed — or, given field names, none of these fields failed. A 403, 404 or 5xx fails it.
assertModalClosed(): selfA closeModal effect: the modal the call came from closes.
assertNoEffects(?string $kind = null): selfNo effect of this kind arrived — or, without a kind, no effect at all.
assertNotified(string $message, ?string $level = null): selfA toast with this message, at this level when given.
assertOk(): selfThe call went through: a 2xx, or a form's way back with no validation errors. Any other redirect (a login page, a handler's URL) is not ok; assert a handler's redirect with assertRedirect().
assertRedirect(?string $url = null): selfThe client is sent elsewhere: a redirect effect or an HTTP redirect other than the form's own way back. Without $url, any destination.
assertStatus(int $status): selfThe call answered this HTTP status — 422 for an action's validation failure.
assertTableRefreshed(?string $table = null): selfA refreshTable effect — for this table when named, else any.
effects(): arrayThe effects that arrived, in order.
errors(): arrayValidation messages per field.
response(): TestResponseThe raw response, for a check the tester does not cover.

On this page