1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace JoshGaber\NovaUnit\Fields; |
4
|
|
|
|
5
|
|
|
use Laravel\Nova\Fields\Field; |
6
|
|
|
use PHPUnit\Framework\Assert as PHPUnit; |
7
|
|
|
|
8
|
|
|
class MockFieldElement |
9
|
|
|
{ |
10
|
|
|
private $field; |
11
|
|
|
private $request; |
|
|
|
|
12
|
|
|
|
13
|
29 |
|
public function __construct(Field $field) |
14
|
|
|
{ |
15
|
29 |
|
$this->field = $field; |
16
|
29 |
|
} |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Assert that the following rule can be found on the. |
20
|
|
|
* |
21
|
|
|
* @param string $rule |
22
|
|
|
* @param string $message |
23
|
|
|
* @return $this |
24
|
|
|
*/ |
25
|
2 |
|
public function assertHasRule(string $rule, string $message = ''): self |
26
|
|
|
{ |
27
|
2 |
|
PHPUnit::assertContains($rule, $this->field->rules, $message); |
28
|
|
|
|
29
|
1 |
|
return $this; |
30
|
|
|
} |
31
|
|
|
|
32
|
2 |
|
public function assertRuleMissing(string $rule, string $message = ''): self |
33
|
|
|
{ |
34
|
2 |
|
PHPUnit::assertNotContains($rule, $this->field->rules, $message); |
35
|
|
|
|
36
|
1 |
|
return $this; |
37
|
|
|
} |
38
|
|
|
|
39
|
2 |
|
public function assertShownOnIndex(string $message = '') |
40
|
|
|
{ |
41
|
2 |
|
$test = $this->field->showOnIndex; |
42
|
2 |
|
PHPUnit::assertTrue( |
43
|
2 |
|
is_callable($test) ? $test() : $test, |
44
|
2 |
|
$message |
45
|
|
|
); |
46
|
1 |
|
} |
47
|
|
|
|
48
|
2 |
|
public function assertHiddenFromIndex(string $message = '') |
49
|
|
|
{ |
50
|
2 |
|
$test = $this->field->showOnIndex; |
51
|
2 |
|
PHPUnit::assertFalse( |
52
|
2 |
|
is_callable($test) ? $test() : $test, |
53
|
2 |
|
$message |
54
|
|
|
); |
55
|
1 |
|
} |
56
|
|
|
|
57
|
2 |
|
public function assertShownOnDetail(string $message = '') |
58
|
|
|
{ |
59
|
2 |
|
$test = $this->field->showOnDetail; |
60
|
2 |
|
PHPUnit::assertTrue( |
61
|
2 |
|
is_callable($test) ? $test() : $test, |
62
|
2 |
|
$message |
63
|
|
|
); |
64
|
1 |
|
} |
65
|
|
|
|
66
|
2 |
|
public function assertHiddenFromDetail(string $message = '') |
67
|
|
|
{ |
68
|
2 |
|
$test = $this->field->showOnDetail; |
69
|
2 |
|
PHPUnit::assertFalse( |
70
|
2 |
|
is_callable($test) ? $test() : $test, |
71
|
2 |
|
$message |
72
|
|
|
); |
73
|
1 |
|
} |
74
|
|
|
|
75
|
2 |
|
public function assertShownWhenCreating(string $message = '') |
76
|
|
|
{ |
77
|
2 |
|
$test = $this->field->showOnCreation; |
78
|
2 |
|
PHPUnit::assertTrue( |
79
|
2 |
|
is_callable($test) ? $test() : $test, |
80
|
2 |
|
$message |
81
|
|
|
); |
82
|
1 |
|
} |
83
|
|
|
|
84
|
2 |
|
public function assertHiddenWhenCreating(string $message = '') |
85
|
|
|
{ |
86
|
2 |
|
$test = $this->field->showOnCreation; |
87
|
2 |
|
PHPUnit::assertFalse( |
88
|
2 |
|
is_callable($test) ? $test() : $test, |
89
|
2 |
|
$message |
90
|
|
|
); |
91
|
1 |
|
} |
92
|
|
|
|
93
|
2 |
|
public function assertShownWhenUpdating(string $message = '') |
94
|
|
|
{ |
95
|
2 |
|
$test = $this->field->showOnUpdate; |
96
|
2 |
|
PHPUnit::assertTrue( |
97
|
2 |
|
is_callable($test) ? $test() : $test, |
98
|
2 |
|
$message |
99
|
|
|
); |
100
|
1 |
|
} |
101
|
|
|
|
102
|
2 |
|
public function assertHiddenWhenUpdating(string $message = '') |
103
|
|
|
{ |
104
|
2 |
|
$test = $this->field->showOnUpdate; |
105
|
2 |
|
PHPUnit::assertFalse( |
106
|
2 |
|
is_callable($test) ? $test() : $test, |
107
|
2 |
|
$message |
108
|
|
|
); |
109
|
1 |
|
} |
110
|
|
|
|
111
|
2 |
|
public function assertNullable(string $message = '') |
112
|
|
|
{ |
113
|
2 |
|
PHPUnit::assertTrue($this->field->nullable, $message); |
114
|
1 |
|
} |
115
|
|
|
|
116
|
2 |
|
public function assertNotNullable(string $message = '') |
117
|
|
|
{ |
118
|
2 |
|
PHPUnit::assertFalse($this->field->nullable, $message); |
119
|
1 |
|
} |
120
|
|
|
|
121
|
2 |
|
public function assertSortable(string $message = '') |
122
|
|
|
{ |
123
|
2 |
|
PHPUnit::assertTrue($this->field->sortable, $message); |
124
|
1 |
|
} |
125
|
|
|
|
126
|
2 |
|
public function assertNotSortable(string $message = '') |
127
|
|
|
{ |
128
|
2 |
|
PHPUnit::assertFalse($this->field->sortable, $message); |
129
|
1 |
|
} |
130
|
|
|
} |
131
|
|
|
|