View on GitHub

NovaUnit

Unit testing suite for Laravel Nova, built to extend PHPUnit

Actions

Testing Actions

To create the testing object for a Nova Action, add the NovaActionTest trait to your class, and invoke the test method.

class TestClass extends TestCase
{
    use NovaActionTest;

    public function testNovaAction()
    {
        $action = $this->novaAction(MyAction::class);
    }
}

The following assertions can be run on the Nova Action:

Testing Action Handle

$response = $action->handle($fields, $models);

Invokes the handle method on the action with the given parameters.

assertMessage()

$response->assertMessage();

Assert that this action will return an Action::message() response with the given input

assertDanger()

$response->assertDanger();

Assert that this action will return an Action::danger() response with the given input

assertDeleted()

$response->assertDeleted();

Assert that this action will return an Action::deleted() response with the given input

assertRedirect()

$response->assertRedirect();

Assert that this action will return an Action::redirect() response with the given input

assertPush()

$response->assertPush();

Assert that this action will return an Action::push() response with the given input

assertOpenInNewTab()

$response->assertOpenInNewTab();

Assert that this action will return an Action::openInNewTab() response with the given input

assertDownload()

$response->assertDownload();

Assert that this action will return an Action::download() response with the given input

assertMessageContains($contents)

$response->assertMessageContains('Success');

Assert that the Action::message() response contains $contents

assertDangerContains($contents)

$response->assertDangerContains('Failure');

Assert that the Action::danger() response contains $contents

Testing Actions on Components

Action assertions can be run on the following Nova classes:

assertHasAction($action)

$component->assertHasAction(MyAction::class);

Asserts that the provided class path $action matches one of the actions returned by the actions() method

assertActionMissing($action)

$component->assertActionMissing(MyAction::class);

Asserts that the provided class path $action does not match any actions returned by the actions() method

assertHasNoAction()

$component->assertHasNoActions();

Asserts that the actions() method returns an empty array.

assertHasValidActions()

$component->assertHasValidActions();

Asserts that all actions returned by the actions() method are valid Nova Actions.

Testing Actions Individually

$action = $component->action(MyAction::class);

Searches the actions() method on the component for the first occurance of an action matching the provided class name, and returns a testing object.

assertShownOnIndex()

$action->assertShownOnIndex();

Asserts that the action will be shown on this component’s index view.

assertHiddenFromIndex()

$action->assertHiddenFromIndex();

Asserts that the action will be hidden from this component’s index view.

assertShownOnDetail()

$action->assertShownOnDetail();

Asserts that the action will be shown on this component’s detail view.

assertHiddenFromDetail()

$action->assertHiddenFromDetail();

Asserts that the action will be hidden from this component’s detail view.

assertShownInline()

$action->assertShownInline();

Asserts that the action will be shown on this component’s table row view.

assertNotShownInline()

$action->assertNotShownInline();

Asserts that the action will be hidden from this component’s table row view.