/** * {@inheritdoc} */ public function getFormParameters(Attribute $attribute) { if ($attribute->isContainHtml()) { return ['type' => 'oro_rich_text']; } else { return ['type' => 'textarea']; } }
/** * {@inheritdoc} */ public function getDefaultValueFormParameters(Attribute $attribute) { if ($attribute->isLocalized()) { return ['type' => LocalizedSelectCollectionType::NAME]; } else { return ['type' => NotLocalizedSelectCollectionType::NAME]; } }
public function testProperties() { $website = new Website(); $website->setName('Website'); $attribute = new Attribute(); $attribute->setType('text'); $properties = [['id', 1], ['attribute', $attribute, false], ['website', $website, false], ['website', null], ['field', AttributeProperty::FIELD_ON_PRODUCT_VIEW], ['value', true], ['value', null], ['fallback', FallbackType::SYSTEM]]; $this->assertPropertyAccessors(new AttributeProperty(), $properties); }
public function testProperties() { $locale = new Locale(); $locale->setCode('es_MX'); $attribute = new Attribute(); $attribute->setType('string'); $properties = [['id', 1], ['value', 'Test label'], ['fallback', 'website'], ['locale', $locale, false], ['locale', null], ['attribute', $attribute, false]]; $this->assertPropertyAccessors(new AttributeLabel(), $properties); }
/** * @return array * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function attributeTypeDataProvider() { $htmlAttribute = new Attribute(); $htmlAttribute->setContainHtml(true); $localizedAttribute = new Attribute(); $localizedAttribute->setLocalized(true); $notLocalizedAttribute = new Attribute(); $notLocalizedAttribute->setLocalized(false); return ['integer' => ['attributeType' => new Integer(), 'expected' => ['name' => Integer::NAME, 'typeField' => 'integer', 'isContainHtml' => false, 'isUsedForSearch' => false, 'isUsedInFilters' => true, 'formParameters' => ['type' => 'integer', 'options' => ['type' => 'text']], 'requiredConstraints' => [new IntegerConstraint()], 'optionalConstraints' => [new GreaterThanZero()], 'canBeUnique' => true, 'canBeRequired' => true]], 'boolean' => ['attributeType' => new Boolean(), 'expected' => ['name' => Boolean::NAME, 'typeField' => 'integer', 'isContainHtml' => false, 'isUsedForSearch' => false, 'isUsedInFilters' => true, 'formParameters' => ['type' => 'checkbox'], 'requiredConstraints' => [], 'optionalConstraints' => [], 'canBeUnique' => false, 'canBeRequired' => false], 'attribute' => null, 'normalizationData' => ['normalize' => [['from' => null, 'to' => null], ['from' => 0, 'to' => false], ['from' => 1, 'to' => true]], 'denormalize' => [['from' => null, 'to' => null], ['from' => '', 'to' => 0], ['from' => '0', 'to' => 0], ['from' => '1', 'to' => 1]]]], 'float' => ['attributeType' => new Float(), 'expected' => ['name' => Float::NAME, 'typeField' => 'float', 'isContainHtml' => false, 'isUsedForSearch' => false, 'isUsedInFilters' => true, 'formParameters' => ['type' => 'number'], 'requiredConstraints' => [new Decimal()], 'optionalConstraints' => [new GreaterThanZero(), new IntegerConstraint()], 'canBeUnique' => true, 'canBeRequired' => true]], 'string' => ['attributeType' => new String(), 'expected' => ['name' => String::NAME, 'typeField' => 'string', 'isContainHtml' => true, 'isUsedForSearch' => true, 'isUsedInFilters' => false, 'formParameters' => ['type' => 'text'], 'requiredConstraints' => [], 'optionalConstraints' => [new Letters(), new Alphanumeric(), new UrlSafe(), new Decimal(), new IntegerConstraint(), new Email(), new Url()], 'canBeUnique' => true, 'canBeRequired' => true]], 'text not localized' => ['attributeType' => new Text(), 'expected' => ['name' => Text::NAME, 'typeField' => 'text', 'isContainHtml' => true, 'isUsedForSearch' => true, 'isUsedInFilters' => false, 'formParameters' => ['type' => 'textarea'], 'requiredConstraints' => [], 'optionalConstraints' => [new Letters(), new Alphanumeric(), new UrlSafe(), new Decimal(), new IntegerConstraint(), new Email(), new Url()], 'canBeUnique' => true, 'canBeRequired' => true]], 'text localized' => ['attributeType' => new Text(), 'expected' => ['name' => Text::NAME, 'typeField' => 'text', 'isContainHtml' => true, 'isUsedForSearch' => true, 'isUsedInFilters' => false, 'formParameters' => ['type' => 'oro_rich_text'], 'requiredConstraints' => [], 'optionalConstraints' => [new Letters(), new Alphanumeric(), new UrlSafe(), new Decimal(), new IntegerConstraint(), new Email(), new Url()], 'canBeUnique' => true, 'canBeRequired' => true], 'attribute' => $htmlAttribute], 'date' => ['attributeType' => new Date(), 'expected' => ['name' => Date::NAME, 'typeField' => 'datetime', 'isContainHtml' => false, 'isUsedForSearch' => false, 'isUsedInFilters' => false, 'formParameters' => ['type' => 'oro_date'], 'requiredConstraints' => [], 'optionalConstraints' => [], 'canBeUnique' => true, 'canBeRequired' => true]], 'datetime' => ['attributeType' => new DateTime(), 'expected' => ['name' => DateTime::NAME, 'typeField' => 'datetime', 'isContainHtml' => false, 'isUsedForSearch' => false, 'isUsedInFilters' => false, 'formParameters' => ['type' => 'oro_datetime'], 'requiredConstraints' => [], 'optionalConstraints' => [], 'canBeUnique' => true, 'canBeRequired' => true]], 'select not localized' => ['attributeType' => new Select(), 'expected' => ['name' => Select::NAME, 'typeField' => 'options', 'isContainHtml' => false, 'isUsedForSearch' => true, 'isUsedInFilters' => true, 'formParameters' => ['type' => SelectAttributeTypeType::NAME], 'defaultFormParameters' => ['type' => NotLocalizedSelectCollectionType::NAME], 'requiredConstraints' => [], 'optionalConstraints' => [], 'canBeUnique' => false, 'canBeRequired' => true], 'attribute' => $notLocalizedAttribute], 'select localized' => ['attributeType' => new Select(), 'expected' => ['name' => Select::NAME, 'typeField' => 'options', 'isContainHtml' => false, 'isUsedForSearch' => true, 'isUsedInFilters' => true, 'formParameters' => ['type' => SelectAttributeTypeType::NAME], 'defaultFormParameters' => ['type' => LocalizedSelectCollectionType::NAME], 'requiredConstraints' => [], 'optionalConstraints' => [], 'canBeUnique' => false, 'canBeRequired' => true], 'attribute' => $localizedAttribute], 'multiselect not localized' => ['attributeType' => new MultiSelect(), 'expected' => ['name' => MultiSelect::NAME, 'typeField' => 'options', 'isContainHtml' => false, 'isUsedForSearch' => true, 'isUsedInFilters' => true, 'formParameters' => ['type' => MultiSelectAttributeTypeType::NAME], 'defaultFormParameters' => ['type' => NotLocalizedMultiselectCollectionType::NAME], 'requiredConstraints' => [], 'optionalConstraints' => [], 'canBeUnique' => false, 'canBeRequired' => true], 'attribute' => $notLocalizedAttribute], 'multiselect localized' => ['attributeType' => new MultiSelect(), 'expected' => ['name' => MultiSelect::NAME, 'typeField' => 'options', 'isContainHtml' => false, 'isUsedForSearch' => true, 'isUsedInFilters' => true, 'formParameters' => ['type' => MultiSelectAttributeTypeType::NAME], 'defaultFormParameters' => ['type' => LocalizedMultiselectCollectionType::NAME], 'requiredConstraints' => [], 'optionalConstraints' => [], 'canBeUnique' => false, 'canBeRequired' => true], 'attribute' => $localizedAttribute]]; }
public function testProperties() { $locale = new Locale(); $locale->setCode('es_MX'); $attribute = new Attribute(); $attribute->setType('select'); $masterOption = new AttributeOption(); $masterOption->setAttribute($attribute)->setValue('master'); $properties = [['id', 1], ['value', 'test'], ['order', 5], ['fallback', 'website'], ['locale', $locale, false], ['locale', null], ['attribute', $attribute, false], ['masterOption', $masterOption], ['masterOption', null]]; $this->assertPropertyAccessors(new AttributeOption(), $properties); }
public function testProperties() { $locale = new Locale(); $locale->setCode('es_MX'); $attribute = new Attribute(); $attribute->setType('float'); $option = new AttributeOption(); $option->setAttribute($attribute); $option->setLocale($locale); $properties = [['id', 1], ['integer', 3], ['string', 'string'], ['float', 3.9999], ['datetime', new \DateTime('now')], ['text', 'text'], ['fallback', 'website'], ['locale', $locale, false], ['locale', null], ['attribute', $attribute, false], ['option', $option, false]]; $this->assertPropertyAccessors(new AttributeDefaultValue(), $properties); }
/** * @param ObjectManager $manager */ public function load(ObjectManager $manager) { $attribute = new Attribute(); $attribute->setCode(self::ATTRIBUTE_CODE)->setType(Select::NAME)->setSharingType(SharingType::GENERAL); foreach (self::$options as $localeCode => $options) { $locale = $localeCode ? $this->getLocaleByCode($manager, $localeCode) : null; foreach ($options as $order => $value) { $option = new AttributeOption(); $option->setLocale($locale)->setValue($value)->setOrder($order); $attribute->addOption($option); } } $manager->persist($attribute); $manager->flush($attribute); $manager->clear(); }
/** * @param array $normalizers */ public function assertNormalizers(array $normalizers) { $this->assertArrayHasKey('query_builder', $normalizers); /** @var \Closure $normalizerCallback */ $normalizerCallback = $normalizers['query_builder']; $this->assertInstanceOf('\\Closure', $normalizerCallback); $attribute = new Attribute(); $attribute->setCode('select_attribute')->setType(Select::NAME); $options = new Options(); $options->set('attribute', $attribute); /** @var \Closure $queryBuilderCallback */ $queryBuilderCallback = $normalizerCallback($options); $this->assertInstanceOf('\\Closure', $queryBuilderCallback); $queryBuilder = $this->getMockBuilder('Doctrine\\ORM\\QueryBuilder')->disableOriginalConstructor()->getMock(); $repository = $this->getMockBuilder('OroB2B\\Bundle\\AttributeBundle\\Entity\\Repository\\AttributeOptionRepository')->disableOriginalConstructor()->getMock(); $repository->expects($this->once())->method('createAttributeOptionsQueryBuilder')->with($attribute)->willReturn($queryBuilder); $this->assertEquals($queryBuilder, $queryBuilderCallback($repository)); }
/** * @Route("/init", name="orob2b_attribute_init") * @Template("OroB2BAttributeBundle:Attribute:update.html.twig") * @AclAncestor("orob2b_attribute_create") * * @return array|RedirectResponse */ public function initAction() { $request = $this->getRequest(); if ($request->getMethod() != 'POST') { return $this->redirect($this->generateUrl('orob2b_attribute_init')); } if ($request->request->has(CreateAttributeType::NAME)) { // processing of create form $form = $this->createForm(CreateAttributeType::NAME); $form->submit($request); if (!$form->isValid()) { return $this->forward('OroB2BAttributeBundle:Attribute:create'); } $attribute = $form->getData(); } elseif ($request->request->has(UpdateAttributeType::NAME)) { // processing of init form $formData = $request->request->get(UpdateAttributeType::NAME); $attribute = new Attribute(); $attribute->setCode($formData['code'])->setType($formData['type'])->setLocalized(!empty($formData['localized'])); } else { throw new BadRequestHttpException('Request does not contain attribute data'); } return $this->update($attribute); }
/** * @param Attribute $attribute * @return AttributeTypeInterface */ protected function getAttributeType(Attribute $attribute) { $type = $attribute->getType(); if (!$type) { throw new TransformationFailedException('Attribute type is not defined'); } $typeObject = $this->typeRegistry->getTypeByName($type); if (!$typeObject) { throw new TransformationFailedException(sprintf('Unknown attribute type "%s"', $type)); } return $typeObject; }
/** * @expectedException \Symfony\Component\Form\Exception\LogicException * @expectedExceptionMessage Form type is required for attribute type "invalid" */ public function testBuildFormNoFormTypeOptionsException() { $type = 'invalid'; /** @var \PHPUnit_Framework_MockObject_MockObject|AttributeTypeInterface $invalidAttributeType */ $invalidAttributeType = $this->getMock('OroB2B\\Bundle\\AttributeBundle\\AttributeType\\OptionAttributeTypeInterface'); $invalidAttributeType->expects($this->any())->method('getName')->will($this->returnValue($type)); $invalidAttributeType->expects($this->any())->method('getDefaultValueFormParameters')->will($this->returnValue([])); $this->typeRegistry->addType($invalidAttributeType); $attribute = new Attribute(); $attribute->setType($type); /** @var \PHPUnit_Framework_MockObject_MockObject|FormBuilderInterface $builder */ $builder = $this->getMock('Symfony\\Component\\Form\\FormBuilderInterface'); $builder->expects($this->any())->method('add')->willReturnSelf(); $this->formType->buildForm($builder, ['data' => $attribute]); }
/** * @param Attribute $attribute * @param string $field * @param array $values */ public function setPropertyValues(Attribute $attribute, $field, array $values) { foreach ($values as $websiteId => $value) { $attributeProperty = $attribute->getPropertyByFieldAndWebsiteId($field, $websiteId); if (!$attributeProperty) { $attributeProperty = new AttributeProperty(); $attributeProperty->setField($field); if ($websiteId) { $attributeProperty->setWebsite($this->databaseHelper->findWebsite($websiteId)); } $attribute->addProperty($attributeProperty); } if ($value instanceof FallbackType) { $attributeProperty->setValue(null)->setFallback($value->getType()); } else { $attributeProperty->setValue($value)->setFallback(null); } } }
/** * @param Attribute $attribute * @param AttributeOption $option * @param int $localeId * @return AttributeDefaultValue */ protected function generateOptionDefaultValue(Attribute $attribute, AttributeOption $option, $localeId) { $defaultValue = null; if ($option->getId()) { $defaultValue = $attribute->getDefaultValueByLocaleIdAndOptionId($localeId, $option->getId()); } if (!$defaultValue) { $defaultValue = new AttributeDefaultValue(); if ($localeId) { $defaultValue->setLocale($this->databaseHelper->findLocale($localeId)); } } $defaultValue->setOption($option); return $defaultValue; }
/** * {@inheritdoc} */ public function load(ObjectManager $manager) { foreach ($this->attributes as $item) { // Create attribute label $label = new AttributeLabel(); $label->setValue($item['label']); // Create attribute $attribute = new Attribute(); $attribute->setCode($item['code']); $attribute->setType($item['type']); $attribute->setSharingType(SharingType::GENERAL); $attribute->setLocalized($item['localized']); $attribute->setSystem($item['system']); $attribute->setRequired($item['required']); $attribute->setUnique($item['unique']); $attribute->addLabel($label); if (isset($item['options'])) { foreach ($item['options'] as $optionItem) { $masterOption = new AttributeOption(); $masterOption->setValue($optionItem['value']); $masterOption->setOrder($optionItem['order']); $attribute->addOption($masterOption); } } $manager->persist($attribute); } if (!empty($this->attributes)) { $manager->flush(); $manager->clear(); } }
/** * @param Attribute $attribute */ protected function addTestProperties(Attribute $attribute) { $attribute->addProperty($this->createProperty(null, AttributeProperty::FIELD_ON_PRODUCT_VIEW, false))->addProperty($this->createProperty(1, AttributeProperty::FIELD_ON_PRODUCT_VIEW, true))->addProperty($this->createProperty(2, AttributeProperty::FIELD_ON_PRODUCT_VIEW, null, FallbackType::SYSTEM))->addProperty($this->createProperty(null, AttributeProperty::FIELD_IN_PRODUCT_LISTING, true))->addProperty($this->createProperty(1, AttributeProperty::FIELD_IN_PRODUCT_LISTING, false))->addProperty($this->createProperty(2, AttributeProperty::FIELD_IN_PRODUCT_LISTING, null, FallbackType::SYSTEM))->addProperty($this->createProperty(null, AttributeProperty::FIELD_USE_IN_SORTING, false))->addProperty($this->createProperty(1, AttributeProperty::FIELD_USE_IN_SORTING, true))->addProperty($this->createProperty(2, AttributeProperty::FIELD_USE_IN_SORTING, null, FallbackType::SYSTEM))->addProperty($this->createProperty(null, AttributeProperty::FIELD_ON_ADVANCED_SEARCH, true))->addProperty($this->createProperty(1, AttributeProperty::FIELD_ON_ADVANCED_SEARCH, false))->addProperty($this->createProperty(2, AttributeProperty::FIELD_ON_ADVANCED_SEARCH, null, FallbackType::SYSTEM))->addProperty($this->createProperty(null, AttributeProperty::FIELD_ON_PRODUCT_COMPARISON, true))->addProperty($this->createProperty(1, AttributeProperty::FIELD_ON_PRODUCT_COMPARISON, false))->addProperty($this->createProperty(2, AttributeProperty::FIELD_ON_PRODUCT_COMPARISON, null, FallbackType::SYSTEM))->addProperty($this->createProperty(null, AttributeProperty::FIELD_USE_IN_FILTERS, false))->addProperty($this->createProperty(1, AttributeProperty::FIELD_USE_IN_FILTERS, true))->addProperty($this->createProperty(2, AttributeProperty::FIELD_USE_IN_FILTERS, null, FallbackType::SYSTEM)); }
/** * @expectedException \LogicException * @expectedExceptionMessage Several attribute options found by the same option ID. */ public function testGetOptionByIdException() { $firstOption = $this->createAttributeOption(1); $secondOption = $this->createAttributeOption(1); $attribute = new Attribute(); $attribute->resetOptions([$firstOption, $secondOption]); $attribute->getOptionById(1); }