Skip to content

Commit 42458a5

Browse files
committed
[Form][Type Date/Time][choice_translation_domain] added tests.
1 parent 8e765ea commit 42458a5

File tree

6 files changed

+131
-2
lines changed

6 files changed

+131
-2
lines changed

src/Symfony/Component/Form/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CHANGELOG
44
2.8.0
55
-----
66

7+
* added option "choice_translation_domain" to DateType, TimeType and DateTimeType.
78
* deprecated option "read_only" in favor of "attr['readonly']"
89
* added the html5 "range" FormType
910
* deprecated the "cascade_validation" option in favor of setting "constraints"

src/Symfony/Component/Form/Extension/Core/Type/DateType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public function configureOptions(OptionsResolver $resolver)
212212
if (is_array($choiceTranslationDomain)) {
213213
$default = false;
214214

215-
return array_merge(
215+
return array_replace(
216216
array('year' => $default, 'month' => $default, 'day' => $default),
217217
$choiceTranslationDomain
218218
);

src/Symfony/Component/Form/Extension/Core/Type/TimeType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public function configureOptions(OptionsResolver $resolver)
201201
if (is_array($choiceTranslationDomain)) {
202202
$default = false;
203203

204-
return array_merge(
204+
return array_replace(
205205
array('hour' => $default, 'minute' => $default, 'second' => $default),
206206
$choiceTranslationDomain
207207
);

src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTimeTypeTest.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,4 +519,57 @@ public function testTimeTypeSingleTextErrorsBubbleUp()
519519
$this->assertSame(array(), iterator_to_array($form['time']->getErrors()));
520520
$this->assertSame(array($error), iterator_to_array($form->getErrors()));
521521
}
522+
523+
public function testPassDefaultChoiceTranslationDomain()
524+
{
525+
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
526+
'with_seconds' => true,
527+
));
528+
529+
$view = $form->createView();
530+
531+
$this->assertFalse($view['date']['year']->vars['choice_translation_domain']);
532+
$this->assertFalse($view['date']['month']->vars['choice_translation_domain']);
533+
$this->assertFalse($view['date']['day']->vars['choice_translation_domain']);
534+
$this->assertFalse($view['time']['hour']->vars['choice_translation_domain']);
535+
$this->assertFalse($view['time']['minute']->vars['choice_translation_domain']);
536+
$this->assertFalse($view['time']['second']->vars['choice_translation_domain']);
537+
}
538+
539+
public function testPassChoiceTranslationDomainAsString()
540+
{
541+
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
542+
'choice_translation_domain' => 'messages',
543+
'with_seconds' => true,
544+
));
545+
546+
$view = $form->createView();
547+
$this->assertSame('messages', $view['date']['year']->vars['choice_translation_domain']);
548+
$this->assertSame('messages', $view['date']['month']->vars['choice_translation_domain']);
549+
$this->assertSame('messages', $view['date']['day']->vars['choice_translation_domain']);
550+
$this->assertSame('messages', $view['time']['hour']->vars['choice_translation_domain']);
551+
$this->assertSame('messages', $view['time']['minute']->vars['choice_translation_domain']);
552+
$this->assertSame('messages', $view['time']['second']->vars['choice_translation_domain']);
553+
}
554+
555+
public function testPassChoiceTranslationDomainAsArray()
556+
{
557+
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
558+
'choice_translation_domain' => array(
559+
'year' => 'foo',
560+
'month' => 'test',
561+
'hour' => 'foo',
562+
'second' => 'test',
563+
),
564+
'with_seconds' => true,
565+
));
566+
567+
$view = $form->createView();
568+
$this->assertSame('foo', $view['date']['year']->vars['choice_translation_domain']);
569+
$this->assertSame('test', $view['date']['month']->vars['choice_translation_domain']);
570+
$this->assertFalse($view['date']['day']->vars['choice_translation_domain']);
571+
$this->assertSame('foo', $view['time']['hour']->vars['choice_translation_domain']);
572+
$this->assertFalse($view['time']['minute']->vars['choice_translation_domain']);
573+
$this->assertSame('test', $view['time']['second']->vars['choice_translation_domain']);
574+
}
522575
}

src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -950,4 +950,41 @@ public function testYearsFor32BitsMachines()
950950

951951
$this->assertEquals($listChoices, $view['year']->vars['choices']);
952952
}
953+
954+
public function testPassDefaultChoiceTranslationDomain()
955+
{
956+
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType');
957+
958+
$view = $form->createView();
959+
$this->assertFalse($view['year']->vars['choice_translation_domain']);
960+
$this->assertFalse($view['month']->vars['choice_translation_domain']);
961+
$this->assertFalse($view['day']->vars['choice_translation_domain']);
962+
}
963+
964+
public function testPassChoiceTranslationDomainAsString()
965+
{
966+
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
967+
'choice_translation_domain' => 'messages',
968+
));
969+
970+
$view = $form->createView();
971+
$this->assertSame('messages', $view['year']->vars['choice_translation_domain']);
972+
$this->assertSame('messages', $view['month']->vars['choice_translation_domain']);
973+
$this->assertSame('messages', $view['day']->vars['choice_translation_domain']);
974+
}
975+
976+
public function testPassChoiceTranslationDomainAsArray()
977+
{
978+
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
979+
'choice_translation_domain' => array(
980+
'year' => 'foo',
981+
'day' => 'test',
982+
),
983+
));
984+
985+
$view = $form->createView();
986+
$this->assertSame('foo', $view['year']->vars['choice_translation_domain']);
987+
$this->assertFalse($view['month']->vars['choice_translation_domain']);
988+
$this->assertSame('test', $view['day']->vars['choice_translation_domain']);
989+
}
953990
}

src/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,4 +736,42 @@ public function testThrowExceptionIfSecondsIsInvalid()
736736
'seconds' => 'bad value',
737737
));
738738
}
739+
740+
public function testPassDefaultChoiceTranslationDomain()
741+
{
742+
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType');
743+
744+
$view = $form->createView();
745+
$this->assertFalse($view['hour']->vars['choice_translation_domain']);
746+
$this->assertFalse($view['minute']->vars['choice_translation_domain']);
747+
}
748+
749+
public function testPassChoiceTranslationDomainAsString()
750+
{
751+
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
752+
'choice_translation_domain' => 'messages',
753+
'with_seconds' => true,
754+
));
755+
756+
$view = $form->createView();
757+
$this->assertSame('messages', $view['hour']->vars['choice_translation_domain']);
758+
$this->assertSame('messages', $view['minute']->vars['choice_translation_domain']);
759+
$this->assertSame('messages', $view['second']->vars['choice_translation_domain']);
760+
}
761+
762+
public function testPassChoiceTranslationDomainAsArray()
763+
{
764+
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
765+
'choice_translation_domain' => array(
766+
'hour' => 'foo',
767+
'second' => 'test',
768+
),
769+
'with_seconds' => true,
770+
));
771+
772+
$view = $form->createView();
773+
$this->assertSame('foo', $view['hour']->vars['choice_translation_domain']);
774+
$this->assertFalse($view['minute']->vars['choice_translation_domain']);
775+
$this->assertSame('test', $view['second']->vars['choice_translation_domain']);
776+
}
739777
}

0 commit comments

Comments
 (0)