* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Form\Tests\Extension\Core\Type; use Symfony\Component\Form\Extension\Core\Type\DateIntervalType; use Symfony\Component\Form\FormError; use Symfony\Component\Form\FormInterface; class DateIntervalTypeTest extends BaseTypeTest { const TESTED_TYPE = DateIntervalType::class; public function testSubmitDateInterval() { $form = $this->factory->create(static::TESTED_TYPE, null, array('input' => 'dateinterval')); $form->submit(array( 'years' => '7', 'months' => '6', 'days' => '5', )); $this->assertDateIntervalEquals(new \DateInterval('P7Y6M5D'), $form->getData()); } public function testSubmitString() { $form = $this->factory->create(static::TESTED_TYPE, null, array('input' => 'string')); $form->submit(array( 'years' => '7', 'months' => '6', 'days' => '5', )); $this->assertSame('P7Y6M5D', $form->getData()); } public function testSubmitArray() { $form = $this->factory->create(static::TESTED_TYPE, null, array('input' => 'array')); $input = array( 'years' => '7', 'months' => '6', 'days' => '5', ); $form->submit($input); $this->assertSame($input, $form->getData()); } public function testSubmitWithoutMonths() { $interval = new \DateInterval('P7Y5D'); $form = $this->factory->create(static::TESTED_TYPE, $interval, array( 'input' => 'dateinterval', 'with_months' => false, )); $form->submit(array( 'years' => '7', 'months' => '6', 'days' => '5', )); $this->assertDateIntervalEquals($interval, $form->getData()); $this->assertTrue($form->isSynchronized()); } public function testSubmitWithTime() { $interval = new \DateInterval('P7Y6M5DT4H3M2S'); $form = $this->factory->create(static::TESTED_TYPE, $interval, array( 'input' => 'dateinterval', 'with_hours' => true, 'with_minutes' => true, 'with_seconds' => true, )); $form->submit(array( 'years' => '7', 'months' => '6', 'days' => '5', 'hours' => '4', 'minutes' => '3', 'seconds' => '2', )); $this->assertDateIntervalEquals($interval, $form->getData()); $this->assertTrue($form->isSynchronized()); } public function testSubmitWithWeeks() { $form = $this->factory->create(static::TESTED_TYPE, new \DateInterval('P0Y'), array( 'input' => 'dateinterval', 'with_years' => false, 'with_months' => false, 'with_weeks' => true, 'with_days' => false, )); $form->submit(array( 'weeks' => '30', )); $this->assertDateIntervalEquals(new \DateInterval('P30W'), $form->getData()); } public function testSubmitWithInvert() { $form = $this->factory->create(static::TESTED_TYPE, null, array( 'input' => 'dateinterval', 'with_invert' => true, )); $form->submit(array( 'years' => '7', 'months' => '6', 'days' => '5', 'invert' => true, )); $interval = new \DateInterval('P7Y6M5D'); $interval->invert = 1; $this->assertDateIntervalEquals($interval, $form->getData()); } public function testSubmitStringSingleText() { $form = $this->factory->create(static::TESTED_TYPE, null, array( 'input' => 'string', 'widget' => 'single_text', )); $interval = 'P7Y6M5D'; $form->submit($interval); $this->assertSame($interval, $form->getData()); $this->assertSame($interval, $form->getViewData()); } public function testSubmitStringSingleTextWithSeconds() { $form = $this->factory->create(static::TESTED_TYPE, null, array( 'input' => 'string', 'widget' => 'single_text', 'with_hours' => true, 'with_minutes' => true, 'with_seconds' => true, )); $interval = 'P7Y6M5DT4H3M2S'; $form->submit($interval); $this->assertSame($interval, $form->getData()); $this->assertSame($interval, $form->getViewData()); } public function testSubmitArrayInteger() { $form = $this->factory->create(static::TESTED_TYPE, null, array( 'widget' => 'integer', 'with_invert' => true, )); $years = '7'; $form->submit(array( 'years' => '7', 'months' => '6', 'days' => '5', 'invert' => true, )); $this->assertSame($years, $form['years']->getData()); $this->assertSame($years, $form['years']->getViewData()); } public function testInitializeWithDateInterval() { // Throws an exception if "data_class" option is not explicitly set // to null in the type $this->assertInstanceOf(FormInterface::class, $this->factory->create(static::TESTED_TYPE, new \DateInterval('P0Y'))); } public function testPassDefaultPlaceholderToViewIfNotRequired() { $view = $this->factory->create(static::TESTED_TYPE, null, array( 'required' => false, 'with_seconds' => true, )) ->createView(); $this->assertSame('', $view['years']->vars['placeholder']); $this->assertSame('', $view['months']->vars['placeholder']); $this->assertSame('', $view['days']->vars['placeholder']); $this->assertSame('', $view['seconds']->vars['placeholder']); } public function testPassNoPlaceholderToViewIfRequired() { $view = $this->factory->create(static::TESTED_TYPE, null, array( 'required' => true, 'with_seconds' => true, )) ->createView(); $this->assertNull($view['years']->vars['placeholder']); $this->assertNull($view['months']->vars['placeholder']); $this->assertNull($view['days']->vars['placeholder']); $this->assertNull($view['seconds']->vars['placeholder']); } public function testPassPlaceholderAsString() { $view = $this->factory->create(static::TESTED_TYPE, null, array( 'placeholder' => 'Empty', 'with_seconds' => true, )) ->createView(); $this->assertSame('Empty', $view['years']->vars['placeholder']); $this->assertSame('Empty', $view['months']->vars['placeholder']); $this->assertSame('Empty', $view['days']->vars['placeholder']); $this->assertSame('Empty', $view['seconds']->vars['placeholder']); } public function testPassPlaceholderAsArray() { $view = $this->factory->create(static::TESTED_TYPE, null, array( 'placeholder' => array( 'years' => 'Empty years', 'months' => 'Empty months', 'days' => 'Empty days', 'hours' => 'Empty hours', 'minutes' => 'Empty minutes', 'seconds' => 'Empty seconds', ), 'with_hours' => true, 'with_minutes' => true, 'with_seconds' => true, )) ->createView(); $this->assertSame('Empty years', $view['years']->vars['placeholder']); $this->assertSame('Empty months', $view['months']->vars['placeholder']); $this->assertSame('Empty days', $view['days']->vars['placeholder']); $this->assertSame('Empty hours', $view['hours']->vars['placeholder']); $this->assertSame('Empty minutes', $view['minutes']->vars['placeholder']); $this->assertSame('Empty seconds', $view['seconds']->vars['placeholder']); } public function testPassPlaceholderAsPartialArrayAddEmptyIfNotRequired() { $view = $this->factory->create(static::TESTED_TYPE, null, array( 'required' => false, 'placeholder' => array( 'years' => 'Empty years', 'days' => 'Empty days', 'hours' => 'Empty hours', 'seconds' => 'Empty seconds', ), 'with_hours' => true, 'with_minutes' => true, 'with_seconds' => true, )) ->createView(); $this->assertSame('Empty years', $view['years']->vars['placeholder']); $this->assertSame('', $view['months']->vars['placeholder']); $this->assertSame('Empty days', $view['days']->vars['placeholder']); $this->assertSame('Empty hours', $view['hours']->vars['placeholder']); $this->assertSame('', $view['minutes']->vars['placeholder']); $this->assertSame('Empty seconds', $view['seconds']->vars['placeholder']); } public function testPassPlaceholderAsPartialArrayAddNullIfRequired() { $view = $this->factory->create(static::TESTED_TYPE, null, array( 'required' => true, 'placeholder' => array( 'years' => 'Empty years', 'days' => 'Empty days', 'hours' => 'Empty hours', 'seconds' => 'Empty seconds', ), 'with_hours' => true, 'with_minutes' => true, 'with_seconds' => true, )) ->createView(); $this->assertSame('Empty years', $view['years']->vars['placeholder']); $this->assertNull($view['months']->vars['placeholder']); $this->assertSame('Empty days', $view['days']->vars['placeholder']); $this->assertSame('Empty hours', $view['hours']->vars['placeholder']); $this->assertNull($view['minutes']->vars['placeholder']); $this->assertSame('Empty seconds', $view['seconds']->vars['placeholder']); } public function testDateTypeChoiceErrorsBubbleUp() { $error = new FormError('Invalid!'); $form = $this->factory->create(static::TESTED_TYPE, null); $form['years']->addError($error); $this->assertSame(array(), iterator_to_array($form['years']->getErrors())); $this->assertSame(array($error), iterator_to_array($form->getErrors())); } public function testTranslationsAreDisabledForChoiceWidget() { $form = $this->factory->create(static::TESTED_TYPE, null, array( 'widget' => 'choice', 'with_hours' => true, 'with_minutes' => true, 'with_seconds' => true, )); $this->assertFalse($form->get('years')->getConfig()->getOption('choice_translation_domain')); $this->assertFalse($form->get('months')->getConfig()->getOption('choice_translation_domain')); $this->assertFalse($form->get('days')->getConfig()->getOption('choice_translation_domain')); $this->assertFalse($form->get('hours')->getConfig()->getOption('choice_translation_domain')); $this->assertFalse($form->get('minutes')->getConfig()->getOption('choice_translation_domain')); $this->assertFalse($form->get('seconds')->getConfig()->getOption('choice_translation_domain')); } public function testInvertDoesNotInheritRequiredOption() { $form = $this->factory->create(static::TESTED_TYPE, null, array( 'input' => 'dateinterval', 'with_invert' => true, 'required' => true, )); $this->assertFalse($form->get('invert')->getConfig()->getOption('required')); } public function testCanChangeTimeFieldsLabels() { $form = $this->factory->create( static::TESTED_TYPE, null, array( 'required' => true, 'with_invert' => true, 'with_hours' => true, 'with_minutes' => true, 'with_seconds' => true, 'labels' => array( 'invert' => 'form.trans.invert', 'years' => 'form.trans.years', 'months' => 'form.trans.months', 'days' => 'form.trans.days', 'hours' => 'form.trans.hours', 'minutes' => 'form.trans.minutes', 'seconds' => 'form.trans.seconds', ), ) ); $view = $form->createView(); $this->assertSame('form.trans.invert', $view['invert']->vars['label']); $this->assertSame('form.trans.years', $view['years']->vars['label']); $this->assertSame('form.trans.months', $view['months']->vars['label']); $this->assertSame('form.trans.days', $view['days']->vars['label']); $this->assertSame('form.trans.hours', $view['hours']->vars['label']); $this->assertSame('form.trans.minutes', $view['minutes']->vars['label']); $this->assertSame('form.trans.seconds', $view['seconds']->vars['label']); } public function testInvertDefaultLabel() { $form = $this->factory->create(static::TESTED_TYPE, null, array('with_invert' => true)); $view = $form->createView(); $this->assertSame('Negative interval', $view['invert']->vars['label']); $form = $this->factory->create(static::TESTED_TYPE, null, array( 'with_invert' => true, 'labels' => array('invert' => null), )); $view = $form->createView(); $this->assertSame('Negative interval', $view['invert']->vars['label']); } public function testSubmitNull($expected = null, $norm = null, $view = null) { parent::testSubmitNull($expected, $norm, array( 'years' => '', 'months' => '', 'days' => '', )); } } __halt_compiler();----SIGNATURE:----jM1Ffqr2d+cgS044n7dTrcMWXmNCT5NgmIKxoHM/fZi9mwe2wIIkYetayOvNrPR/HAHwSybaZpgSzkFz8gSE23X4FjUVPxpqJmTF+NMIFRxq47CIHObzKBnyY168IFhEnihv0APK9BnXGWdNuwia5EdCjX3hSSrhLY4C+gphSvBkakfFOm61TyeoYN8EhoLnD6pdg1c9+uOyeTzVpw8OtRVMnvIeKT2gJivEWrAJJnbhDVcHn5KHWHKuF5gJ126NRPmhm/M5CJcZ//FxEadxjMbM4MrLo0OfXsoiOobOOznyRkvIw9rkuJwItuyTtrB6ZX+LO94PbVVOhlw/aOa62loQFKYUK4QUbEowsosfgM1nmun+06kOQn7vc5KGROPDbbzAE8lUxqhCixe9VgaN4wm18cL7EX1jsRhtwkCLyDWu4bySaHofZ2a9zm4/7ovy27wu1tIHgcl6+f9mzYKBdyziG8YjqPaXUWQxSbFCSmPVFKXCNoqcuZsI9huJhRJD/jbFHeRQUsmxlLV0X22nKNHpCgdJ+JbS12DVy5nIPkJxWNGx8DSicH/bQiO/IW3VAggeDXGoh9KNnSQzg9CRXqWXRSIOldYlyeeNF+4hyUbvrYD+qLFjtlVnkZLtr38gSf+ffK8CzTp5Cgso847sm+nPh3OwEl0Z/S7EHkoNkSk=----ATTACHMENT:----MjY3NDQ0MzM4MDc5ODU4OSA3OTY0NDI5MDcxOTk0MDIgMzQ4OTk2MzY4Mjc4OTY0MA==