function it_adds_violation_when_date_min_is_not_valid($context, AttributeInterface $attribute, ValidDateRange $constraint) { $date = new \DateTime(); $attribute->getDateMin()->willReturn('not_a_date'); $attribute->getDateMax()->willReturn($date); $context->addViolationAt('dateMin', $constraint->invalidDateMessage)->shouldBeCalled(); $this->validate($attribute, $constraint); }
/** * {@inheritdoc} */ public function guessConstraints(AttributeInterface $attribute) { $constraints = array(); if ('pim_catalog_date' === $attribute->getAttributeType()) { $min = $attribute->getDateMin(); $max = $attribute->getDateMax(); } else { $min = $attribute->getNumberMin(); $max = $attribute->getNumberMax(); if (false === $attribute->isNegativeAllowed() && ($min === null || $min < 0)) { $min = 0; } } if (null !== $min || null !== $max) { $constraints[] = new Range(array('min' => $min, 'max' => $max)); } return $constraints; }
function it_does_not_guess_minmax_date(AttributeInterface $attribute) { $attribute->getAttributeType()->willReturn('pim_catalog_date'); $attribute->getDateMin()->willReturn(null); $attribute->getDateMax()->willReturn(null); $attribute->getNumberMin()->shouldNotBeCalled(); $attribute->getNumberMax()->shouldNotBeCalled(); $attribute->isNegativeAllowed()->shouldNotBeCalled(); $constraints = $this->guessConstraints($attribute); $constraints->shouldReturn([]); }
/** * Get extra data to store in version * * @param AttributeInterface $attribute * * @return array */ protected function getVersionedData(AttributeInterface $attribute) { $dateMin = is_null($attribute->getDateMin()) ? '' : $attribute->getDateMin()->format(\DateTime::ISO8601); $dateMax = is_null($attribute->getDateMax()) ? '' : $attribute->getDateMax()->format(\DateTime::ISO8601); return ['available_locales' => $this->normalizeAvailableLocales($attribute), 'localizable' => $attribute->isLocalizable(), 'scope' => $attribute->isScopable() ? self::CHANNEL_SCOPE : self::GLOBAL_SCOPE, 'options' => $this->normalizeOptions($attribute), 'sort_order' => (int) $attribute->getSortOrder(), 'required' => (int) $attribute->isRequired(), 'max_characters' => (string) $attribute->getMaxCharacters(), 'validation_rule' => (string) $attribute->getValidationRule(), 'validation_regexp' => (string) $attribute->getValidationRegexp(), 'wysiwyg_enabled' => (string) $attribute->isWysiwygEnabled(), 'number_min' => (string) $attribute->getNumberMin(), 'number_max' => (string) $attribute->getNumberMax(), 'decimals_allowed' => (string) $attribute->isDecimalsAllowed(), 'negative_allowed' => (string) $attribute->isNegativeAllowed(), 'date_min' => $dateMin, 'date_max' => $dateMax, 'metric_family' => (string) $attribute->getMetricFamily(), 'default_metric_unit' => (string) $attribute->getDefaultMetricUnit(), 'max_file_size' => (string) $attribute->getMaxFileSize()]; }