/** * Get empty value for specified attribute depending on its type * * @param AttributeInterface $attribute * * @return array|bool|string|null */ protected function getEmptyValue(AttributeInterface $attribute) { switch ($attribute->getAttributeType()) { case 'pim_catalog_metric': $emptyValue = ['data' => null, 'unit' => $attribute->getDefaultMetricUnit()]; break; case 'pim_catalog_multiselect': case 'pim_reference_data_multiselect': $emptyValue = []; break; case 'pim_catalog_text': $emptyValue = ''; break; case 'pim_catalog_boolean': $emptyValue = false; break; case 'pim_catalog_price_collection': $emptyValue = []; break; default: $emptyValue = null; break; } return $emptyValue; }
function let(TranslationNormalizer $transnormalizer, AttributeInterface $attribute, AttributeGroupInterface $attributeGroup) { $this->beConstructedWith($transnormalizer); $transnormalizer->normalize(Argument::cetera())->willReturn([]); $attribute->getAttributeType()->willReturn('Yes/No'); $attribute->getCode()->willReturn('attribute_size'); $attribute->getGroup()->willReturn($attributeGroup); $attributeGroup->getCode()->willReturn('size'); $attribute->isUnique()->willReturn(true); $attribute->isUseableAsGridFilter()->willReturn(false); $attribute->getAllowedExtensions()->willReturn(['csv', 'xml', 'json']); $attribute->getMetricFamily()->willReturn('Length'); $attribute->getDefaultMetricUnit()->willReturn('Centimenter'); $attribute->getReferenceDataName()->willReturn('color'); $attribute->isLocalizable()->willReturn(true); $attribute->isScopable()->willReturn(false); }
function it_should_provide_the_empty_value_for_the_given_attribute(AttributeInterface $attribute) { $attribute->getAttributeType()->willReturn('pim_catalog_metric'); $attribute->getDefaultMetricUnit()->willReturn('METER'); $this->supports($attribute)->shouldReturn(true); $this->getEmptyValue($attribute)->shouldReturn(['data' => null, 'unit' => 'METER']); $attribute->getAttributeType()->willReturn('pim_catalog_multiselect'); $this->supports($attribute)->shouldReturn(true); $this->getEmptyValue($attribute)->shouldReturn([]); $attribute->getAttributeType()->willReturn('pim_catalog_text'); $this->supports($attribute)->shouldReturn(true); $this->getEmptyValue($attribute)->shouldReturn(''); $attribute->getAttributeType()->willReturn('pim_catalog_boolean'); $this->supports($attribute)->shouldReturn(true); $this->getEmptyValue($attribute)->shouldReturn(false); $attribute->getAttributeType()->willReturn('pim_catalog_price_collection'); $this->supports($attribute)->shouldReturn(true); $this->getEmptyValue($attribute)->shouldReturn([]); }