Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
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
Prev Previous commit
Next Next commit
[Form] BirthdayType add tests
  • Loading branch information
guillaumeVDP committed Nov 14, 2024
commit 6c3676ab0f18a3b4b3cd2db5f10eb3a783aa2af5
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,43 @@ class BirthdayTypeTest extends DateTypeTest
{
public const TESTED_TYPE = BirthdayType::class;

public function testSetInvalidYearsOption()
public function testSetInvalidYearsOption(): void
{
$this->expectException(InvalidOptionsException::class);
$this->factory->create(static::TESTED_TYPE, null, [
'years' => 'bad value',
'widget' => 'choice',
]);
}

public function testWidgetSingleTextHasDefaultAttrMinMax(): void
{
$currentMonth = date('m');
$currentDay = date('d');
$form = $this->factory->create(static::TESTED_TYPE, null, [
'widget' => 'single_text',
]);
$formView = $form->createView();
$options = $form->getConfig()->getOptions();
$expectedMin = sprintf('%d-%s-%s', reset($options['years']), $currentMonth, $currentDay);
$expectedMax = sprintf('%d-%s-%s', end($options['years']), $currentMonth, $currentDay);
$this->assertEquals($expectedMin, $formView->vars['attr']['min']);
$this->assertEquals($expectedMax, $formView->vars['attr']['max']);
}

public function testWidgetSingleTextDoesntRemoveUserAttr(): void
{
$expectedMin = date('Y-m-d', strtotime('10 years ago'));
$expectedMax = date('Y-m-d', strtotime('1 years ago'));
$form = $this->factory->create(static::TESTED_TYPE, null, [
'widget' => 'single_text',
'attr' => [
'min' => $expectedMin,
'max' => $expectedMax
]
]);
$formView = $form->createView();
$this->assertEquals($expectedMin, $formView->vars['attr']['min']);
$this->assertEquals($expectedMax, $formView->vars['attr']['max']);
}
}
Loading