Commit 709deb86 authored by Benni Mack's avatar Benni Mack
Browse files

[TASK] Ensure tests for extensions work

This change makes some FE calls easier for testing
in extensions, such as EXT:solr.

Resolves: #96050
Releases: master, 11.5
Change-Id: I3482ac0abe4e813ff5cba795da9b730ee0efbdee
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/72249

Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Rafael Kähm's avatarRafael Kähm <rafael.kaehm@dkd.de>
Tested-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Rafael Kähm's avatarRafael Kähm <rafael.kaehm@dkd.de>
Reviewed-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
parent 715d2c47
Pipeline #19691 passed with stages
in 37 minutes and 40 seconds
......@@ -19,6 +19,7 @@ namespace TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Transform;
use TYPO3\CMS\Core\Core\SystemEnvironmentBuilder;
use TYPO3\CMS\Core\Http\ServerRequest;
use TYPO3\CMS\Core\Site\Entity\NullSite;
use TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait;
use TYPO3\CMS\Fluid\View\StandaloneView;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
......@@ -43,8 +44,13 @@ class HtmlViewHelperTest extends FunctionalTestCase
[$this->buildDefaultLanguageConfiguration('EN', '/')]
);
$GLOBALS['TYPO3_REQUEST'] = (new ServerRequest('https://typo3.localhost/', 'GET'))
->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_BE);
// A nullsite is used, so PageLinkBuilder does not "detect" the default site (from TSFE) as the same
// site making all links absolute for our tests
$rootPageSite = new NullSite();
$GLOBALS['TYPO3_REQUEST'] = (new ServerRequest('https://typo3-2.localhost/', 'GET'))
->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_BE)
->withAttribute('site', $rootPageSite)
->withAttribute('language', $rootPageSite->getDefaultLanguage());
}
public static function isTransformedDataProvider(): array
......
......@@ -6798,9 +6798,10 @@ class ContentObjectRenderer implements LoggerAwareInterface
}
/**
* @return \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
* @return TypoScriptFrontendController|null
* @internal this is set to public so extensions such as EXT:solr can use the method in tests.
*/
protected function getTypoScriptFrontendController()
public function getTypoScriptFrontendController()
{
return $this->typoScriptFrontendController ?: $GLOBALS['TSFE'] ?? null;
}
......
......@@ -3545,11 +3545,11 @@ class TypoScriptFrontendController implements LoggerAwareInterface
/**
* Returns the current BE user.
*
* @return \TYPO3\CMS\Backend\FrontendBackendUserAuthentication
* @return FrontendBackendUserAuthentication|null
*/
protected function getBackendUser()
{
return $GLOBALS['BE_USER'];
return $GLOBALS['BE_USER'] ?? null;
}
/**
......
......@@ -41,6 +41,7 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
use TYPO3\CMS\Core\Utility\RootlineUtility;
use TYPO3\CMS\Frontend\ContentObject\TypolinkModifyLinkConfigForPageLinksHookInterface;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
/**
* Builds a TypoLink to a certain page
......@@ -649,6 +650,9 @@ class PageLinkBuilder extends AbstractTypolinkBuilder
*/
protected function getCurrentSite(): ?SiteInterface
{
if ($this->typoScriptFrontendController instanceof TypoScriptFrontendController) {
return $this->typoScriptFrontendController->getSite();
}
if (isset($GLOBALS['TYPO3_REQUEST']) && $GLOBALS['TYPO3_REQUEST'] instanceof ServerRequestInterface) {
return $GLOBALS['TYPO3_REQUEST']->getAttribute('site', null);
}
......@@ -672,6 +676,9 @@ class PageLinkBuilder extends AbstractTypolinkBuilder
*/
protected function getCurrentSiteLanguage(): ?SiteLanguage
{
if ($this->typoScriptFrontendController instanceof TypoScriptFrontendController) {
return $this->typoScriptFrontendController->getLanguage();
}
if (isset($GLOBALS['TYPO3_REQUEST']) && $GLOBALS['TYPO3_REQUEST'] instanceof ServerRequestInterface) {
return $GLOBALS['TYPO3_REQUEST']->getAttribute('language', null);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment