/**
  * {@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();
     }
 }
 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);
 }
 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);
 }
 public function reverseTransformExceptionDataProvider()
 {
     $unknownTypeAttribute = new Attribute();
     $unknownTypeAttribute->setType('unknown');
     return ['not an array' => ['Symfony\\Component\\Form\\Exception\\UnexpectedTypeException', 'Expected argument of type "array", "DateTime" given', new \DateTime()], 'no attribute type' => ['Symfony\\Component\\Form\\Exception\\TransformationFailedException', 'Attribute type is not defined', ['code' => 'test']], 'unknown attribute type' => ['Symfony\\Component\\Form\\Exception\\TransformationFailedException', 'Unknown attribute type "unknown"', ['code' => 'test'], $unknownTypeAttribute]];
 }
 /**
  * @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]);
 }
 /**
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testAttributeRelations()
 {
     // Create websites
     $firstWebsite = new Website();
     $firstWebsite->setName('First Website');
     $firstWebsite->setUrl('www.first-website.com');
     $secondWebsite = new Website();
     $secondWebsite->setName('Second Website');
     $secondWebsite->setUrl('www.second-website.com');
     $thirdWebsite = new Website();
     $thirdWebsite->setName('Third Website');
     $thirdWebsite->setUrl('www.third-website.com');
     // Create locales
     $localeOne = new Locale();
     $localeOne->setCode('es_MX');
     $localeTwo = new Locale();
     $localeTwo->setCode('en_GB');
     $localeThree = new Locale();
     $localeThree->setCode('en_AU');
     // Create attribute labels
     $labelOne = new AttributeLabel();
     $labelOne->setValue('Attribute 01');
     $labelOne->setLocale($localeOne);
     $labelTwo = new AttributeLabel();
     $labelTwo->setValue('Attribute 02');
     $labelTwo->setLocale($localeTwo);
     $labelThree = new AttributeLabel();
     $labelThree->setValue('Attribute 03');
     $labelThree->setLocale($localeThree);
     // Create attribute
     $attribute = new Attribute();
     $attribute->setType('select');
     // Create attribute properties
     $propertyOne = new AttributeProperty();
     $propertyOne->setAttribute($attribute);
     $propertyOne->setWebsite($firstWebsite);
     $propertyTwo = new AttributeProperty();
     $propertyTwo->setAttribute($attribute);
     $propertyTwo->setWebsite($secondWebsite);
     $propertyThree = new AttributeProperty();
     $propertyThree->setAttribute($attribute);
     $propertyThree->setWebsite($thirdWebsite);
     // Create options
     $optionOne = new AttributeOption();
     $optionOne->setAttribute($attribute);
     $optionOne->setLocale($localeOne);
     $optionTwo = new AttributeOption();
     $optionTwo->setAttribute($attribute);
     $optionTwo->setLocale($localeTwo);
     $optionThree = new AttributeOption();
     $optionThree->setAttribute($attribute);
     $optionThree->setLocale($localeThree);
     // Create default values
     $defaultValueOne = new AttributeDefaultValue();
     $defaultValueOne->setAttribute($attribute);
     $defaultValueOne->setLocale($localeOne);
     $defaultValueOne->setOption($optionOne);
     $defaultValueTwo = new AttributeDefaultValue();
     $defaultValueTwo->setAttribute($attribute);
     $defaultValueTwo->setLocale($localeTwo);
     $defaultValueTwo->setOption($optionTwo);
     $defaultValueThree = new AttributeDefaultValue();
     $defaultValueThree->setAttribute($attribute);
     $defaultValueThree->setLocale($localeThree);
     $defaultValueThree->setOption($optionThree);
     // Reset labels
     $this->assertSame($attribute, $attribute->resetLabels([$labelOne, $labelTwo]));
     $actual = $attribute->getLabels();
     $this->assertInstanceOf('Doctrine\\Common\\Collections\\ArrayCollection', $actual);
     $this->assertEquals([$labelOne, $labelTwo], $actual->toArray());
     foreach ($actual as $label) {
         $this->assertContains($label, $attribute->getLabels());
     }
     // Reset properties
     $this->assertSame($attribute, $attribute->resetProperties([$propertyOne, $propertyTwo]));
     $actual = $attribute->getProperties();
     $this->assertInstanceOf('Doctrine\\Common\\Collections\\ArrayCollection', $actual);
     $this->assertEquals([$propertyOne, $propertyTwo], $actual->toArray());
     foreach ($actual as $property) {
         $this->assertContains($property, $attribute->getProperties());
     }
     // Reset options
     $this->assertSame($attribute, $attribute->resetOptions([$optionOne, $optionTwo]));
     $actual = $attribute->getOptions();
     $this->assertInstanceOf('Doctrine\\Common\\Collections\\ArrayCollection', $actual);
     $this->assertEquals([$optionOne, $optionTwo], $actual->toArray());
     foreach ($actual as $option) {
         $this->assertContains($option, $attribute->getOptions());
     }
     // Reset default values
     $this->assertSame($attribute, $attribute->resetDefaultValues([$defaultValueOne, $defaultValueTwo]));
     $actual = $attribute->getDefaultValues();
     $this->assertInstanceOf('Doctrine\\Common\\Collections\\ArrayCollection', $actual);
     $this->assertEquals([$defaultValueOne, $defaultValueTwo], $actual->toArray());
     foreach ($actual as $defaultValue) {
         $this->assertContains($defaultValue, $attribute->getDefaultValues());
     }
     // Add already added label
     $this->assertSame($attribute, $attribute->addLabel($labelTwo));
     $actual = $attribute->getLabels();
     $this->assertInstanceOf('Doctrine\\Common\\Collections\\ArrayCollection', $actual);
     $this->assertEquals([$labelOne, $labelTwo], $actual->toArray());
     // Add already added  property
     $this->assertSame($attribute, $attribute->addProperty($propertyTwo));
     $actual = $attribute->getProperties();
     $this->assertInstanceOf('Doctrine\\Common\\Collections\\ArrayCollection', $actual);
     $this->assertEquals([$propertyOne, $propertyTwo], $actual->toArray());
     // Add already added  option
     $this->assertSame($attribute, $attribute->addOption($optionTwo));
     $actual = $attribute->getOptions();
     $this->assertInstanceOf('Doctrine\\Common\\Collections\\ArrayCollection', $actual);
     $this->assertEquals([$optionOne, $optionTwo], $actual->toArray());
     // Add already added  default value
     $this->assertSame($attribute, $attribute->addDefaultValue($defaultValueTwo));
     $actual = $attribute->getDefaultValues();
     $this->assertInstanceOf('Doctrine\\Common\\Collections\\ArrayCollection', $actual);
     $this->assertEquals([$defaultValueOne, $defaultValueTwo], $actual->toArray());
     // Add new label
     $this->assertSame($attribute, $attribute->addLabel($labelThree));
     $actual = $attribute->getLabels();
     $this->assertInstanceOf('Doctrine\\Common\\Collections\\ArrayCollection', $actual);
     $this->assertEquals([$labelOne, $labelTwo, $labelThree], $actual->toArray());
     foreach ($actual as $label) {
         $this->assertContains($label, $attribute->getLabels());
     }
     // Add new property
     $this->assertSame($attribute, $attribute->addProperty($propertyThree));
     $actual = $attribute->getProperties();
     $this->assertInstanceOf('Doctrine\\Common\\Collections\\ArrayCollection', $actual);
     $this->assertEquals([$propertyOne, $propertyTwo, $propertyThree], $actual->toArray());
     foreach ($actual as $property) {
         $this->assertContains($property, $attribute->getProperties());
     }
     // Add new option
     $this->assertSame($attribute, $attribute->addOption($optionThree));
     $actual = $attribute->getOptions();
     $this->assertInstanceOf('Doctrine\\Common\\Collections\\ArrayCollection', $actual);
     $this->assertEquals([$optionOne, $optionTwo, $optionThree], $actual->toArray());
     foreach ($actual as $option) {
         $this->assertContains($option, $attribute->getOptions());
     }
     // Add new default value
     $this->assertSame($attribute, $attribute->addDefaultValue($defaultValueThree));
     $actual = $attribute->getDefaultValues();
     $this->assertInstanceOf('Doctrine\\Common\\Collections\\ArrayCollection', $actual);
     $this->assertEquals([$defaultValueOne, $defaultValueTwo, $defaultValueThree], $actual->toArray());
     foreach ($actual as $defaultValue) {
         $this->assertContains($defaultValue, $attribute->getDefaultValues());
     }
     // Remove label
     $this->assertSame($attribute, $attribute->removeLabel($labelOne));
     $actual = $attribute->getLabels();
     $this->assertInstanceOf('Doctrine\\Common\\Collections\\ArrayCollection', $actual);
     $this->assertContains($labelTwo, $actual->toArray());
     $this->assertContains($labelThree, $actual->toArray());
     $this->assertNotContains($labelOne, $actual->toArray());
     // Remove property
     $this->assertSame($attribute, $attribute->removeProperty($propertyOne));
     $actual = $attribute->getProperties();
     $this->assertInstanceOf('Doctrine\\Common\\Collections\\ArrayCollection', $actual);
     $this->assertContains($propertyTwo, $actual->toArray());
     $this->assertContains($propertyThree, $actual->toArray());
     $this->assertNotContains($propertyOne, $actual->toArray());
     // Remove option
     $this->assertSame($attribute, $attribute->removeOption($optionOne));
     $actual = $attribute->getOptions();
     $this->assertInstanceOf('Doctrine\\Common\\Collections\\ArrayCollection', $actual);
     $this->assertContains($optionTwo, $actual->toArray());
     $this->assertContains($optionThree, $actual->toArray());
     $this->assertNotContains($optionOne, $actual->toArray());
     // Remove default value
     $this->assertSame($attribute, $attribute->removeDefaultValue($defaultValueOne));
     $actual = $attribute->getDefaultValues();
     $this->assertInstanceOf('Doctrine\\Common\\Collections\\ArrayCollection', $actual);
     $this->assertContains($defaultValueTwo, $actual->toArray());
     $this->assertContains($defaultValueThree, $actual->toArray());
     $this->assertNotContains($defaultValueOne, $actual->toArray());
 }