setKey() public method

Sets the key of the webspace.
public setKey ( string $key )
$key string
Example #1
0
 /**
  * Parses the entire file and returns a webspace object.
  *
  * @param $file
  *
  * @return Webspace
  */
 protected function parseXml($file)
 {
     $this->xpath = new \DOMXPath($this->tryLoad($file));
     $this->xpath->registerNamespace('x', 'http://schemas.sulu.io/webspace/webspace');
     // set simple webspace properties
     $this->webspace = new Webspace();
     $this->webspace->setName($this->xpath->query('/x:webspace/x:name')->item(0)->nodeValue);
     $this->webspace->setKey($this->xpath->query('/x:webspace/x:key')->item(0)->nodeValue);
     $this->webspace->setTheme($this->generateTheme());
     $this->webspace->setNavigation($this->generateNavigation());
     $this->webspace->setResourceLocatorStrategy('tree_leaf_edit');
     $this->generateTemplates($this->webspace);
     $this->generateDefaultTemplates($this->webspace);
     // set security
     $this->generateSecurity();
     // set localizations on webspaces
     $this->generateWebspaceLocalizations();
     // set segments on webspaces
     $this->generateSegments();
     // set portals on webspaces
     $this->generatePortals();
     // validate the webspace, and throw exceptions if not valid
     $this->validate();
     return $this->webspace;
 }
 public function testResolve()
 {
     $webspace = new Webspace();
     $webspace->setKey('sulu_io');
     $portal = new Portal();
     $locale = new Localization();
     $locale->setLanguage('de');
     $locale->setDefault(true);
     $portal->addLocalization($locale);
     $localization = new Localization();
     $localization->setLanguage('de');
     $localization->setCountry('at');
     $requestAnalyzer = $this->prophesize('Sulu\\Component\\Webspace\\Analyzer\\WebsiteRequestAnalyzer');
     $requestAnalyzer->getWebspace()->willReturn($webspace);
     $requestAnalyzer->getCurrentLocalization()->willReturn($localization);
     $requestAnalyzer->getPortalUrl()->willReturn('sulu.io/de');
     $requestAnalyzer->getResourceLocatorPrefix()->willReturn('/de');
     $requestAnalyzer->getResourceLocator()->willReturn('/search');
     $requestAnalyzer->getGetParameters()->willReturn(['p' => 1]);
     $requestAnalyzer->getPostParameters()->willReturn([]);
     $requestAnalyzer->getPortal()->willReturn($portal);
     $requestAnalyzer->getAnalyticsKey()->willReturn('analyticsKey');
     $result = $this->resolver->resolve($requestAnalyzer->reveal());
     $this->assertEquals(['request' => ['webspaceKey' => 'sulu_io', 'locale' => 'de_at', 'defaultLocale' => 'de', 'portalUrl' => 'sulu.io/de', 'resourceLocatorPrefix' => '/de', 'resourceLocator' => '/search', 'get' => ['p' => 1], 'post' => [], 'analyticsKey' => 'analyticsKey']], $result);
 }
Example #3
0
 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);
 }
Example #4
0
 protected function prepareWebspaceManager()
 {
     if ($this->webspaceManager !== null) {
         return;
     }
     $this->webspace = new Webspace();
     $this->webspace->setKey('sulu_io');
     $local1 = new Localization();
     $local1->setLanguage('en');
     $local2 = new Localization();
     $local2->setLanguage('en');
     $local2->setCountry('us');
     $this->webspace->setLocalizations([$local1, $local2]);
     $this->webspace->setName('Default');
     $theme = new Theme();
     $theme->setKey('test');
     $theme->addDefaultTemplate('page', 'default');
     $this->webspace->setTheme($theme);
     $this->webspace->setNavigation(new Navigation([new NavigationContext('main', []), new NavigationContext('footer', [])]));
     $this->webspaceManager = $this->getMock('Sulu\\Component\\Webspace\\Manager\\WebspaceManagerInterface');
     $this->webspaceManager->expects($this->any())->method('findWebspaceByKey')->will($this->returnValue($this->webspace));
 }
 protected function setUp()
 {
     parent::setUp();
     $this->requestAnalyzer = $this->prophesize(RequestAnalyzerInterface::class);
     $webspace = new Webspace();
     $webspace->setKey('sulu_test');
     $locale = new Localization();
     $locale->setLanguage('en');
     $portal = new Portal();
     $portal->setDefaultLocalization($locale);
     $this->requestAnalyzer->getWebspace()->willReturn($webspace);
     $this->requestAnalyzer->getPortal()->willReturn($portal);
     $this->requestAnalyzer->getCurrentLocalization()->willReturn($locale);
     $this->contentPath = $this->prophesize(ContentPathInterface::class);
     $this->contentPath->getContentPath('/test', 'sulu_test', 'de')->willReturn('/de/test');
     $this->contentPath->getContentPath('/test-en', 'sulu_test', 'en')->willReturn('/en/test-en');
     $this->contentPath->getContentPath('/test-en-us', 'sulu_test', 'en-us')->willReturn('/en/test-en-us');
     $this->contentPath->getContentPath('/test-en-us', 'sulu_test', 'en_us')->willReturn('/en/test-en-us');
     $this->contentPath->getContentPath('/test-fr', 'sulu_test', 'fr')->willReturn('/fr/test-fr');
 }
