-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from Rasalas/v2.x
Add support for nested fields in form validation resolves #8
- Loading branch information
Showing
3 changed files
with
81 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Leaf\Form; | ||
|
||
test('getDotNotatedValue retrieves simple field', function () { | ||
$array = ['name' => 'Max']; | ||
expect(Form::getDotNotatedValue($array, 'name'))->toBe('Max'); | ||
}); | ||
|
||
test('getDotNotatedValue returns null for non-existent field', function () { | ||
$array = ['name' => 'Max']; | ||
expect(Form::getDotNotatedValue($array, 'age'))->toBeNull(); | ||
}); | ||
|
||
test('getDotNotatedValue retrieves nested field', function () { | ||
$nestedArray = [ | ||
'customer' => [ | ||
'phone' => '123456789', | ||
'name' => 'Anna' | ||
], | ||
'order' => [ | ||
'id' => 1 | ||
] | ||
]; | ||
expect(Form::getDotNotatedValue($nestedArray, 'customer.phone'))->toBe('123456789'); | ||
expect(Form::getDotNotatedValue($nestedArray, 'customer.name'))->toBe('Anna'); | ||
expect(Form::getDotNotatedValue($nestedArray, 'order.id'))->toBe(1); | ||
}); | ||
|
||
test('getDotNotatedValue retrieves deeply nested field', function () { | ||
$deepNestedArray = [ | ||
'customer' => [ | ||
'details' => [ | ||
'address' => [ | ||
'city' => 'Berlin' | ||
] | ||
] | ||
] | ||
]; | ||
expect(Form::getDotNotatedValue($deepNestedArray, 'customer.details.address.city'))->toBe('Berlin'); | ||
}); | ||
|
||
test('getDotNotatedValue returns null for non-existent nested field', function () { | ||
$deepNestedArray = [ | ||
'customer' => [ | ||
'details' => [ | ||
'address' => [ | ||
'city' => 'Berlin' | ||
] | ||
] | ||
] | ||
]; | ||
expect(Form::getDotNotatedValue($deepNestedArray, 'customer.details.phone'))->toBeNull(); | ||
}); |