Commit 1d9e8248 authored by Benni Mack's avatar Benni Mack
Browse files

[TASK] Avoid getIndpEnv and TYPO3_REQUEST in Link Builder

This change removes any usage of GeneralUtility::getIndpEnv()
in favor of NormalizedParams (non-global state) and
using ServerRequestInterface from cObject.

With this change, almost all usages of getIndpEnv()
from EXT:frontend are gone.

Also, Prophecies are removed from the affected unit tests.

Resolves: #98381
Releases: main
Change-Id: Ib7d9b92ee49dc47a9744892a4125f4b112c14bab
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/75795


Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: Andreas Fernandez's avatarAndreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Andreas Fernandez's avatarAndreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
parent 3563b7d5
......@@ -48,7 +48,7 @@ class ErrorController
*/
public function internalErrorAction(ServerRequestInterface $request, string $message, array $reasons = []): ResponseInterface
{
if (!$this->isPageUnavailableHandlerConfigured()) {
if (!$this->isPageUnavailableHandlerConfigured($request)) {
throw new InternalServerErrorException($message, 1607585445);
}
$errorHandler = $this->getErrorHandlerFromSite($request, 500);
......@@ -70,7 +70,7 @@ class ErrorController
*/
public function unavailableAction(ServerRequestInterface $request, string $message, array $reasons = []): ResponseInterface
{
if (!$this->isPageUnavailableHandlerConfigured()) {
if (!$this->isPageUnavailableHandlerConfigured($request)) {
throw new ServiceUnavailableException($message, 1518472181);
}
$errorHandler = $this->getErrorHandlerFromSite($request, 503);
......@@ -130,11 +130,13 @@ class ErrorController
* Checks whether the devIPMask matches the current visitor's IP address.
* Note: the name of this method is a misnomer (legacy code),
*
* @param ServerRequestInterface $request
* @return bool True if the server error handler should be used.
*/
protected function isPageUnavailableHandlerConfigured(): bool
protected function isPageUnavailableHandlerConfigured(ServerRequestInterface $request): bool
{
return !GeneralUtility::cmpIP(GeneralUtility::getIndpEnv('REMOTE_ADDR'), $GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask']);
$normalizedParams = $request->getAttribute('normalizedParams');
return !GeneralUtility::cmpIP($normalizedParams->getRemoteAddress(), $GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask']);
}
/**
......
......@@ -19,7 +19,7 @@ namespace TYPO3\CMS\Frontend\Typolink;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Domain\Repository\PageRepository;
use TYPO3\CMS\Core\Http\ServerRequestFactory;
use TYPO3\CMS\Core\Http\NormalizedParams;
use TYPO3\CMS\Core\Routing\PageArguments;
use TYPO3\CMS\Core\Site\Entity\NullSite;
use TYPO3\CMS\Core\Site\Entity\Site;
......@@ -79,16 +79,21 @@ abstract class AbstractTypolinkBuilder
'path' => $matches[4],
];
$isUrlModified = false;
// Set scheme and host if not yet part of the URL:
// Set scheme and host if not yet part of the URL
if (empty($urlParts['host'])) {
$urlParts['scheme'] = GeneralUtility::getIndpEnv('TYPO3_SSL') ? 'https' : 'http';
$urlParts['host'] = GeneralUtility::getIndpEnv('HTTP_HOST');
$normalizedParams = $this->contentObjectRenderer->getRequest()->getAttribute('normalizedParams');
// @todo: This fallback should vanish mid-term: typolink has a dependency to ServerRequest
// and should expect the normalizedParams argument is properly set as well. When for
// instance CLI triggers this code, it should have set up a proper request.
$normalizedParams ??= NormalizedParams::createFromRequest($this->contentObjectRenderer->getRequest());
$urlParts['scheme'] = $normalizedParams->isHttps() ? 'https' : 'http';
$urlParts['host'] = $normalizedParams->getHttpHost();
$urlParts['path'] = '/' . ltrim($urlParts['path'], '/');
// absRefPrefix has been prepended to $url beforehand
// so we only modify the path if no absRefPrefix has been set
// otherwise we would destroy the path
if ($this->getTypoScriptFrontendController()->absRefPrefix === '') {
$urlParts['path'] = GeneralUtility::getIndpEnv('TYPO3_SITE_PATH') . ltrim($urlParts['path'], '/');
$urlParts['path'] = $normalizedParams->getSitePath() . ltrim($urlParts['path'], '/');
}
$isUrlModified = true;
}
......@@ -199,7 +204,7 @@ abstract class AbstractTypolinkBuilder
// However, this is added to avoid any exceptions when trying to create a link.
// Detecting the "first" site usually comes from the fact that TSFE needs to be instantiated
// during tests
$request = $GLOBALS['TYPO3_REQUEST'] ?? ServerRequestFactory::fromGlobals();
$request = $this->contentObjectRenderer->getRequest();
$site = $request->getAttribute('site');
if (!$site instanceof Site) {
$sites = GeneralUtility::makeInstance(SiteFinder::class)->getAllSites();
......
......@@ -17,12 +17,13 @@ declare(strict_types=1);
namespace TYPO3\CMS\Frontend\Tests\Functional\ContentObject;
use Prophecy\PhpUnit\ProphecyTrait;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Log\NullLogger;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Domain\Repository\PageRepository;
use TYPO3\CMS\Core\Http\NormalizedParams;
use TYPO3\CMS\Core\Http\ServerRequest;
use TYPO3\CMS\Core\Resource\FileReference;
use TYPO3\CMS\Core\Routing\PageArguments;
use TYPO3\CMS\Core\Site\SiteFinder;
......@@ -36,7 +37,6 @@ use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
class ContentObjectRendererTest extends FunctionalTestCase
{
use ProphecyTrait;
use SiteBasedTestTrait;
/**
......@@ -51,11 +51,6 @@ class ContentObjectRendererTest extends FunctionalTestCase
*/
protected $subject;
/**
* @var TypoScriptFrontendController
*/
protected $typoScriptFrontendController;
protected array $pathsToProvideInTestInstance = ['typo3/sysext/frontend/Tests/Functional/Fixtures/Images' => 'fileadmin/user_upload'];
protected function setUp(): void
......@@ -71,13 +66,10 @@ class ContentObjectRendererTest extends FunctionalTestCase
],
$this->buildErrorHandlingConfiguration('Fluid', [404]),
);
$_SERVER['HTTP_HOST'] = 'example.com';
$_SERVER['REQUEST_URI'] = '/en/';
$_GET['id'] = 1;
GeneralUtility::flushInternalRuntimeCaches();
$site = GeneralUtility::makeInstance(SiteFinder::class)->getSiteByIdentifier('test');
$this->typoScriptFrontendController = GeneralUtility::makeInstance(
$typoScriptFrontendController = GeneralUtility::makeInstance(
TypoScriptFrontendController::class,
GeneralUtility::makeInstance(Context::class),
$site,
......@@ -85,10 +77,16 @@ class ContentObjectRendererTest extends FunctionalTestCase
new PageArguments(1, '0', []),
GeneralUtility::makeInstance(FrontendUserAuthentication::class)
);
$this->typoScriptFrontendController->sys_page = GeneralUtility::makeInstance(PageRepository::class);
$this->typoScriptFrontendController->tmpl = GeneralUtility::makeInstance(TemplateService::class);
$this->subject = GeneralUtility::makeInstance(ContentObjectRenderer::class, $this->typoScriptFrontendController);
$this->subject->setRequest($this->prophesize(ServerRequestInterface::class)->reveal());
$typoScriptFrontendController->sys_page = GeneralUtility::makeInstance(PageRepository::class);
$typoScriptFrontendController->tmpl = GeneralUtility::makeInstance(TemplateService::class);
$this->subject = GeneralUtility::makeInstance(ContentObjectRenderer::class, $typoScriptFrontendController);
$this->subject->setRequest($this->getPreparedRequest());
}
protected function getPreparedRequest(): ServerRequestInterface
{
$request = new ServerRequest('http://example.com/en/', 'GET', null, [], ['HTTP_HOST' => 'example.com', 'REQUEST_URI' => '/en/']);
return $request->withQueryParams(['id' => 1])->withAttribute('normalizedParams', NormalizedParams::createFromRequest($request));
}
/**
......@@ -336,6 +334,7 @@ class ContentObjectRendererTest extends FunctionalTestCase
{
$expected = '<a href="mailto:test@example.com">Send me an email</a>';
$subject = new ContentObjectRenderer();
$subject->setRequest($this->getPreparedRequest());
$result = $subject->typoLink('Send me an email', ['parameter' => 'mailto:test@example.com']);
self::assertEquals($expected, $result);
......@@ -350,6 +349,7 @@ class ContentObjectRendererTest extends FunctionalTestCase
{
$tsfe = $this->getMockBuilder(TypoScriptFrontendController::class)->disableOriginalConstructor()->getMock();
$subject = new ContentObjectRenderer($tsfe);
$subject->setRequest($this->getPreparedRequest());
$tsfe->config['config']['spamProtectEmailAddresses'] = 1;
$result = $subject->typoLink('Send me an email', ['parameter' => 'mailto:test@example.com']);
......@@ -363,7 +363,7 @@ class ContentObjectRendererTest extends FunctionalTestCase
{
$tsfe = $this->getMockBuilder(TypoScriptFrontendController::class)->disableOriginalConstructor()->getMock();
$subject = new ContentObjectRenderer($tsfe);
$subject->start([], 'tt_content');
$subject->start([], 'tt_content', $this->getPreparedRequest());
$expected = '';
$actual = $subject->searchWhere('ab', 'header,bodytext', 'tt_content');
......@@ -377,7 +377,7 @@ class ContentObjectRendererTest extends FunctionalTestCase
{
$tsfe = $this->getMockBuilder(TypoScriptFrontendController::class)->disableOriginalConstructor()->getMock();
$subject = new ContentObjectRenderer($tsfe);
$subject->setRequest($this->prophesize(ServerRequestInterface::class)->reveal());
$subject->setRequest($this->getPreparedRequest());
$subject->setLogger(new NullLogger());
$input = 'This is a simple inline text, no wrapping configured';
$result = $subject->parseFunc($input, $this->getLibParseFunc());
......@@ -532,7 +532,7 @@ And another one';
$imageTag . '</a>' => true,
'data-window-features="' . $windowFeatures => true,
'data-window-target="thePicture"' => true,
' target="' . 'thePicture' => true,
' target="thePicture' => true,
],
];
......@@ -659,7 +659,6 @@ And another one';
*/
public function imageLinkWrapWrapsTheContentAsConfigured(string $content, array $configuration, array $expected, array $expectedParams = []): void
{
$GLOBALS['TSFE'] = $this->typoScriptFrontendController;
$this->importCSVDataSet(__DIR__ . '/DataSet/FileReferences.csv');
$fileReferenceData = [
'uid' => 1,
......@@ -668,6 +667,7 @@ And another one';
];
$fileReference = new FileReference($fileReferenceData);
$this->subject->setCurrentFile($fileReference);
$this->subject->setRequest($this->getPreparedRequest());
$result = $this->subject->imageLinkWrap($content, $fileReference, $configuration);
foreach ($expected as $expectedString => $shouldContain) {
......
......@@ -33,6 +33,7 @@ class SlugSiteRequestTest extends AbstractTestCase
// Force subrequest-based errors ON, because some tests can't work otherwise.
protected array $configurationToUseInTestInstance = [
'SYS' => [
'devIPmask' => '123.123.123.123',
'encryptionKey' => '4408d27a916d51e624b69af3554f516dbab61037a9f7b9fd6f81b4d3bedeccb6',
'features' => [
'subrequestPageErrors' => true,
......
......@@ -18,6 +18,7 @@ declare(strict_types=1);
namespace TYPO3\CMS\Frontend\Tests\Unit\Controller;
use Prophecy\PhpUnit\ProphecyTrait;
use TYPO3\CMS\Core\Http\NormalizedParams;
use TYPO3\CMS\Core\Http\ServerRequest;
use TYPO3\CMS\Core\Information\Typo3Information;
use TYPO3\CMS\Core\Utility\GeneralUtility;
......@@ -41,9 +42,10 @@ class ErrorControllerTest extends UnitTestCase
$typo3InformationProphecy = $this->prophesize(Typo3Information::class);
$typo3InformationProphecy->getCopyrightYear()->willReturn('1999-20XX');
GeneralUtility::addInstance(Typo3Information::class, $typo3InformationProphecy->reveal());
$GLOBALS['TYPO3_REQUEST'] = [];
$request = new ServerRequest();
$request = (new ServerRequest())->withAttribute('normalizedParams', NormalizedParams::createFromRequest($request));
$subject = new ErrorController();
$response = $subject->pageNotFoundAction(new ServerRequest(), 'This test page was not found!');
$response = $subject->pageNotFoundAction($request, 'This test page was not found!');
self::assertSame(404, $response->getStatusCode());
self::assertStringContainsString('This test page was not found!', $response->getBody()->getContents());
}
......@@ -56,9 +58,10 @@ class ErrorControllerTest extends UnitTestCase
$typo3InformationProphecy = $this->prophesize(Typo3Information::class);
$typo3InformationProphecy->getCopyrightYear()->willReturn('1999-20XX');
GeneralUtility::addInstance(Typo3Information::class, $typo3InformationProphecy->reveal());
$GLOBALS['TYPO3_REQUEST'] = [];
$request = new ServerRequest();
$request = (new ServerRequest())->withAttribute('normalizedParams', NormalizedParams::createFromRequest($request));
$subject = new ErrorController();
$response = $subject->unavailableAction(new ServerRequest(), 'This page is temporarily unavailable.');
$response = $subject->unavailableAction($request, 'This page is temporarily unavailable.');
self::assertSame(503, $response->getStatusCode());
self::assertStringContainsString('This page is temporarily unavailable.', $response->getBody()->getContents());
}
......@@ -73,8 +76,10 @@ class ErrorControllerTest extends UnitTestCase
$this->expectExceptionMessage('All your system are belong to us!');
$this->expectExceptionCode(1518472181);
$request = new ServerRequest();
$request = (new ServerRequest())->withAttribute('normalizedParams', NormalizedParams::createFromRequest($request));
$subject = new ErrorController();
$subject->unavailableAction(new ServerRequest(), 'All your system are belong to us!');
$subject->unavailableAction($request, 'All your system are belong to us!');
}
/**
......@@ -85,8 +90,10 @@ class ErrorControllerTest extends UnitTestCase
$typo3InformationProphecy = $this->prophesize(Typo3Information::class);
$typo3InformationProphecy->getCopyrightYear()->willReturn('1999-20XX');
GeneralUtility::addInstance(Typo3Information::class, $typo3InformationProphecy->reveal());
$request = new ServerRequest();
$request = (new ServerRequest())->withAttribute('normalizedParams', NormalizedParams::createFromRequest($request));
$subject = new ErrorController();
$response = $subject->internalErrorAction(new ServerRequest(), 'All your system are belong to us!');
$response = $subject->internalErrorAction($request, 'All your system are belong to us!');
self::assertSame(500, $response->getStatusCode());
self::assertStringContainsString('All your system are belong to us!', $response->getBody()->getContents());
}
......@@ -101,8 +108,10 @@ class ErrorControllerTest extends UnitTestCase
$this->expectExceptionMessage('All your system are belong to us!');
$this->expectExceptionCode(1607585445);
$request = new ServerRequest();
$request = (new ServerRequest())->withAttribute('normalizedParams', NormalizedParams::createFromRequest($request));
$subject = new ErrorController();
$subject->internalErrorAction(new ServerRequest(), 'All your system are belong to us!');
$subject->internalErrorAction($request, 'All your system are belong to us!');
}
/**
......@@ -113,8 +122,10 @@ class ErrorControllerTest extends UnitTestCase
$typo3InformationProphecy = $this->prophesize(Typo3Information::class);
$typo3InformationProphecy->getCopyrightYear()->willReturn('1999-20XX');
GeneralUtility::addInstance(Typo3Information::class, $typo3InformationProphecy->reveal());
$request = new ServerRequest();
$request = (new ServerRequest())->withAttribute('normalizedParams', NormalizedParams::createFromRequest($request));
$subject = new ErrorController();
$response = $subject->pageNotFoundAction(new ServerRequest(), 'Error handler is not configured.');
$response = $subject->pageNotFoundAction($request, 'Error handler is not configured.');
self::assertSame(404, $response->getStatusCode());
self::assertSame('text/html; charset=utf-8', $response->getHeaderLine('Content-Type'));
self::assertStringContainsString('Error handler is not configured.', $response->getBody()->getContents());
......@@ -125,8 +136,10 @@ class ErrorControllerTest extends UnitTestCase
*/
public function defaultErrorHandlerWithJsonResponseIsChosenWhenNoSiteConfiguredForPageNotFoundAction(): void
{
$request = new ServerRequest();
$request = (new ServerRequest())->withAttribute('normalizedParams', NormalizedParams::createFromRequest($request));
$subject = new ErrorController();
$response = $subject->pageNotFoundAction((new ServerRequest())->withAddedHeader('Accept', 'application/json'), 'Error handler is not configured.');
$response = $subject->pageNotFoundAction($request->withAddedHeader('Accept', 'application/json'), 'Error handler is not configured.');
$responseContent = \json_decode($response->getBody()->getContents(), true);
self::assertSame(404, $response->getStatusCode());
self::assertSame('application/json; charset=utf-8', $response->getHeaderLine('Content-Type'));
......@@ -141,8 +154,10 @@ class ErrorControllerTest extends UnitTestCase
$typo3InformationProphecy = $this->prophesize(Typo3Information::class);
$typo3InformationProphecy->getCopyrightYear()->willReturn('1999-20XX');
GeneralUtility::addInstance(Typo3Information::class, $typo3InformationProphecy->reveal());
$request = new ServerRequest();
$request = (new ServerRequest())->withAttribute('normalizedParams', NormalizedParams::createFromRequest($request));
$subject = new ErrorController();
$response = $subject->unavailableAction(new ServerRequest(), 'Error handler is not configured.');
$response = $subject->unavailableAction($request, 'Error handler is not configured.');
self::assertSame(503, $response->getStatusCode());
self::assertSame('text/html; charset=utf-8', $response->getHeaderLine('Content-Type'));
self::assertStringContainsString('Error handler is not configured.', $response->getBody()->getContents());
......@@ -153,8 +168,10 @@ class ErrorControllerTest extends UnitTestCase
*/
public function defaultErrorHandlerWithJsonResponseIsChosenWhenNoSiteConfiguredForUnavailableAction(): void
{
$request = new ServerRequest();
$request = (new ServerRequest())->withAttribute('normalizedParams', NormalizedParams::createFromRequest($request));
$subject = new ErrorController();
$response = $subject->unavailableAction((new ServerRequest())->withAddedHeader('Accept', 'application/json'), 'Error handler is not configured.');
$response = $subject->unavailableAction($request->withAddedHeader('Accept', 'application/json'), 'Error handler is not configured.');
$responseContent = \json_decode($response->getBody()->getContents(), true);
self::assertSame(503, $response->getStatusCode());
self::assertSame('application/json; charset=utf-8', $response->getHeaderLine('Content-Type'));
......@@ -169,8 +186,10 @@ class ErrorControllerTest extends UnitTestCase
$typo3InformationProphecy = $this->prophesize(Typo3Information::class);
$typo3InformationProphecy->getCopyrightYear()->willReturn('1999-20XX');
GeneralUtility::addInstance(Typo3Information::class, $typo3InformationProphecy->reveal());
$request = new ServerRequest();
$request = (new ServerRequest())->withAttribute('normalizedParams', NormalizedParams::createFromRequest($request));
$subject = new ErrorController();
$response = $subject->internalErrorAction(new ServerRequest(), 'Error handler is not configured.');
$response = $subject->internalErrorAction($request, 'Error handler is not configured.');
self::assertSame(500, $response->getStatusCode());
self::assertSame('text/html; charset=utf-8', $response->getHeaderLine('Content-Type'));
self::assertStringContainsString('Error handler is not configured.', $response->getBody()->getContents());
......@@ -181,8 +200,10 @@ class ErrorControllerTest extends UnitTestCase
*/
public function defaultErrorHandlerWithJsonResponseIsChosenWhenNoSiteConfiguredForInternalErrorAction(): void
{
$request = new ServerRequest();
$request = (new ServerRequest())->withAttribute('normalizedParams', NormalizedParams::createFromRequest($request));
$subject = new ErrorController();
$response = $subject->internalErrorAction((new ServerRequest())->withAddedHeader('Accept', 'application/json'), 'Error handler is not configured.');
$response = $subject->internalErrorAction($request->withAddedHeader('Accept', 'application/json'), 'Error handler is not configured.');
$responseContent = \json_decode($response->getBody()->getContents(), true);
self::assertSame(500, $response->getStatusCode());
self::assertSame('application/json; charset=utf-8', $response->getHeaderLine('Content-Type'));
......@@ -197,8 +218,10 @@ class ErrorControllerTest extends UnitTestCase
$typo3InformationProphecy = $this->prophesize(Typo3Information::class);
$typo3InformationProphecy->getCopyrightYear()->willReturn('1999-20XX');
GeneralUtility::addInstance(Typo3Information::class, $typo3InformationProphecy->reveal());
$request = new ServerRequest();
$request = (new ServerRequest())->withAttribute('normalizedParams', NormalizedParams::createFromRequest($request));
$subject = new ErrorController();
$response = $subject->accessDeniedAction(new ServerRequest(), 'Error handler is not configured.');
$response = $subject->accessDeniedAction($request, 'Error handler is not configured.');
self::assertSame(403, $response->getStatusCode());
self::assertSame('text/html; charset=utf-8', $response->getHeaderLine('Content-Type'));
self::assertStringContainsString('Error handler is not configured.', $response->getBody()->getContents());
......@@ -209,8 +232,10 @@ class ErrorControllerTest extends UnitTestCase
*/
public function defaultErrorHandlerWithJsonResponseIsChosenWhenNoSiteConfiguredForAccessDeniedAction(): void
{
$request = new ServerRequest();
$request = (new ServerRequest())->withAttribute('normalizedParams', NormalizedParams::createFromRequest($request));
$subject = new ErrorController();
$response = $subject->accessDeniedAction((new ServerRequest())->withAddedHeader('Accept', 'application/json'), 'Error handler is not configured.');
$response = $subject->accessDeniedAction($request->withAddedHeader('Accept', 'application/json'), 'Error handler is not configured.');
$responseContent = \json_decode($response->getBody()->getContents(), true);
self::assertSame(403, $response->getStatusCode());
self::assertSame('application/json; charset=utf-8', $response->getHeaderLine('Content-Type'));
......
......@@ -18,9 +18,10 @@ declare(strict_types=1);
namespace TYPO3\CMS\Frontend\Tests\Unit\Typolink;
use PHPUnit\Framework\MockObject\MockObject;
use Prophecy\PhpUnit\ProphecyTrait;
use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\Container;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Http\ServerRequest;
use TYPO3\CMS\Core\Log\LogManager;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\StringUtility;
......@@ -35,8 +36,6 @@ use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
*/
class AbstractTypolinkBuilderTest extends UnitTestCase
{
use ProphecyTrait;
protected bool $resetSingletonInstances = true;
protected bool $backupEnvironment = true;
......@@ -193,15 +192,22 @@ class AbstractTypolinkBuilderTest extends UnitTestCase
Environment::isWindows() ? 'WINDOWS' : 'UNIX'
);
$this->frontendControllerMock->absRefPrefix = '';
$contentObjectRendererProphecy = $this->prophesize(ContentObjectRenderer::class);
$cObj = new ContentObjectRenderer($this->frontendControllerMock, new Container());
// Force hostname
$serverRequest = new ServerRequest(
'http://localhost/index.php',
'GET',
null,
[],
['HTTP_HOST' => 'localhost', 'SCRIPT_NAME' => '/index.php']
);
$cObj->setRequest($serverRequest);
$subject = $this->getAccessibleMock(
AbstractTypolinkBuilder::class,
['build'],
[$contentObjectRendererProphecy->reveal(), $this->frontendControllerMock]
[$cObj, $this->frontendControllerMock]
);
// Force hostname
$_SERVER['HTTP_HOST'] = 'localhost';
$_SERVER['SCRIPT_NAME'] = '/index.php';
self::assertEquals($expected, $subject->_call('forceAbsoluteUrl', $url, $configuration));
}
......@@ -221,15 +227,22 @@ class AbstractTypolinkBuilderTest extends UnitTestCase
Environment::getPublicPath() . '/index.php',
Environment::isWindows() ? 'WINDOWS' : 'UNIX'
);
$contentObjectRendererProphecy = $this->prophesize(ContentObjectRenderer::class);
$cObj = new ContentObjectRenderer($this->frontendControllerMock, new Container());
// Force hostname
$serverRequest = new ServerRequest(
'http://localhost/subfolder/index.php',
'GET',
null,
[],
['HTTP_HOST' => 'localhost', 'SCRIPT_NAME' => '/subfolder/index.php']
);
$cObj->setRequest($serverRequest);
$subject = $this->getAccessibleMock(
AbstractTypolinkBuilder::class,
['build'],
[$contentObjectRendererProphecy->reveal(), $this->frontendControllerMock]
[$cObj, $this->frontendControllerMock]
);
// Force hostname
$_SERVER['HTTP_HOST'] = 'localhost';
$_SERVER['SCRIPT_NAME'] = '/subfolder/index.php';
$expected = 'http://localhost/subfolder/fileadmin/my.pdf';
$url = 'fileadmin/my.pdf';
......@@ -346,10 +359,17 @@ class AbstractTypolinkBuilderTest extends UnitTestCase
string $fallbackTarget,
?string $doctype
): void {
$this->frontendControllerMock->config =
['config' => [ 'doctype' => $doctype]];
$renderer = GeneralUtility::makeInstance(ContentObjectRenderer::class);
$subject = $this->getAccessibleMockForAbstractClass(AbstractTypolinkBuilder::class, [$renderer, $this->frontendControllerMock]);
$this->frontendControllerMock->config = ['config' => ['doctype' => $doctype]];
$cObj = new ContentObjectRenderer($this->frontendControllerMock, new Container());
$serverRequest = new ServerRequest(
'http://localhost/subfolder/index.php',
'GET',
null,
[],
['HTTP_HOST' => 'localhost', 'SCRIPT_NAME' => '/subfolder/index.php']
);
$cObj->setRequest($serverRequest);
$subject = $this->getAccessibleMockForAbstractClass(AbstractTypolinkBuilder::class, [$cObj, $this->frontendControllerMock]);
$actual = $subject->_call(
'resolveTargetAttribute',
$conf,
......
Supports Markdown
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