[BUGFIX] Use PageTitle API for indexed_search 54/60354/7
authorJonas Schwabe <jonas.schwabe@eyeworkers.de>
Fri, 29 Mar 2019 16:52:11 +0000 (17:52 +0100)
committerRichard Haeser <richard@maxserv.com>
Wed, 10 Apr 2019 09:04:49 +0000 (11:04 +0200)
The value of indexedDocTitle was not updated when a title had been
generated by the PageTitle API. This simply writes the generated
page title to indexedDocTitle so that it can be used in the
indexed hook.

Resolves: #88041
Releases: master, 9.5
Change-Id: I8ac1fd8295447aafa7e175fb09fa11f565442019
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/60354
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Richard Haeser <richard@maxserv.com>
Tested-by: Oliver Klee <typo3-coding@oliverklee.de>
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Richard Haeser <richard@maxserv.com>
typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php
typo3/sysext/frontend/Tests/Unit/Controller/TypoScriptFrontendControllerTest.php

index aecb333..6f57720 100644 (file)
@@ -2828,6 +2828,10 @@ class TypoScriptFrontendController implements LoggerAwareInterface
         $titleProvider = GeneralUtility::makeInstance(PageTitleProviderManager::class);
         $pageTitle = $titleProvider->getTitle();
 
+        if ($pageTitle !== '') {
+            $this->indexedDocTitle = $pageTitle;
+        }
+
         $titleTagContent = $this->printTitle(
             $pageTitle,
             (bool)($this->config['config']['noPageTitle'] ?? false),
index f8f69c5..f18e0f2 100644 (file)
@@ -15,9 +15,13 @@ namespace TYPO3\CMS\Frontend\Tests\Unit\Controller;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Cache\Backend\NullBackend;
+use TYPO3\CMS\Core\Cache\CacheManager;
 use TYPO3\CMS\Core\Context\Context;
 use TYPO3\CMS\Core\Http\ServerRequestFactory;
 use TYPO3\CMS\Core\Page\PageRenderer;
+use TYPO3\CMS\Core\PageTitle\PageTitleProviderManager;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
 use TYPO3\CMS\Frontend\Page\PageRepository;
 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
@@ -470,4 +474,26 @@ class TypoScriptFrontendControllerTest extends UnitTestCase
         $this->assertEquals('[[:space:]]stop[[:space:]]|[[:space:]]word[[:space:]]', $subject->sWordRegEx);
         $this->assertEquals(['stop', 'word'], $subject->sWordList);
     }
+
+    /**
+     * @test
+     * @see https://forge.typo3.org/issues/88041
+     */
+    public function indexedSearchHookUsesPageTitleApi(): void
+    {
+        $pageTitle = 'This is a test page title coming from PageTitleProviderManager';
+
+        $pageTitleProvider = $this->prophesize(PageTitleProviderManager::class);
+        $pageTitleProvider->getTitle()->willReturn($pageTitle);
+        GeneralUtility::setSingletonInstance(PageTitleProviderManager::class, $pageTitleProvider->reveal());
+
+        $nullCacheBackend = new NullBackend('');
+        $cacheManager = $this->prophesize(CacheManager::class);
+        $cacheManager->getCache('cache_pages')->willReturn($nullCacheBackend);
+        GeneralUtility::setSingletonInstance(CacheManager::class, $cacheManager->reveal());
+
+        $subject = new TypoScriptFrontendController(null, 1, 0);
+        $subject->generatePageTitle();
+        $this->assertSame($pageTitle, $subject->indexedDocTitle);
+    }
 }