forked from area17/twill
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
69 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
namespace A17\Twill\Tests\Unit\Services\Forms; | ||
|
||
use A17\Twill\Services\Forms\Option; | ||
use A17\Twill\Services\Forms\Options; | ||
use A17\Twill\Tests\Unit\TestCase; | ||
|
||
class OptionsTest extends TestCase | ||
{ | ||
public static function inputs(): array | ||
{ | ||
return [ | ||
'array of objects' => [ | ||
[ | ||
Option::make('foo', 'Foo label'), | ||
Option::make('bar', 'Bar label', false), | ||
], | ||
false, | ||
], | ||
|
||
'array of key-value pairs' => [ | ||
[ | ||
'foo' => 'Foo label', | ||
'bar' => 'Bar label', | ||
], | ||
true, | ||
], | ||
|
||
'array of arrays' => [ | ||
[ | ||
[ | ||
'value' => 'foo', | ||
'label' => 'Foo label', | ||
], | ||
[ | ||
'value' => 'bar', | ||
'label' => 'Bar label', | ||
'selectable' => false, | ||
], | ||
], | ||
false, | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider inputs | ||
*/ | ||
public function testFromArray(array $options, bool $barShouldBeSelectable): void | ||
{ | ||
$options = Options::fromArray($options); | ||
|
||
$this->assertEquals([ | ||
[ | ||
'value' => 'foo', | ||
'label' => 'Foo label', | ||
'selectable' => true, | ||
], | ||
[ | ||
'value' => 'bar', | ||
'label' => 'Bar label', | ||
'selectable' => $barShouldBeSelectable, | ||
], | ||
], $options->toArray()); | ||
} | ||
} |