public function testToArray() { $expected = ['key' => 'foo', 'name' => 'portal_key', 'localizations' => [['fr']], 'security' => ['system' => 'sec_sys'], 'segments' => [['asd']], 'portals' => [['one']], 'theme' => ['dsa'], 'navigation' => ['contexts' => []]]; $this->security->getSystem()->willReturn($expected['security']['system']); $this->localization->toArray()->willReturn($expected['localizations'][0]); $this->segment->toArray()->willReturn($expected['segments'][0]); $this->theme->toArray()->willReturn($expected['theme']); $this->portal->toArray()->willReturn($expected['portals'][0]); $this->webspace->setKey($expected['key']); $this->webspace->setName($expected['name']); $this->webspace->setLocalizations([$this->localization->reveal()]); $this->webspace->setSecurity($this->security->reveal()); $this->webspace->setSegments([$this->segment->reveal()]); $this->webspace->setPortals([$this->portal->reveal()]); $this->webspace->setTheme($this->theme->reveal()); $res = $this->webspace->toArray(); $this->assertEquals($expected, $res); }
/** * Adds a segment to the webspace. * * @param Segment $segment */ public function addSegment(Segment $segment) { $this->segments[] = $segment; if ($segment->isDefault()) { $this->setDefaultSegment($segment); } }
/** * Generates the available segments for the webspace from the XML document. */ protected function generateSegments() { foreach ($this->xpath->query('/x:webspace/x:segments/x:segment') as $segmentNode) { /** @var \DOMNode $segmentNode */ $segment = new Segment(); $segment->setName($segmentNode->nodeValue); $segment->setKey($segmentNode->attributes->getNamedItem('key')->nodeValue); $defaultNode = $segmentNode->attributes->getNamedItem('default'); if ($defaultNode) { $segment->setDefault($defaultNode->nodeValue == 'true'); } else { $segment->setDefault(false); } $this->webspace->addSegment($segment); } }
public function setUp() { $webspaces = []; $portals = []; $portalInformations = ['prod' => [], 'dev' => []]; $this->webspaceCollection = new WebspaceCollection(); // first portal $portal = new Portal(); $portal->setName('Portal1'); $portal->setKey('portal1'); $theme = new Theme(); $theme->setKey('portal1theme'); $environment = new Environment(); $url = new Url(); $url->setUrl('www.portal1.com'); $url->setLanguage('en'); $url->setCountry('us'); $environment->addUrl($url); $environment->setType('prod'); $url = new Url(); $url->setUrl('portal1.com'); $url->setRedirect('www.portal1.com'); $environment->addUrl($url); $portal->addEnvironment($environment); $localizationEnUs = new Localization(); $localizationEnUs->setCountry('us'); $localizationEnUs->setLanguage('en'); $localizationEnUs->setShadow('auto'); $localizationEnUs->setDefault(true); $localizationEnCa = new Localization(); $localizationEnCa->setCountry('ca'); $localizationEnCa->setLanguage('en'); $localizationEnCa->setDefault(false); $localizationEnUs->addChild($localizationEnCa); $localizationFrCa = new Localization(); $localizationFrCa->setCountry('ca'); $localizationFrCa->setLanguage('fr'); $localizationFrCa->setDefault(false); $portal->addLocalization($localizationEnUs); $portal->addLocalization($localizationEnCa); $portal->addLocalization($localizationFrCa); $portal->setDefaultLocalization($localizationEnUs); $portal->setResourceLocatorStrategy('tree'); $webspace = new Webspace(); $webspace->addLocalization($localizationEnUs); $webspace->addLocalization($localizationFrCa); $segmentSummer = new Segment(); $segmentSummer->setName('Summer'); $segmentSummer->setKey('s'); $segmentSummer->setDefault(true); $segmentWinter = new Segment(); $segmentWinter->setName('Winter'); $segmentWinter->setKey('w'); $segmentWinter->setDefault(false); $webspace->addSegment($segmentSummer); $webspace->addSegment($segmentWinter); $webspace->setTheme($theme); $webspace->addPortal($portal); $webspace->setKey('default'); $webspace->setName('Default'); $webspace->addPortal($portal); $webspace->setNavigation(new Navigation([new NavigationContext('main', [])])); $portals[] = $portal; $webspaces[] = $webspace; $portalInformations['prod']['www.portal1.com'] = new PortalInformation(RequestAnalyzerInterface::MATCH_TYPE_FULL, $webspace, $portal, $localizationEnUs, 'www.portal1.com', $segmentSummer); $portalInformations['dev']['portal1.lo'] = new PortalInformation(RequestAnalyzerInterface::MATCH_TYPE_FULL, $webspace, $portal, $localizationEnUs, 'portal1.lo', $segmentSummer); $this->webspaceCollection->setWebspaces($webspaces); $this->webspaceCollection->setPortals($portals); $this->webspaceCollection->setPortalInformations($portalInformations); }