Skip to content

Commit

Permalink
[BUGFIX] Always provide default language
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
andreaskienast authored and maddy2101 committed Jul 5, 2019
1 parent 11398a3 commit 2b8a9d2
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
Expand Up @@ -47,6 +47,10 @@ public function getSystemLanguages($pageId = 0)
$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) {
Expand Down
@@ -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);
}
}

0 comments on commit 2b8a9d2

Please sign in to comment.