Exemple #1
0
 /**
  * Renders the canonical tag for the current page. Uses the value provided by the SEO extension. If the SEO
  * extension does not provide a value, it checks if the current page is a shadow, and writes the correct canonical
  * tag automatically.
  *
  * @param array $seoExtension The values delivered by the SEO extension of Sulu
  * @param string[] $urls All the localized URLs for the current page
  * @param string $shadowBaseLocale The displayed language, in case the current page is a shadow
  * @param string $webspaceKey The key of the current webspace
  *
  * @return string The rendered canonical link tag
  */
 private function renderCanonicalTag(array $seoExtension, array $urls, $shadowBaseLocale, $webspaceKey)
 {
     $canonicalTagHtml = '<link rel="canonical" href="%s"/>' . PHP_EOL;
     if (isset($seoExtension['canonicalUrl']) && $seoExtension['canonicalUrl'] !== '') {
         return sprintf($canonicalTagHtml, $seoExtension['canonicalUrl']);
     }
     if ($shadowBaseLocale && isset($urls[$shadowBaseLocale])) {
         return sprintf($canonicalTagHtml, $this->contentPath->getContentPath($urls[$shadowBaseLocale], $webspaceKey, $shadowBaseLocale));
     }
     return '';
 }
 /**
  * @dataProvider provideSeoData
  *
  * @param $seoExtension
  * @param $content
  * @param $urls
  * @param $defaultLocale
  * @param $shadowBaseLocale
  * @param $expectedResults
  * @param array $unexpectedResults
  */
 public function testRenderSeoTags($seoExtension, $content, $urls, $defaultLocale, $shadowBaseLocale, $expectedResults, $unexpectedResults = [])
 {
     /** @var Localization $localization */
     $localization = $this->prophesize(Localization::class);
     $localization->getLocalization()->willReturn($defaultLocale);
     /** @var Portal $portal */
     $portal = $this->prophesize(Portal::class);
     $portal->getDefaultLocalization()->willReturn($localization->reveal());
     $this->requestAnalyzer->getPortal()->willReturn($portal->reveal());
     $webspace = $this->prophesize(Webspace::class);
     $this->requestAnalyzer->getWebspace()->willReturn($webspace);
     $this->contentPath->getContentPath(Argument::cetera())->will(function ($arguments) {
         return '/' . str_replace('_', '-', $arguments[2]) . $arguments[0];
     });
     $result = $this->seoTwigExtension->renderSeoTags($seoExtension, $content, $urls, $shadowBaseLocale);
     foreach ($expectedResults as $expectedResult) {
         $this->assertContains($expectedResult, $result);
     }
     foreach ($unexpectedResults as $unexpectedResult) {
         $this->assertNotContains($unexpectedResult, $result);
     }
 }
Exemple #3
0
 /**
  * Returns link-alternate html tag
  *  - e.g. <link rel="alternate" href="http://sulu.lo/de/test-url" hreflang="de" />.
  *
  * @param string $url
  * @param string $webspaceKey
  * @param string $locale
  * @param bool $default
  *
  * @return string
  */
 private function getAlternate($url, $webspaceKey, $locale, $default = false)
 {
     $url = $this->contentPath->getContentPath($url, $webspaceKey, $locale);
     return sprintf('<link rel="alternate" href="%s" hreflang="%s" />', $url, !$default ? str_replace('_', '-', $locale) : 'x-default');
 }
 /**
  * Seo titel.
  */
 public function testGetSeoMetaTagsFallback()
 {
     $extension = new MetaTwigExtension($this->requestAnalyzer->reveal(), $this->contentPath->reveal());
     $metaTags = $extension->getSeoMetaTags(['seo' => ['title' => 'SEO Title', 'noIndex' => false, 'noFollow' => false, 'keywords' => 'SEO, Keywords'], 'excerpt' => ['description' => 'Excerpt Description']], ['title' => 'Page Title']);
     $this->assertEquals(['<meta name="description" content="Excerpt Description">', '<meta name="keywords" content="SEO, Keywords">', '<meta name="robots" content="INDEX, FOLLOW">'], explode(PHP_EOL, $metaTags));
 }