View on GitHub

NovaUnit

Unit testing suite for Laravel Nova, built to extend PHPUnit

Fields

Testing Fields on Components

Field assertions can be run on the following Nova classes:

assertHasField($field)

$component->assertHasField('field_name');

Asserts that the provided string matches the name or attribute of one of the fields returned by the fields() method

assertFieldMissing($field)

$component->assertFieldMissing('field_name');

Asserts that the provided string does not match the name or attribute of one of the fields returned by the fields() method

assertHasNoFields()

$component->assertHasNoFields();

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

assertHasValidFields()

$component->assertHasValidFields();

Asserts that all fields returned by the fields() method are valid. Examples of valid fields include:

Testing Fields Individually

To test configuration of a component’s individual fields, you may use the field($fieldName) method:

$field = $component->field('field_name');

Searches the components fields() array for a field with a name or attribute matching $fieldname, and returns first occurrence in a testing class.

assertHasRule($rule)

$field->assertHasRule('required');

Asserts that the following rule is being applied to the value of this field. This assertion only works on string-type rules, not closures.

assertRuleMissing($rule)

$field->assertRuleMissing('required');

Asserts that the following rule is not being applied to the value of this field. This assertion only works on string-type rules, not closures.

assertHasCreationRule($rule)

$field->assertHasCreationRule('required');

Asserts that the following rule is being applied to the value of this field when a resource is created. This assertion only works on string-type rules, not closures.

assertCreationRuleMissing($rule)

$field->assertCreationRuleMissing('required');

Asserts that the following rule is not being applied to the value of this field when a resource is created. This assertion only works on string-type rules, not closures.

assertHasUpdateRule($rule)

$field->assertHasUpdateRule('required');

Asserts that the following rule is being applied to the value of this field when a resource is updated. This assertion only works on string-type rules, not closures.

assertUpdateRuleMissing($rule)

$field->assertUpdateRuleMissing('required');

Asserts that the following rule is not being applied to the value of this field when a resource is updated. This assertion only works on string-type rules, not closures.

assertShownOnIndex()

$field->assertShownOnIndex();

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

assertHiddenFromIndex()

$field->assertHiddenFromIndex();

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

assertShownOnDetail()

$field->assertShownOnDetail();

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

assertHiddenFromDetail()

$field->assertHiddenFromDetail();

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

assertNullable()

$field->assertNullable();

Asserts that the value of this field will be set to null if left empty.

assertNotNullable()

$field->assertNotNullable();

Asserts that the value of this field will not be set to null if left empty.

assertSortable()

$field->assertSortable();

Asserts that the component’s records can be sorted by this field.

assertNotSortable()

$field->assertNotSortable();

Asserts that the component’s records cannot be sorted by this field.