/**
  * @param Webspace $webspace
  * @param Portal   $portal
  */
 public function __construct(Webspace $webspace, Portal $portal)
 {
     $this->webspace = $webspace;
     $this->portal = $portal;
     $message = 'The portal "' . $portal->getKey() . '" in the webspace definition "' . $webspace->getKey() . '" ' . 'has multiple default localizations';
     parent::__construct($message, 0);
 }
Esempio n. 2
0
 public function testLoad()
 {
     $importedRouteCollection = new RouteCollection();
     $importedRouteCollection->add('route1', new Route('/example/route1'));
     $importedRouteCollection->add('route2', new Route('/route2'));
     $portal1 = new Portal();
     $portal1->setKey('sulu_lo');
     $portal2 = new Portal();
     $portal2->setKey('sulu_com');
     $portalInformations = [new PortalInformation(null, null, $portal1, null, 'sulu.io/de'), new PortalInformation(null, null, $portal2, null, 'sulu.com')];
     $this->loaderResolver->resolve(Argument::any(), Argument::any())->willReturn($this->loader->reveal());
     $this->loader->load(Argument::any(), Argument::any())->willReturn($importedRouteCollection);
     $this->webspaceManager->getPortalInformations(Argument::any())->willReturn($portalInformations);
     $routeCollection = $this->portalLoader->load('', 'portal');
     $this->assertCount(4, $routeCollection);
     $routes = $routeCollection->getIterator();
     $this->assertArrayHasKey('sulu.io/de.route1', $routes);
     $this->assertArrayHasKey('sulu.io/de.route2', $routes);
     $this->assertArrayHasKey('sulu.com.route1', $routes);
     $this->assertArrayHasKey('sulu.com.route2', $routes);
     $this->assertEquals('/de/example/route1', $routeCollection->get('sulu.io/de.route1')->getPath());
     $this->assertEquals('/de/route2', $routeCollection->get('sulu.io/de.route2')->getPath());
     $this->assertEquals('/example/route1', $routeCollection->get('sulu.com.route1')->getPath());
     $this->assertEquals('/route2', $routeCollection->get('sulu.com.route2')->getPath());
 }
 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);
 }
 /**
  * @param Webspace $webspace
  * @param Portal   $portal
  */
 public function __construct(Webspace $webspace, Portal $portal)
 {
     $this->webspace = $webspace;
     $this->portal = $portal;
     $message = 'The portal "' . $portal->getKey() . '" in the webspace definition "' . $webspace->getKey() . '" ' . 'has not specified the required attributes (a default localization)';
     parent::__construct($message, 0);
 }
Esempio n. 5
0
 /**
  * Test get alternate links.
  */
 public function testGetAlternateLinksDifferentDefaultLocale()
 {
     $locale = new Localization();
     $locale->setLanguage('de');
     $this->portal->setXDefaultLocalization($locale);
     $extension = new MetaTwigExtension($this->requestAnalyzer->reveal(), $this->contentPath->reveal());
     $urls = $extension->getAlternateLinks(['de' => '/test', 'en' => '/test-en', 'en-us' => '/test-en-us', 'fr' => '/test-fr']);
     $this->assertEquals(['<link rel="alternate" href="/de/test" hreflang="x-default" />', '<link rel="alternate" href="/de/test" hreflang="de" />', '<link rel="alternate" href="/en/test-en" hreflang="en" />', '<link rel="alternate" href="/en/test-en-us" hreflang="en-us" />', '<link rel="alternate" href="/fr/test-fr" hreflang="fr" />'], explode(PHP_EOL, $urls));
 }
Esempio n. 6
0
 /**
  * {@inheritdoc}
  */
 public function renderSitemap($alias, $page, $locale, Portal $portal, $host, $scheme)
 {
     if (!$this->sitemapProviderPool->hasProvider($alias)) {
         return;
     }
     $provider = $this->sitemapProviderPool->getProvider($alias);
     if ($provider->getMaxPage() < $page) {
         return;
     }
     $entries = $provider->build($page, $portal->getKey(), $locale);
     return $this->render('SuluWebsiteBundle:Sitemap:sitemap.xml.twig', ['webspaceKey' => $portal->getWebspace()->getKey(), 'locale' => $locale, 'defaultLocale' => $portal->getXDefaultLocalization()->getLocale(), 'domain' => $host, 'scheme' => $scheme, 'entries' => $entries]);
 }
Esempio n. 7
0
 /**
  * Returns key of portal.
  */
 public function getPortalKey()
 {
     if (null === $this->portal) {
         return;
     }
     return $this->portal->getKey();
 }
Esempio n. 8
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);
 }
Esempio n. 9
0
 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');
 }
 public function __construct(Portal $portal, $environment)
 {
     parent::__construct(sprintf('The environment "%s" could not be found in the portal "%s".', $environment, $portal->getKey()));
     $this->portal = $portal;
     $this->environment = $environment;
 }
Esempio n. 11
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());
 }