Example #6
0
 /**
  * @param $file
  *
  * @return Portal
  */
 private function parseXml($file)
 {
     // load xml file
     $xmlDoc = XmlUtils::loadFile($file, __DIR__ . static::SCHEME_PATH);
     $this->xpath = new \DOMXPath($xmlDoc);
     $this->xpath->registerNamespace('x', 'http://schemas.sulu.io/webspace/webspace');
     // set simple webspace properties
     $this->webspace = new Webspace();
     $this->webspace->setName($this->xpath->query('/x:webspace/x:name')->item(0)->nodeValue);
     $this->webspace->setKey($this->xpath->query('/x:webspace/x:key')->item(0)->nodeValue);
     $this->webspace->setTheme($this->generateTheme());
     $this->webspace->setNavigation($this->generateNavigation());
     // set security
     $this->generateSecurity();
     // set localizations on webspaces
     $this->generateWebspaceLocalizations();
     // set segments on webspaces
     $this->generateSegments();
     // set portals on webspaces
     $this->generatePortals();
     // validate the webspace, and throw exceptions if not valid
     $this->validate();
     return $this->webspace;
 }
 protected function setUp()
 {
     parent::setUp();
     $this->contentMapper = $this->prophesize('Sulu\\Component\\Content\\Mapper\\ContentMapperInterface');
     $this->requestAnalyzer = $this->prophesize('Sulu\\Component\\Webspace\\Analyzer\\RequestAnalyzerInterface');
     $this->contentTypeManager = $this->prophesize('Sulu\\Component\\Content\\ContentTypeManagerInterface');
     $this->structureManager = $this->prophesize('Sulu\\Component\\Content\\Compat\\StructureManagerInterface');
     $this->sessionManager = $this->prophesize('Sulu\\Component\\PHPCR\\SessionManager\\SessionManagerInterface');
     $this->session = $this->prophesize('PHPCR\\SessionInterface');
     $this->node = $this->prophesize('PHPCR\\NodeInterface');
     $this->parentNode = $this->prophesize('PHPCR\\NodeInterface');
     $this->startPageNode = $this->prophesize('PHPCR\\NodeInterface');
     $webspace = new Webspace();
     $webspace->setKey('sulu_test');
     $locale = new Localization();
     $locale->setCountry('us');
     $locale->setLanguage('en');
     $this->requestAnalyzer->getWebspace()->willReturn($webspace);
     $this->requestAnalyzer->getCurrentLocalization()->willReturn($locale);
     $this->contentTypeManager->get('text_line')->willReturn(new TextLine(''));
     $this->sessionManager->getSession()->willReturn($this->session->reveal());
     $this->sessionManager->getContentNode('sulu_test')->willReturn($this->startPageNode->reveal());
     $this->session->getNodeByIdentifier('123-123-123')->willReturn($this->node->reveal());
     $this->session->getNodeByIdentifier('321-321-321')->willReturn($this->parentNode->reveal());
     $this->node->getIdentifier()->willReturn('123-123-123');
     $this->node->getParent()->willReturn($this->parentNode->reveal());
     $this->node->getDepth()->willReturn(4);
     $this->parentNode->getIdentifier()->willReturn('321-321-321');
     $this->parentNode->getDepth()->willReturn(3);
     $this->startPageNode->getDepth()->willReturn(3);
     $this->structureResolver = new StructureResolver($this->contentTypeManager->reveal(), $this->structureManager->reveal());
 }
Example #8
0
 /**
  * @dataProvider provideAnalyzeWithFormat
  */
 public function testAnalyzeWithFormat($config, $expected = [])
 {
     $webspace = new Webspace();
     $webspace->setKey('sulu');
     $portal = new Portal();
     $portal->setKey('sulu');
     $localization = new Localization();
     $localization->setCountry('at');
     $localization->setLanguage('de');
     $portalInformation = new PortalInformation($config['match_type'], $webspace, $portal, $localization, $config['portal_url'], null, $config['redirect']);
     $this->prepareWebspaceManager($portalInformation);
     $requestFormat = false;
     $request = $this->getMock('\\Symfony\\Component\\HttpFoundation\\Request');
     $request->request = new ParameterBag(['post' => 1]);
     $request->query = new ParameterBag(['get' => 1]);
     $request->expects($this->any())->method('getHost')->will($this->returnValue('sulu.lo'));
     $request->expects($this->any())->method('getPathInfo')->will($this->returnValue($config['path_info']));
     $request->expects($this->once())->method('setLocale')->with('de_at');
     if ($expected['format']) {
         $request->expects($this->once())->method('setRequestFormat')->will($this->returnCallback(function ($format) use(&$requestFormat) {
             $requestFormat = $format;
         }));
     }
     $request->expects($this->once())->method('getRequestFormat')->will($this->returnCallback(function () use(&$requestFormat) {
         return $requestFormat;
     }));
     $this->requestAnalyzer->analyze($request);
     $this->assertEquals('de_at', $this->requestAnalyzer->getCurrentLocalization()->getLocalization());
     $this->assertEquals('sulu', $this->requestAnalyzer->getWebspace()->getKey());
     $this->assertEquals('sulu', $this->requestAnalyzer->getPortal()->getKey());
     $this->assertEquals(null, $this->requestAnalyzer->getSegment());
     $this->assertEquals($expected['portal_url'], $this->requestAnalyzer->getPortalUrl());
     $this->assertEquals($expected['redirect'], $this->requestAnalyzer->getRedirect());
     $this->assertEquals($expected['resource_locator'], $this->requestAnalyzer->getResourceLocator());
     $this->assertEquals($expected['resource_locator_prefix'], $this->requestAnalyzer->getResourceLocatorPrefix());
     $this->assertEquals($expected['format'], $request->getRequestFormat());
     $this->assertEquals(['post' => 1], $this->requestAnalyzer->getPostParameters());
     $this->assertEquals(['get' => 1], $this->requestAnalyzer->getGetParameters());
 }
Example #9
0
 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);
 }