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);
 }
Exemplo n.º 2
0
 /**
  * @param ObjectManager $manager
  */
 public function load(ObjectManager $manager)
 {
     $organization = $this->getReference('default_organization');
     $businessUnit = $manager->getRepository('OroOrganizationBundle:BusinessUnit')->findOneBy(['name' => LoadOrganizationAndBusinessUnitData::MAIN_BUSINESS_UNIT]);
     $url = parse_url($this->container->get('oro_config.manager')->get('oro_ui.application_url'));
     /** @var Locale $locale */
     $locale = $this->getReference('default_website_locale');
     $website = new Website();
     $website->setName(self::DEFAULT_WEBSITE_NAME)->setOrganization($organization)->setOwner($businessUnit)->setUrl($url['host'])->addLocale($locale);
     $manager->persist($website);
     /** @var EntityManager $manager */
     $manager->flush($website);
 }
Exemplo n.º 3
0
 public function testLocaleWebsites()
 {
     // Create websites
     $websiteOne = new Website();
     $websiteOne->setName('Website One');
     $websiteOne->setUrl('www.website-one.com');
     $websiteTwo = new Website();
     $websiteTwo->setName('Website Two');
     $websiteTwo->setUrl('www.website-two.com');
     $websiteThree = new Website();
     $websiteThree->setName('Website Three');
     $websiteThree->setUrl('www.website-three.com');
     // Create locale
     $currentLocale = new Locale();
     $currentLocale->setCode('en_US');
     // reset websites for current locale
     $this->assertSame($currentLocale, $currentLocale->resetWebsites([$websiteOne, $websiteTwo]));
     $actual = $currentLocale->getWebsites();
     $this->assertInstanceOf('Doctrine\\Common\\Collections\\ArrayCollection', $actual);
     $this->assertEquals([$websiteOne, $websiteTwo], $actual->toArray());
     /** @var Website $website */
     foreach ($actual as $website) {
         $this->assertContains($website, $currentLocale->getWebsites());
     }
     // add websites to current locale
     $this->assertSame($currentLocale, $currentLocale->addWebsite($websiteTwo));
     $actual = $currentLocale->getWebsites();
     $this->assertInstanceOf('Doctrine\\Common\\Collections\\ArrayCollection', $actual);
     $this->assertEquals([$websiteOne, $websiteTwo], $actual->toArray());
     $this->assertSame($currentLocale, $currentLocale->addWebsite($websiteThree));
     $actual = $currentLocale->getWebsites();
     $this->assertInstanceOf('Doctrine\\Common\\Collections\\ArrayCollection', $actual);
     $this->assertEquals([$websiteOne, $websiteTwo, $websiteThree], $actual->toArray());
     /** @var Website $website */
     foreach ($actual as $website) {
         $this->assertContains($website, $currentLocale->getWebsites());
     }
     // remove websites from current locale
     $this->assertSame($currentLocale, $currentLocale->removeWebsite($websiteOne));
     $actual = $currentLocale->getWebsites();
     $this->assertInstanceOf('Doctrine\\Common\\Collections\\ArrayCollection', $actual);
     $this->assertContains($websiteTwo, $actual->toArray());
     $this->assertContains($websiteThree, $actual->toArray());
     $this->assertNotContains($websiteOne, $actual->toArray());
 }
Exemplo n.º 4
0
 public function testWebsiteLocales()
 {
     // Create locales
     $localeOne = new Locale();
     $localeOne->setCode('es_MX');
     $localeTwo = new Locale();
     $localeTwo->setCode('en_GB');
     $localeThree = new Locale();
     $localeThree->setCode('en_AU');
     // Create website
     $currentWebsite = new Website();
     $currentWebsite->setName('Current Website');
     $currentWebsite->setUrl('www.current-website.com');
     // reset locales for current website
     $this->assertSame($currentWebsite, $currentWebsite->resetLocales([$localeOne, $localeTwo]));
     $actual = $currentWebsite->getLocales();
     $this->assertInstanceOf('Doctrine\\Common\\Collections\\ArrayCollection', $actual);
     $this->assertEquals([$localeOne, $localeTwo], $actual->toArray());
     /** @var Locale $locale */
     foreach ($actual as $locale) {
         $this->assertContains($locale, $currentWebsite->getLocales());
     }
     // add locales to current website
     $this->assertSame($currentWebsite, $currentWebsite->addLocale($localeTwo));
     $actual = $currentWebsite->getLocales();
     $this->assertInstanceOf('Doctrine\\Common\\Collections\\ArrayCollection', $actual);
     $this->assertEquals([$localeOne, $localeTwo], $actual->toArray());
     $this->assertSame($currentWebsite, $currentWebsite->addLocale($localeThree));
     $actual = $currentWebsite->getLocales();
     $this->assertInstanceOf('Doctrine\\Common\\Collections\\ArrayCollection', $actual);
     $this->assertEquals([$localeOne, $localeTwo, $localeThree], $actual->toArray());
     /** @var Locale $locale */
     foreach ($actual as $locale) {
         $this->assertContains($locale, $currentWebsite->getLocales());
     }
     // remove locales from current website
     $this->assertSame($currentWebsite, $currentWebsite->removeLocale($localeOne));
     $actual = $currentWebsite->getLocales();
     $this->assertInstanceOf('Doctrine\\Common\\Collections\\ArrayCollection', $actual);
     $this->assertContains($localeTwo, $actual->toArray());
     $this->assertContains($localeThree, $actual->toArray());
     $this->assertNotContains($localeOne, $actual->toArray());
 }
Exemplo n.º 5
0
 /**
  * @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());
 }