From 06ea58aa4fde0667cef55809fccd4d9ce3fcbd3f Mon Sep 17 00:00:00 2001 From: Leo Feyer Date: Thu, 4 Nov 2021 12:34:14 +0100 Subject: [PATCH] CS --- .../AddCanonicalFieldsListener.php | 9 +++- core-bundle/src/Resources/config/services.yml | 2 +- .../src/Resources/contao/dca/tl_page.php | 50 +++++++++---------- .../Resources/contao/languages/en/tl_page.xlf | 39 ++++++++------- .../src/Resources/contao/models/PageModel.php | 24 ++++----- .../Resources/contao/pages/PageRegular.php | 13 +++-- .../CoreResponseContextFactory.php | 20 +++++--- .../HtmlHeadBag/HtmlHeadBag.php | 6 ++- .../CoreResponseContextFactoryTest.php | 16 +++--- .../HtmlHeadBag/HtmlHeadBagTest.php | 6 +++ 10 files changed, 105 insertions(+), 80 deletions(-) diff --git a/core-bundle/src/EventListener/DataContainer/AddCanonicalFieldsListener.php b/core-bundle/src/EventListener/DataContainer/AddCanonicalFieldsListener.php index aa7686818e0..1cdc91c0e58 100644 --- a/core-bundle/src/EventListener/DataContainer/AddCanonicalFieldsListener.php +++ b/core-bundle/src/EventListener/DataContainer/AddCanonicalFieldsListener.php @@ -32,6 +32,10 @@ public function __construct(ContaoFramework $contaoFramework) public function __invoke(DataContainer $dc): void { + if (!$dc->id) { + return; + } + /** @var PageModel $pageModel */ $pageModel = $this->contaoFramework->getAdapter(PageModel::class); $page = $pageModel->findWithDetails($dc->id); @@ -41,8 +45,9 @@ public function __invoke(DataContainer $dc): void } PaletteManipulator::create() - ->addField('canonicalKeepParams', 'serpPreview') - ->addField('canonicalLink', 'serpPreview') + ->addLegend('canonical_legend', 'meta_legend', PaletteManipulator::POSITION_AFTER, true) + ->addField('canonicalLink', 'canonical_legend', PaletteManipulator::POSITION_APPEND) + ->addField('canonicalKeepParams', 'canonical_legend', PaletteManipulator::POSITION_APPEND) ->applyToPalette('regular', 'tl_page') ; } diff --git a/core-bundle/src/Resources/config/services.yml b/core-bundle/src/Resources/config/services.yml index 2ce40429456..7027fdee777 100644 --- a/core-bundle/src/Resources/config/services.yml +++ b/core-bundle/src/Resources/config/services.yml @@ -716,8 +716,8 @@ services: - '@Contao\CoreBundle\Routing\ResponseContext\ResponseContextAccessor' - '@event_dispatcher' - '@contao.security.token_checker' - - '@contao.framework' - '@Contao\CoreBundle\String\HtmlDecoder' + - '@contao.framework' public: true contao.search.indexer.default: diff --git a/core-bundle/src/Resources/contao/dca/tl_page.php b/core-bundle/src/Resources/contao/dca/tl_page.php index d6c896e5157..df7e7ead740 100644 --- a/core-bundle/src/Resources/contao/dca/tl_page.php +++ b/core-bundle/src/Resources/contao/dca/tl_page.php @@ -180,8 +180,8 @@ 'regular' => '{title_legend},title,alias,type;{meta_legend},pageTitle,robots,description,serpPreview;{protected_legend:hide},protected;{layout_legend:hide},includeLayout;{cache_legend:hide},includeCache;{chmod_legend:hide},includeChmod;{expert_legend:hide},cssClass,sitemap,hide,noSearch,guests,requireItem;{tabnav_legend:hide},tabindex,accesskey;{publish_legend},published,start,stop', 'forward' => '{title_legend},title,alias,type;{meta_legend},pageTitle,robots;{redirect_legend},jumpTo,redirect;{protected_legend:hide},protected;{layout_legend:hide},includeLayout;{cache_legend:hide},includeCache;{chmod_legend:hide},includeChmod;{expert_legend:hide},cssClass,sitemap,hide,guests;{tabnav_legend:hide},tabindex,accesskey;{publish_legend},published,start,stop', 'redirect' => '{title_legend},title,alias,type;{meta_legend},pageTitle,robots;{redirect_legend},redirect,url,target;{protected_legend:hide},protected;{layout_legend:hide},includeLayout;{cache_legend:hide},includeCache;{chmod_legend:hide},includeChmod;{expert_legend:hide},cssClass,sitemap,hide,guests;{tabnav_legend:hide},tabindex,accesskey;{publish_legend},published,start,stop', - 'root' => '{title_legend},title,alias,type;{meta_legend},pageTitle,enableCanonical;{url_legend},dns,useSSL,urlPrefix,urlSuffix,validAliasCharacters,useFolderUrl;{language_legend},language,fallback,disableLanguageRedirect;{global_legend:hide},adminEmail,mailerTransport,dateFormat,timeFormat,datimFormat,staticFiles,staticPlugins;{protected_legend:hide},protected;{layout_legend},includeLayout;{twoFactor_legend:hide},enforceTwoFactor;{cache_legend:hide},includeCache;{chmod_legend:hide},includeChmod;{publish_legend},published,start,stop', - 'rootfallback' => '{title_legend},title,alias,type;{meta_legend},pageTitle,enableCanonical;{url_legend},dns,useSSL,urlPrefix,urlSuffix,validAliasCharacters,useFolderUrl;{language_legend},language,fallback,disableLanguageRedirect;{website_legend:hide},favicon,robotsTxt;{global_legend:hide},adminEmail,mailerTransport,dateFormat,timeFormat,datimFormat,staticFiles,staticPlugins;{protected_legend:hide},protected;{layout_legend},includeLayout;{twoFactor_legend:hide},enforceTwoFactor;{cache_legend:hide},includeCache;{chmod_legend:hide},includeChmod;{publish_legend},published,start,stop', + 'root' => '{title_legend},title,alias,type;{meta_legend},pageTitle;{url_legend},dns,useSSL,urlPrefix,urlSuffix,validAliasCharacters,useFolderUrl;{language_legend},language,fallback,disableLanguageRedirect;{global_legend:hide},mailerTransport,enableCanonical,adminEmail,dateFormat,timeFormat,datimFormat,staticFiles,staticPlugins;{protected_legend:hide},protected;{layout_legend},includeLayout;{twoFactor_legend:hide},enforceTwoFactor;{cache_legend:hide},includeCache;{chmod_legend:hide},includeChmod;{publish_legend},published,start,stop', + 'rootfallback' => '{title_legend},title,alias,type;{meta_legend},pageTitle;{url_legend},dns,useSSL,urlPrefix,urlSuffix,validAliasCharacters,useFolderUrl;{language_legend},language,fallback,disableLanguageRedirect;{website_legend:hide},favicon,robotsTxt;{global_legend:hide},mailerTransport,enableCanonical,adminEmail,dateFormat,timeFormat,datimFormat,staticFiles,staticPlugins;{protected_legend:hide},protected;{layout_legend},includeLayout;{twoFactor_legend:hide},enforceTwoFactor;{cache_legend:hide},includeCache;{chmod_legend:hide},includeChmod;{publish_legend},published,start,stop', 'logout' => '{title_legend},title,alias,type;{forward_legend},jumpTo,redirectBack;{protected_legend:hide},protected;{chmod_legend:hide},includeChmod;{expert_legend:hide},cssClass,sitemap,hide;{tabnav_legend:hide},tabindex,accesskey;{publish_legend},published,start,stop', 'error_401' => '{title_legend},title,alias,type;{meta_legend},pageTitle,robots,description;{forward_legend},autoforward;{layout_legend:hide},includeLayout;{cache_legend:hide},includeCache;{chmod_legend:hide},includeChmod;{expert_legend:hide},cssClass;{publish_legend},published,start,stop', 'error_403' => '{title_legend},title,alias,type;{meta_legend},pageTitle,robots,description;{forward_legend},autoforward;{layout_legend:hide},includeLayout;{cache_legend:hide},includeCache;{chmod_legend:hide},includeChmod;{expert_legend:hide},cssClass;{publish_legend},published,start,stop', @@ -253,14 +253,6 @@ 'eval' => array('maxlength'=>255, 'tl_class'=>'w50'), 'sql' => "varchar(255) NOT NULL default ''" ), - 'enableCanonical' => array - ( - 'exclude' => true, - 'inputType' => 'checkbox', - 'default' => true, - 'eval' => array('tl_class'=>'w50 m12'), - 'sql' => "char(1) NOT NULL default ''" - ), 'language' => array ( 'exclude' => true, @@ -307,21 +299,6 @@ static function ($value) 'eval' => array('url_callback'=>array('tl_page', 'getSerpUrl'), 'title_tag_callback'=>array('tl_page', 'getTitleTag'), 'titleFields'=>array('pageTitle', 'title')), 'sql' => null ), - 'canonicalLink' => array - ( - 'exclude' => true, - 'search' => true, - 'inputType' => 'text', - 'eval' => array('rgxp'=>'url', 'decodeEntities'=>true, 'maxlength'=>255, 'dcaPicker'=>true, 'tl_class'=>'w50'), - 'sql' => "varchar(255) NOT NULL default ''" - ), - 'canonicalKeepParams' => array - ( - 'exclude' => true, - 'inputType' => 'text', - 'eval' => array('decodeEntities'=>true, 'maxlength'=>255, 'tl_class'=>'w50'), - 'sql' => "varchar(255) NOT NULL default ''" - ), 'redirect' => array ( 'exclude' => true, @@ -446,6 +423,29 @@ static function ($value) 'eval' => array('tl_class'=>'w50', 'includeBlankOption'=>true), 'sql' => "varchar(255) NOT NULL default ''" ), + 'enableCanonical' => array + ( + 'exclude' => true, + 'inputType' => 'checkbox', + 'default' => true, + 'eval' => array('tl_class'=>'w50 m12'), + 'sql' => "char(1) NOT NULL default ''" + ), + 'canonicalLink' => array + ( + 'exclude' => true, + 'search' => true, + 'inputType' => 'text', + 'eval' => array('rgxp'=>'url', 'decodeEntities'=>true, 'maxlength'=>255, 'dcaPicker'=>true, 'tl_class'=>'w50'), + 'sql' => "varchar(255) NOT NULL default ''" + ), + 'canonicalKeepParams' => array + ( + 'exclude' => true, + 'inputType' => 'text', + 'eval' => array('decodeEntities'=>true, 'maxlength'=>255, 'tl_class'=>'w50'), + 'sql' => "varchar(255) NOT NULL default ''" + ), 'adminEmail' => array ( 'exclude' => true, diff --git a/core-bundle/src/Resources/contao/languages/en/tl_page.xlf b/core-bundle/src/Resources/contao/languages/en/tl_page.xlf index 7b34c689ddd..a06dbadddef 100644 --- a/core-bundle/src/Resources/contao/languages/en/tl_page.xlf +++ b/core-bundle/src/Resources/contao/languages/en/tl_page.xlf @@ -26,24 +26,6 @@ Please enter the page title. - - Enable rel="canonical" support - - - You can disable built-in rel="canonical" support and take control over it yourself. - - - Manual rel="canonical" selection - - - You can manually select the desired target page for rel="canonical" support. - - - Query parameters to keep for rel="canonical" - - - By default, Contao points to itself for rel="canonical". You may add a comma-separated list of query parameters which should be kept. Use "*" as a wildcard. - Language @@ -128,6 +110,24 @@ Here you can override the mailer transport used to send e-mails on this website. + + Enable rel="canonical" + + + Add rel="canonical" tags to the website. + + + Custom URL + + + Here you can set a custom canonical URL. + + + Query parameters + + + By default, Contao strips the query paramters in the canonical URL. Here you can add a comma-separated list of query parameters to preserve. Use "*" as a wildcard. + E-mail address of the website administrator @@ -344,6 +344,9 @@ Metadata + + Canonical URL + System settings diff --git a/core-bundle/src/Resources/contao/models/PageModel.php b/core-bundle/src/Resources/contao/models/PageModel.php index 2c1ed2906af..e123f32df51 100644 --- a/core-bundle/src/Resources/contao/models/PageModel.php +++ b/core-bundle/src/Resources/contao/models/PageModel.php @@ -50,6 +50,9 @@ * @property string|null $favicon * @property string|null $robotsTxt * @property string $mailerTransport + * @property string|integer $enableCanonical + * @property string $canonicalLink + * @property string $canonicalKeepParams * @property string $adminEmail * @property string $dateFormat * @property string $timeFormat @@ -85,9 +88,6 @@ * @property string|integer $stop * @property string|boolean $enforceTwoFactor * @property string|integer $twoFactorJumpTo - * @property string|integer $enableCanonical - * @property string $canonicalLink - * @property string $canonicalKeepParams * * @property array $trail * @property string $mainAlias @@ -144,6 +144,9 @@ * @method static PageModel|null findOneByFavicon($val, array $opt=array()) * @method static PageModel|null findOneByRobotsTxt($val, array $opt=array()) * @method static PageModel|null findOneByMailerTransport($val, array $opt=array()) + * @method static PageModel|null findOneByEnableCanonical($val, array $opt=array()) + * @method static PageModel|null findOneByCanonicalLink($val, array $opt=array()) + * @method static PageModel|null findOneByCanonicalKeepParams($val, array $opt=array()) * @method static PageModel|null findOneByAdminEmail($val, array $opt=array()) * @method static PageModel|null findOneByDateFormat($val, array $opt=array()) * @method static PageModel|null findOneByTimeFormat($val, array $opt=array()) @@ -176,9 +179,6 @@ * @method static PageModel|null findOneByStop($val, array $opt=array()) * @method static PageModel|null findOneByEnforceTwoFactor($val, array $opt=array()) * @method static PageModel|null findOneByTwoFactorJumpTo($val, array $opt=array()) - * @method static PageModel|null findOneByEnableCanonical($val, array $opt=array()) - * @method static PageModel|null findOneByCanonicalLink($val, array $opt=array()) - * @method static PageModel|null findOneByCanonicalKeepParams($val, array $opt=array()) * * @method static Collection|PageModel[]|PageModel|null findByPid($val, array $opt=array()) * @method static Collection|PageModel[]|PageModel|null findBySorting($val, array $opt=array()) @@ -203,6 +203,9 @@ * @method static Collection|PageModel[]|PageModel|null findByFavicon($val, array $opt=array()) * @method static Collection|PageModel[]|PageModel|null findByRobotsTxt($val, array $opt=array()) * @method static Collection|PageModel[]|PageModel|null findByMailerTransport($val, array $opt=array()) + * @method static Collection|PageModel[]|PageModel|null findByEnableCanonical($val, array $opt=array()) + * @method static Collection|PageModel[]|PageModel|null findByCanonicalLink($val, array $opt=array()) + * @method static Collection|PageModel[]|PageModel|null findByCanonicalKeepParams($val, array $opt=array()) * @method static Collection|PageModel[]|PageModel|null findByAdminEmail($val, array $opt=array()) * @method static Collection|PageModel[]|PageModel|null findByDateFormat($val, array $opt=array()) * @method static Collection|PageModel[]|PageModel|null findByTimeFormat($val, array $opt=array()) @@ -235,9 +238,6 @@ * @method static Collection|PageModel[]|PageModel|null findByStop($val, array $opt=array()) * @method static Collection|PageModel[]|PageModel|null findByEnforceTwoFactor($val, array $opt=array()) * @method static Collection|PageModel[]|PageModel|null findByTwoFactorJumpTo($val, array $opt=array()) - * @method static Collection|PageModel[]|PageModel|null findByEnableCanonical($val, array $opt=array()) - * @method static Collection|PageModel[]|PageModel|null findByCanonicalLink($val, array $opt=array()) - * @method static Collection|PageModel[]|PageModel|null findByCanonicalKeepParams($val, array $opt=array()) * @method static Collection|PageModel[]|PageModel|null findMultipleByIds($val, array $opt=array()) * @method static Collection|PageModel[]|PageModel|null findBy($col, $val, array $opt=array()) * @method static Collection|PageModel[]|PageModel|null findAll(array $opt=array()) @@ -266,6 +266,9 @@ * @method static integer countByFavicon($val, array $opt=array()) * @method static integer countByRobotsTxt($val, array $opt=array()) * @method static integer countByMailerTransport($val, array $opt=array()) + * @method static integer countByEnableCanonical($val, array $opt=array()) + * @method static integer countByCanonicalLink($val, array $opt=array()) + * @method static integer countByCanonicalKeepParams($val, array $opt=array()) * @method static integer countByAdminEmail($val, array $opt=array()) * @method static integer countByDateFormat($val, array $opt=array()) * @method static integer countByTimeFormat($val, array $opt=array()) @@ -298,9 +301,6 @@ * @method static integer countByStop($val, array $opt=array()) * @method static integer countByEnforceTwoFactor($val, array $opt=array()) * @method static integer countByTwoFactorJumpTo($val, array $opt=array()) - * @method static integer countByEnableCanonical($val, array $opt=array()) - * @method static integer countByCanonicalLink($val, array $opt=array()) - * @method static integer countByCanonicalKeepParams($val, array $opt=array()) * * @author Leo Feyer */ diff --git a/core-bundle/src/Resources/contao/pages/PageRegular.php b/core-bundle/src/Resources/contao/pages/PageRegular.php index b47342bd093..28c3e05f406 100644 --- a/core-bundle/src/Resources/contao/pages/PageRegular.php +++ b/core-bundle/src/Resources/contao/pages/PageRegular.php @@ -79,9 +79,10 @@ protected function prepare($objPage) $locale = LocaleUtil::formatAsLocale($objPage->language); $container = System::getContainer(); + $container->get('translator')->setLocale($locale); + $request = $container->get('request_stack')->getCurrentRequest(); $request->setLocale($locale); - $container->get('translator')->setLocale($locale); $this->responseContext = $container->get(CoreResponseContextFactory::class)->createContaoWebpageResponseContext($objPage); @@ -213,21 +214,23 @@ protected function prepare($objPage) } } + $headBag = $this->responseContext->get(HtmlHeadBag::class); + // Set the page title and description AFTER the modules have been generated $this->Template->mainTitle = $objPage->rootPageTitle; - $this->Template->pageTitle = htmlspecialchars($this->responseContext->get(HtmlHeadBag::class)->getTitle()); + $this->Template->pageTitle = htmlspecialchars($headBag->getTitle()); // Remove shy-entities (see #2709) $this->Template->mainTitle = str_replace('[-]', '', $this->Template->mainTitle); $this->Template->pageTitle = str_replace('[-]', '', $this->Template->pageTitle); // Meta robots tag - $this->Template->robots = $this->responseContext->get(HtmlHeadBag::class)->getMetaRobots(); + $this->Template->robots = $headBag->getMetaRobots(); // Canonical if ($objPage->enableCanonical) { - $this->Template->canonical = $this->responseContext->get(HtmlHeadBag::class)->getCanonicalUriForRequest($request); + $this->Template->canonical = $headBag->getCanonicalUriForRequest($request); } // Fall back to the default title tag @@ -238,7 +241,7 @@ protected function prepare($objPage) // Assign the title and description $this->Template->title = strip_tags($this->replaceInsertTags($objLayout->titleTag)); - $this->Template->description = htmlspecialchars($this->responseContext->get(HtmlHeadBag::class)->getMetaDescription()); + $this->Template->description = htmlspecialchars($headBag->getMetaDescription()); // Body onload and body classes $this->Template->onload = trim($objLayout->onload); diff --git a/core-bundle/src/Routing/ResponseContext/CoreResponseContextFactory.php b/core-bundle/src/Routing/ResponseContext/CoreResponseContextFactory.php index 9060d1912cd..601bfbddf16 100644 --- a/core-bundle/src/Routing/ResponseContext/CoreResponseContextFactory.php +++ b/core-bundle/src/Routing/ResponseContext/CoreResponseContextFactory.php @@ -29,16 +29,16 @@ class CoreResponseContextFactory private ResponseContextAccessor $responseContextAccessor; private EventDispatcherInterface $eventDispatcher; private TokenChecker $tokenChecker; - private ContaoFramework $contaoFramework; private HtmlDecoder $htmlDecoder; + private ContaoFramework $contaoFramework; - public function __construct(ResponseContextAccessor $responseContextAccessor, EventDispatcherInterface $eventDispatcher, TokenChecker $tokenChecker, ContaoFramework $contaoFramework, HtmlDecoder $htmlDecoder) + public function __construct(ResponseContextAccessor $responseContextAccessor, EventDispatcherInterface $eventDispatcher, TokenChecker $tokenChecker, HtmlDecoder $htmlDecoder, ContaoFramework $contaoFramework) { $this->responseContextAccessor = $responseContextAccessor; $this->eventDispatcher = $eventDispatcher; $this->tokenChecker = $tokenChecker; - $this->contaoFramework = $contaoFramework; $this->htmlDecoder = $htmlDecoder; + $this->contaoFramework = $contaoFramework; } public function createResponseContext(): ResponseContext @@ -91,17 +91,23 @@ public function createContaoWebpageResponseContext(PageModel $pageModel): Respon } if ($pageModel->enableCanonical && $pageModel->canonicalLink) { - $url = $this->contaoFramework->getAdapter(Controller::class)->replaceInsertTags($pageModel->canonicalLink, false); + // TODO: Replace this with the insert tags service once #3638 has been merged + /** @var Controller $controller */ + $controller = $this->contaoFramework->getAdapter(Controller::class); + $url = $controller->replaceInsertTags($pageModel->canonicalLink, false); - // Ensure absolute links (FIXME: Remove once we remove support for relative urls) + // Ensure absolute links if (!preg_match('#^https?://#', $url)) { - $url = $this->contaoFramework->getAdapter(Environment::class)->get('base').$url; + /** @var Environment $environment */ + $environment = $this->contaoFramework->getAdapter(Environment::class); + $url = $environment->get('base').$url; } + $htmlHeadBag->setCanonicalUri($url); } if ($pageModel->enableCanonical && $pageModel->canonicalKeepParams) { - $htmlHeadBag->setKeepParamsForCanonical(array_map('trim', explode(',', (string) $pageModel->canonicalKeepParams))); + $htmlHeadBag->setKeepParamsForCanonical(array_map('trim', explode(',', $pageModel->canonicalKeepParams))); } $jsonLdManager diff --git a/core-bundle/src/Routing/ResponseContext/HtmlHeadBag/HtmlHeadBag.php b/core-bundle/src/Routing/ResponseContext/HtmlHeadBag/HtmlHeadBag.php index 197926f6f82..4b65784883d 100644 --- a/core-bundle/src/Routing/ResponseContext/HtmlHeadBag/HtmlHeadBag.php +++ b/core-bundle/src/Routing/ResponseContext/HtmlHeadBag/HtmlHeadBag.php @@ -108,10 +108,12 @@ public function getCanonicalUriForRequest(Request $request): string } } - return Request::create( + $request = Request::create( $request->getSchemeAndHttpHost().$request->getBaseUrl().$request->getPathInfo(), $request->getMethod(), $params - )->getUri(); + ); + + return $request->getUri(); } } diff --git a/core-bundle/tests/Routing/ResponseContext/CoreResponseContextFactoryTest.php b/core-bundle/tests/Routing/ResponseContext/CoreResponseContextFactoryTest.php index b5ed920b5d4..79510432e8f 100644 --- a/core-bundle/tests/Routing/ResponseContext/CoreResponseContextFactoryTest.php +++ b/core-bundle/tests/Routing/ResponseContext/CoreResponseContextFactoryTest.php @@ -43,8 +43,8 @@ public function testResponseContext(): void $responseAccessor, $this->createMock(EventDispatcherInterface::class), $this->createMock(TokenChecker::class), - $this->createMock(ContaoFramework::class), - new HtmlDecoder() + new HtmlDecoder(), + $this->createMock(ContaoFramework::class) ); $responseContext = $factory->createResponseContext(); @@ -64,8 +64,8 @@ public function testWebpageResponseContext(): void $responseAccessor, $this->createMock(EventDispatcherInterface::class), $this->createMock(TokenChecker::class), - $this->createMock(ContaoFramework::class), - new HtmlDecoder() + new HtmlDecoder(), + $this->createMock(ContaoFramework::class) ); $responseContext = $factory->createWebpageResponseContext(); @@ -135,8 +135,8 @@ public function testContaoWebpageResponseContext(): void $responseAccessor, $this->createMock(EventDispatcherInterface::class), $this->createMock(TokenChecker::class), - $contaoFramework, - new HtmlDecoder() + new HtmlDecoder(), + $contaoFramework ); $responseContext = $factory->createContaoWebpageResponseContext($pageModel); @@ -181,8 +181,8 @@ public function testDecodingAndCleanupOnContaoResponseContext(): void $this->createMock(ResponseContextAccessor::class), $this->createMock(EventDispatcherInterface::class), $this->createMock(TokenChecker::class), - $this->createMock(ContaoFramework::class), - new HtmlDecoder() + new HtmlDecoder(), + $this->createMock(ContaoFramework::class) ); $responseContext = $factory->createContaoWebpageResponseContext($pageModel); diff --git a/core-bundle/tests/Routing/ResponseContext/HtmlHeadBag/HtmlHeadBagTest.php b/core-bundle/tests/Routing/ResponseContext/HtmlHeadBag/HtmlHeadBagTest.php index 515723113b4..03d4ad30b27 100644 --- a/core-bundle/tests/Routing/ResponseContext/HtmlHeadBag/HtmlHeadBagTest.php +++ b/core-bundle/tests/Routing/ResponseContext/HtmlHeadBag/HtmlHeadBagTest.php @@ -36,19 +36,24 @@ public function testHeadManagerBasics(): void public function testCanonicalHandling(): void { $manager = new HtmlHeadBag(); + $this->assertSame([], $manager->getKeepParamsForCanonical()); $manager->addKeepParamsForCanonical('page'); $manager->addKeepParamsForCanonical('page2'); + $this->assertSame(['page', 'page2'], $manager->getKeepParamsForCanonical()); $manager->setKeepParamsForCanonical(['foo', 'page']); + $this->assertSame(['foo', 'page'], $manager->getKeepParamsForCanonical()); $request = Request::create('https://contao.org/foobar/page?query=test&foo=bar&baz=bak&page=12'); + $this->assertSame('https://contao.org/foobar/page?foo=bar&page=12', $manager->getCanonicalUriForRequest($request)); $manager->setCanonicalUri('https://example.com/i-decided-myself?page=23&foo=bar'); + $this->assertSame('https://example.com/i-decided-myself?page=23&foo=bar', $manager->getCanonicalUri()); $this->assertSame('https://example.com/i-decided-myself?foo=bar&page=23', $manager->getCanonicalUriForRequest($request)); } @@ -59,6 +64,7 @@ public function testCanonicalWithWildCards(): void $manager->setKeepParamsForCanonical(['foo', 'page_*']); $request = Request::create('https://contao.org/foobar/page?query=test&foo=bar&baz=bak&page_42=12'); + $this->assertSame('https://contao.org/foobar/page?foo=bar&page_42=12', $manager->getCanonicalUriForRequest($request)); } }