[BUGFIX] Always provide default language 18/61218/4
authorAndreas Fernandez <a.fernandez@scripting-base.de>
Wed, 3 Jul 2019 14:02:08 +0000 (16:02 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Fri, 5 Jul 2019 14:40:06 +0000 (16:40 +0200)
The TranslationConfigurationProvider should always provide the default
language, even if the backend user doesn't have permissions configured.

This is due to the fact that some actions always require the presence
of the default language. This is a regression introduced with sites.

This patch always adds the default languages, as it was with pseudo
sites in place.

Resolves: #88504
Releases: master, 9.5
Change-Id: I2a8be4d399f7c24f8e2f8ec53374d9f419e92b71
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/61218
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Daniel Goerz <daniel.goerz@posteo.de>
typo3/sysext/backend/Classes/Configuration/TranslationConfigurationProvider.php
typo3/sysext/backend/Tests/Unit/Configuration/TranslationConfigurationProviderTest.php [new file with mode: 0644]

index 8d17b92..84dc23a 100644 (file)
@@ -47,6 +47,10 @@ class TranslationConfigurationProvider
             $site = new NullSite();
         }
         $siteLanguages = $site->getAvailableLanguages($this->getBackendUserAuthentication(), true);
+        if (!isset($siteLanguages[0])) {
+            $siteLanguages[0] = $site->getDefaultLanguage();
+            ksort($siteLanguages);
+        }
 
         $languages = [];
         foreach ($siteLanguages as $id => $siteLanguage) {
diff --git a/typo3/sysext/backend/Tests/Unit/Configuration/TranslationConfigurationProviderTest.php b/typo3/sysext/backend/Tests/Unit/Configuration/TranslationConfigurationProviderTest.php
new file mode 100644 (file)
index 0000000..db9be4c
--- /dev/null
@@ -0,0 +1,56 @@
+<?php
+declare(strict_types = 1);
+namespace TYPO3\CMS\Backend\Tests\Unit\Configuration;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider;
+use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
+use TYPO3\CMS\Core\Site\Entity\Site;
+use TYPO3\CMS\Core\Site\SiteFinder;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
+
+class TranslationConfigurationProviderTest extends UnitTestCase
+{
+    /**
+     * @var TranslationConfigurationProvider
+     */
+    protected $subject;
+
+    protected function setUp(): void
+    {
+        parent::setUp();
+
+        $this->subject = new TranslationConfigurationProvider();
+    }
+
+    /**
+     * @test
+     */
+    public function defaultLanguageIsAlwaysReturned(): void
+    {
+        $pageId = 1;
+        $site = new Site('dummy', $pageId, ['base' => 'http://sub.domainhostname.tld/path/']);
+        $siteFinderProphecy = $this->prophesize(SiteFinder::class);
+        $siteFinderProphecy->getSiteByPageId($pageId)->willReturn($site);
+        GeneralUtility::addInstance(SiteFinder::class, $siteFinderProphecy->reveal());
+
+        $backendUserAuthentication = $this->prophesize(BackendUserAuthentication::class);
+        $GLOBALS['BE_USER'] = $backendUserAuthentication->reveal();
+
+        $languages = $this->subject->getSystemLanguages($pageId);
+        $this->assertArrayHasKey(0, $languages);
+    }
+}