File tree 4 files changed +32
-6
lines changed
4 files changed +32
-6
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ public function getPillDataForFilter(): array
11
11
$ filters = [];
12
12
13
13
foreach ($ this ->getAppliedFiltersWithValuesForPills () as $ filterKey => $ value ) {
14
- if (! is_null ($ filter = $ this ->getFilterByKey ($ filterKey ))) {
14
+ if (! is_null ($ filter = $ this ->getFilterByKey ($ filterKey )) && ! $ filter -> isEmpty ( $ filter -> validate ( $ value )) ) {
15
15
$ filters [$ filter ->getKey ()] = FilterPillData::make (
16
16
filterKey: $ filter ->getKey (),
17
17
customPillBlade: $ filter ->getCustomPillBlade () ?? null ,
Original file line number Diff line number Diff line change @@ -49,11 +49,13 @@ public function getAppliedFiltersWithValuesForPills(): array
49
49
}
50
50
51
51
$ validatedValue = $ filter ->validate ($ item );
52
+
52
53
if ($ filter instanceof BooleanFilter) {
53
54
return ! ($ filter ->isEmpty ($ validatedValue ));
54
- } elseif ($ validatedValue === null || $ validatedValue === 'null ' ) {
55
+ } elseif ($ validatedValue === null || $ validatedValue === 'null ' || $ filter -> isEmpty ( $ validatedValue ) ) {
55
56
return false ;
56
57
} elseif (is_array ($ validatedValue )) {
58
+ $ filter ->isEmpty ($ validatedValue );
57
59
if (array_key_exists (0 , $ validatedValue ) && (is_null ($ validatedValue [0 ]) || $ validatedValue [0 ] == 'null ' )) {
58
60
return false ;
59
61
}
Original file line number Diff line number Diff line change @@ -40,12 +40,10 @@ public function validate(array|string|null $values): array|bool
40
40
return false ;
41
41
}
42
42
43
- $ startDate = $ this ->createCarbonDate ($ returnedValues ['minDate ' ]);
44
- $ endDate = $ this ->createCarbonDate ($ returnedValues ['maxDate ' ]);
45
-
46
- if (! ($ startDate instanceof Carbon) || ! ($ endDate instanceof Carbon)) {
43
+ if (! (($ startDate = $ this ->createCarbonDate ($ returnedValues ['minDate ' ])) instanceof Carbon) || ! (($ endDate = $ this ->createCarbonDate ($ returnedValues ['maxDate ' ])) instanceof Carbon)) {
47
44
return false ;
48
45
}
46
+
49
47
if ($ startDate ->gt ($ endDate )) {
50
48
return false ;
51
49
}
@@ -198,6 +196,9 @@ public function getFilterPillValue($value): array|string|bool|null
198
196
199
197
public function isEmpty (array |string |null $ value ): bool
200
198
{
199
+ if (is_null ($ value ) || empty ($ value )) {
200
+ return true ;
201
+ }
201
202
$ values = [];
202
203
if (is_array ($ value )) {
203
204
if (! isset ($ value ['minDate ' ]) || ! isset ($ value ['maxDate ' ])) {
Original file line number Diff line number Diff line change @@ -435,4 +435,27 @@ public function test_check_if_can_get_locale(): void
435
435
$ this ->assertSame ('de ' , self ::$ filterInstance ->getPillsLocale ());
436
436
$ this ->assertTrue (self ::$ filterInstance ->hasPillsLocale ());
437
437
}
438
+
439
+ public function test_can_check_validation_rejects_invalid_values_array (): void
440
+ {
441
+ $ missingStartDate = self ::$ filterInstance ->validate ([null , '2020-01-01 ' ]);
442
+ $ missingEndDate = self ::$ filterInstance ->validate (['2020-01-01 ' , null ]);
443
+ $ missingBoth = self ::$ filterInstance ->validate ([null , null ]);
444
+
445
+ $ this ->assertFalse ($ missingStartDate );
446
+ $ this ->assertFalse ($ missingEndDate );
447
+ $ this ->assertFalse ($ missingBoth );
448
+ $ this ->assertTrue (self ::$ filterInstance ->isEmpty ($ missingStartDate ));
449
+ $ this ->assertTrue (self ::$ filterInstance ->isEmpty ($ missingEndDate ));
450
+ $ this ->assertTrue (self ::$ filterInstance ->isEmpty ($ missingBoth ));
451
+ }
452
+
453
+ public function test_can_check_validation_rejects_broken_values_array (): void
454
+ {
455
+ $ this ->assertFalse (self ::$ filterInstance ->validate (['minDate ' => 'asdf ' , 'maxDate ' => '2020-02-02 ' ]));
456
+ $ this ->assertFalse (self ::$ filterInstance ->validate (['minDate ' => '4121-31-31 ' , 'maxDate ' => '2020-02-02 ' ]));
457
+ $ this ->assertFalse (self ::$ filterInstance ->validate (['minDate ' => '2020-02-02 ' , 'maxDate ' => 'asdf ' ]));
458
+ $ this ->assertFalse (self ::$ filterInstance ->validate (['minDate ' => '2020-02-02 ' , 'maxDate ' => '4121-31-31 ' ]));
459
+
460
+ }
438
461
}
You can’t perform that action at this time.
0 commit comments