[BUGFIX] Make sure the baseVariants are respected 75/61375/4
authorGuido Schmechel <guido.schmechel@brandung.de>
Fri, 26 Jul 2019 10:17:20 +0000 (12:17 +0200)
committerAndreas Fernandez <a.fernandez@scripting-base.de>
Thu, 8 Aug 2019 11:43:26 +0000 (13:43 +0200)
In the ContentObjectRenderer there is the possibility to get
the Site Configuration. Here a simple array which is read out.

In the case of baseUrl, the baseVariants are now considered
with the possible conditions.

Resolves: #88847
Releases: master, 9.5
Change-Id: I8db7e9264e82d4021ea8fe63b690eb2ec09288e4
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/61375
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Daniel Maier <dani-maier@gmx.de>
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php
typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php

index 9d9deb8..560cc1b 100644 (file)
@@ -4711,6 +4711,8 @@ class ContentObjectRenderer implements LoggerAwareInterface
                         if ($site instanceof Site) {
                             if ($key === 'identifier') {
                                 $retVal = $site->getIdentifier();
+                            } elseif ($key === 'base') {
+                                $retVal = $site->getBase();
                             } else {
                                 try {
                                     $retVal = ArrayUtility::getValueByPath($site->getConfiguration(), $key, '.');
index 54cdd3d..2303d72 100644 (file)
@@ -1703,6 +1703,38 @@ class ContentObjectRendererTest extends UnitTestCase
     }
 
     /**
+     * Checks if getData() works with type "site" and base variants
+     *
+     * @test
+     */
+    public function getDataWithTypeSiteWithBaseVariants(): void
+    {
+        $cacheManagerProphecy = $this->prophesize(CacheManager::class);
+        $cacheManagerProphecy->getCache('core')->willReturn(new NullFrontend('core'));
+        GeneralUtility::setSingletonInstance(CacheManager::class, $cacheManagerProphecy->reveal());
+        putenv('LOCAL_DEVELOPMENT=1');
+
+        $site = new Site('my-site', 123, [
+            'base' => 'http://prod.com',
+            'baseVariants' => [
+                [
+                    'base' => 'http://staging.com',
+                    'condition' => 'applicationContext == "Production/Staging"'
+                ],
+                [
+                    'base' => 'http://dev.com',
+                    'condition' => 'getenv("LOCAL_DEVELOPMENT") == 1'
+                ],
+            ]
+        ]);
+
+        $serverRequest = $this->prophesize(ServerRequestInterface::class);
+        $serverRequest->getAttribute('site')->willReturn($site);
+        $GLOBALS['TYPO3_REQUEST'] = $serverRequest->reveal();
+        $this->assertEquals('http://dev.com', $this->subject->getData('site:base'));
+    }
+
+    /**
      * Checks if getData() works with type "siteLanguage"
      *
      * @test