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); }
/** * @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); }
/** * @param Website $website * * @return Website */ public function removeWebsite(Website $website) { if ($this->websites->contains($website)) { $this->websites->removeElement($website); } return $this; }
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()); }
/** * {@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(); }
/** * Load websites * * @param ObjectManager $manager */ public function load(ObjectManager $manager) { /** @var EntityManager $manager */ $user = $this->getUser($manager); $businessUnit = $user->getOwner(); $organization = $user->getOrganization(); // 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); $this->setReference($site->getName(), $site); $manager->persist($site); } $manager->flush(); $manager->clear(); }
public function testPreUpdate() { $website = new Website(); $website->preUpdate(); $this->assertInstanceOf('\\DateTime', $website->getUpdatedAt()); }
/** * @Route("/view/{id}", name="orob2b_website_view", requirements={"id"="\d+"}) * @Acl( * id="orob2b_website_view", * type="entity", * class="OroB2BWebsiteBundle:Website", * permission="VIEW" * ) * * @param Website $website * @return Response */ public function viewAction(Website $website) { // TODO: Implement view action return new Response($website->getName()); }
/** * @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()); }