Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add a test for multi-dimensional arrays
  • Loading branch information
stevebauman committed Nov 28, 2022
commit 7c58630bef90520b1473ce1be6c6b188d880221b
22 changes: 22 additions & 0 deletions tests/FilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,28 @@ public function __invoke(Builder $query, $value, string $property): Builder
expect($models->count())->toEqual(1);
});

it('should apply a filter with a multi-dimensional array value', function () {
TestModel::create(['name' => 'John Doe']);

$models = createQueryFromFilterRequest(['conditions' => [[
'attribute' => 'name',
'operator' => '=',
'value' => 'John Doe',
]]])
->allowedFilters(AllowedFilter::callback('conditions', function ($query, $conditions) {
foreach ($conditions as $condition) {
$query->where(
$condition['attribute'],
$condition['operator'],
$condition['value']
);
}
}))
->get();

expect($models->count())->toEqual(1);
});

it('can override the array value delimiter for single filters', function () {
TestModel::create(['name' => '>XZII/Q1On']);
TestModel::create(['name' => 'h4S4MG3(+>azv4z/I<o>']);
Expand Down