Esempio n. 12
0
 /**
  * @param Portal $portal
  * @param Environment $environment
  * @param string $urlAddress
  * @param string $urlAnalyticsKey
  * @param Url $url
  */
 private function buildUrlPartialMatch(Portal $portal, Environment $environment, $urlAddress, $urlAnalyticsKey, Url $url)
 {
     $replacers = [];
     $defaultSegment = $portal->getWebspace()->getDefaultSegment();
     if ($defaultSegment) {
         $replacers[ReplacerInterface::REPLACER_SEGMENT] = $defaultSegment->getKey();
     }
     $urlResult = $this->urlReplacer->cleanup($urlAddress, [ReplacerInterface::REPLACER_LANGUAGE, ReplacerInterface::REPLACER_COUNTRY, ReplacerInterface::REPLACER_LOCALIZATION, ReplacerInterface::REPLACER_SEGMENT]);
     $urlRedirect = $this->generateUrlAddress($urlAddress, $replacers);
     if ($this->validateUrlPartialMatch($urlResult, $environment)) {
         $this->portalInformations[$environment->getType()][$urlResult] = new PortalInformation(RequestAnalyzerInterface::MATCH_TYPE_PARTIAL, $portal->getWebspace(), $portal, null, $urlResult, $portal->getWebspace()->getDefaultSegment(), $urlRedirect, $urlAnalyticsKey, false, $url->getUrl(), $this->urlReplacer->hasHostReplacer($urlResult) ? 4 : 9);
     }
 }
Esempio n. 13
0
 /**
  * Generates the definitions for the available environments for this webspace.
  *
  * @param \DOMNode $portalNode
  * @param Portal $portal
  */
 protected function generateEnvironments(\DOMNode $portalNode, Portal $portal)
 {
     foreach ($this->xpath->query('x:environments/x:environment', $portalNode) as $environmentNode) {
         /** @var \DOMNode $environmentNode */
         $environment = new Environment();
         $environment->setType($environmentNode->attributes->getNamedItem('type')->nodeValue);
         $this->generateUrls($environmentNode, $environment);
         $this->generateCustomUrls($environmentNode, $environment);
         $portal->addEnvironment($environment);
     }
 }
 /**
  * Returns custom-url data with the connected locales.
  *
  * @param Portal $portal
  * @param Environment $environment
  * @param Context $context
  *
  * @return array
  */
 private function getCustomUrlsForEnvironment(Portal $portal, Environment $environment, Context $context)
 {
     $customUrls = [];
     foreach ($environment->getCustomUrls() as $customUrl) {
         $customUrl = $context->accept($customUrl);
         $customUrl['locales'] = $context->accept($portal->getLocalizations());
         $customUrls[] = $customUrl;
     }
     return $customUrls;
 }
Esempio n. 15
0
 /**
  * @param Portal      $portal
  * @param Environment $environment
  * @param string      $urlAddress
  * @param string      $urlAnalyticsKey
  */
 private function buildUrlPartialMatch(Portal $portal, Environment $environment, $urlAddress, $urlAnalyticsKey)
 {
     $replacers = [self::REPLACER_LANGUAGE => $portal->getDefaultLocalization()->getLanguage(), self::REPLACER_COUNTRY => $portal->getDefaultLocalization()->getCountry(), self::REPLACER_LOCALIZATION => $portal->getDefaultLocalization()->getLocalization('-')];
     $defaultSegment = $portal->getWebspace()->getDefaultSegment();
     if ($defaultSegment) {
         $replacers[self::REPLACER_SEGMENT] = $defaultSegment->getKey();
     }
     $urlResult = $this->removeUrlPlaceHolders($urlAddress);
     $urlRedirect = $this->generateUrlAddress($urlAddress, $replacers);
     if ($this->validateUrlPartialMatch($urlResult, $environment)) {
         $this->portalInformations[$environment->getType()][$urlResult] = new PortalInformation(RequestAnalyzerInterface::MATCH_TYPE_PARTIAL, $portal->getWebspace(), $portal, $portal->getDefaultLocalization(), $urlResult, $portal->getWebspace()->getDefaultSegment(), $urlRedirect, $urlAnalyticsKey);
     }
 }
Esempio n. 16
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);
 }
Esempio n. 17
0
 public function testGetCollectionMovedResourceLocator()
 {
     // Set up test
     $path = '/qwertz/';
     $prefix = '/de';
     $uuid = 1;
     $portal = new Portal();
     $portal->setKey('portal');
     $theme = new Theme();
     $theme->setKey('theme');
     $webspace = new Webspace();
     $webspace->setTheme($theme);
     $portal->setWebspace($webspace);
     $localization = new Localization();
     $localization->setLanguage('de');
     $structure = $this->getStructureMock($uuid);
     $requestAnalyzer = $this->getRequestAnalyzerMock($portal, $path, $prefix, $localization, RequestAnalyzerInterface::MATCH_TYPE_FULL, 'sulu.lo', 'sulu.lo/en-us');
     $activeTheme = $this->getActiveThemeMock();
     $contentMapper = $this->getContentMapperMock();
     $contentMapper->expects($this->any())->method('loadByResourceLocator')->will($this->throwException(new ResourceLocatorMovedException('/new-test', '123-123-123')));
     $portalRouteProvider = new ContentRouteProvider($contentMapper, $requestAnalyzer, $activeTheme);
     $request = $this->getRequestMock($path);
     // Test the route provider
     $routes = $portalRouteProvider->getRouteCollectionForRequest($request);
     $this->assertCount(1, $routes);
     $route = $routes->getIterator()->current();
     $this->assertEquals('SuluWebsiteBundle:Default:redirect', $route->getDefaults()['_controller']);
     $this->assertEquals('/de/new-test', $route->getDefaults()['url']);
 }
 public function __construct(Portal $portal, $locale)
 {
     parent::__construct(sprintf('The locale "%s" could not be found in the portal "%s".', $locale, $portal->getKey()));
     $this->portal = $portal;
     $this->locale = $locale;
 }