-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathFieldTest.php
More file actions
67 lines (51 loc) · 1.75 KB
/
Copy pathFieldTest.php
File metadata and controls
67 lines (51 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
namespace SimpleSquid\Nova\Fields\Enum\Tests\Fields;
use BenSampo\Enum\Rules\EnumValue;
use Laravel\Nova\Http\Requests\NovaRequest;
use PHPUnit\Framework\Attributes\Test;
use SimpleSquid\Nova\Fields\Enum\Enum;
use SimpleSquid\Nova\Fields\Enum\Tests\Examples\IntegerEnum;
use SimpleSquid\Nova\Fields\Enum\Tests\TestCase;
class FieldTest extends TestCase
{
private $field;
protected function setUp(): void
{
parent::setUp();
$this->setUpDatabase($this->app);
$this->field = Enum::make('Enum')->attach(IntegerEnum::class);
}
#[Test]
public function it_starts_with_no_options_and_rules()
{
$field = Enum::make('Enum');
$this->assertArrayNotHasKey('options', $field->meta);
$this->assertEmpty($field->rules);
}
#[Test]
public function it_allows_an_enum_to_be_attached()
{
$this->assertIsObject($this->field);
$this->assertTrue(property_exists($this->field, 'optionsCallback'));
}
#[Test]
public function it_adds_correct_rules()
{
$this->assertContains('required', $this->field->rules);
$this->assertContainsEquals(new EnumValue(IntegerEnum::class, false), $this->field->rules);
}
#[Test]
public function it_displays_enum_options()
{
$this->assertCount(count(IntegerEnum::getValues()), $this->field->optionsCallback);
$this->assertSame(IntegerEnum::asSelectArray(), $this->field->optionsCallback);
}
#[Test]
public function it_can_be_nullable()
{
$this->field->nullable();
$this->assertNotContains('required', $this->field->rules);
$this->assertContains('nullable', $this->field->rules);
$this->assertFalse($this->field->isRequired(new NovaRequest));
}
}