Esempio n. 1
0
 /**
  * @param ObjectManager $manager
  */
 public function load(ObjectManager $manager)
 {
     $locale = new Locale();
     $locale->setCode($this->container->get('oro_locale.settings')->getLocale());
     $manager->persist($locale);
     /** @var EntityManager $manager */
     $manager->flush($locale);
     $this->addReference('default_website_locale', $locale);
 }
 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);
 }
Esempio n. 5
0
 /**
  * Load locales
  *
  * @param ObjectManager $manager
  */
 public function load(ObjectManager $manager)
 {
     // Create locales sample with relationship between locales
     $localesRegistry = [];
     foreach ($this->locales as $item) {
         $locale = new Locale();
         $locale->setCode($item['code']);
         if ($item['parent']) {
             $locale->setParentLocale($localesRegistry[$item['parent']]);
         }
         $localesRegistry[$item['code']] = $locale;
         $manager->persist($locale);
     }
     $manager->flush();
     $manager->clear();
 }
 /**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     /** @var EntityManager $manager */
     $user = $this->getUser($manager);
     $businessUnit = $user->getOwner();
     $organization = $user->getOrganization();
     // Create locales sample with relationship between locales
     $localesRegistry = [];
     foreach ($this->locales as $item) {
         $code = $this->getLocaleNameByCode($item['code']);
         $locale = new Locale();
         $locale->setCode($code);
         if ($item['parent']) {
             $parentCode = $this->getLocaleNameByCode($item['parent']);
             $locale->setParentLocale($localesRegistry[$parentCode]);
         }
         $localesRegistry[$code] = $locale;
         $manager->persist($locale);
     }
     $manager->flush();
     // Create websites
     foreach ($this->webSites as $webSite) {
         $site = new Website();
         $siteLocales = [];
         foreach ($webSite['locales'] as $localeCode) {
             $siteLocales[] = $this->getLocaleByCode($manager, $localeCode);
         }
         $site->setOwner($businessUnit)->setOrganization($organization)->setName($webSite['name'])->setUrl($webSite['url'])->resetLocales($siteLocales);
         $manager->persist($site);
     }
     $manager->flush();
     // Create website sharing relationship
     foreach ($this->webSites as $webSite) {
         $site = $this->getWebsiteByName($manager, $webSite['name']);
         if ($webSite['sharing']) {
             foreach ($webSite['sharing'] as $siteName) {
                 $relatedWebsite = $this->getWebsiteByName($manager, $siteName);
                 $site->addRelatedWebsite($relatedWebsite);
             }
         }
     }
     $manager->flush();
     $manager->clear();
 }
Esempio n. 7
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());
 }
Esempio n. 8
0
 public function testPreUpdate()
 {
     $locale = new Locale();
     $this->assertNull($locale->getUpdatedAt());
     $locale->preUpdate();
     $this->assertInstanceOf('\\DateTime', $locale->getUpdatedAt());
 }
 /**
  * @param Product $product
  * @param Locale $locale
  * @return LocalizedFallbackValue
  */
 protected function getLocalizedName(Product $product, Locale $locale)
 {
     $localizedName = null;
     foreach ($product->getNames() as $name) {
         $nameLocale = $name->getLocale();
         if ($nameLocale && $nameLocale->getId() === $locale->getId()) {
             $localizedName = $name;
             break;
         }
     }
     if (!$localizedName) {
         throw new \LogicException('At least one localized name must be defined');
     }
     return $localizedName;
 }
Esempio n. 10
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());
 }