From ef62fac03ef3f50e223133397b6d776bbb515f6e Mon Sep 17 00:00:00 2001
From: Andreas Fernandez <a.fernandez@scripting-base.de>
Date: Wed, 25 Jul 2018 08:53:42 +0200
Subject: [PATCH] [BUGFIX] Determine default language as origin correctly

Resolves: #85638
Releases: master, 8.7
Change-Id: I98ecaef360d5a27e965cbb67c5719729054b9c37
Reviewed-on: https://review.typo3.org/57676
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Mathias Schreiber <mathias.schreiber@typo3.com>
Tested-by: Mathias Schreiber <mathias.schreiber@typo3.com>
Reviewed-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
Reviewed-by: Nicole Cordes <typo3@cordes.co>
Tested-by: Nicole Cordes <typo3@cordes.co>
---
 .../Localization/LocalizationRepository.php   |  2 +-
 .../Fixtures/tt_content-danish-language.xml   |  3 ++
 .../Page/LocalizationControllerTest.php       | 35 +++++++++++++++++--
 .../LocalizationRepositoryTest.php            | 14 +++++---
 4 files changed, 47 insertions(+), 7 deletions(-)

diff --git a/typo3/sysext/backend/Classes/Domain/Repository/Localization/LocalizationRepository.php b/typo3/sysext/backend/Classes/Domain/Repository/Localization/LocalizationRepository.php
index cc4142aab4a6..0d69f8a2521d 100644
--- a/typo3/sysext/backend/Classes/Domain/Repository/Localization/LocalizationRepository.php
+++ b/typo3/sysext/backend/Classes/Domain/Repository/Localization/LocalizationRepository.php
@@ -66,7 +66,7 @@ class LocalizationRepository
                     $queryBuilder->quoteIdentifier('tt_content_orig.uid')
                 )
             )
-            ->join(
+            ->leftJoin(
                 'tt_content_orig',
                 'sys_language',
                 'sys_language',
diff --git a/typo3/sysext/backend/Tests/Functional/Controller/Page/Fixtures/tt_content-danish-language.xml b/typo3/sysext/backend/Tests/Functional/Controller/Page/Fixtures/tt_content-danish-language.xml
index 9c0879577cb4..6369d79ecd53 100644
--- a/typo3/sysext/backend/Tests/Functional/Controller/Page/Fixtures/tt_content-danish-language.xml
+++ b/typo3/sysext/backend/Tests/Functional/Controller/Page/Fixtures/tt_content-danish-language.xml
@@ -5,6 +5,7 @@
 		<pid>1</pid>
 		<sys_language_uid>1</sys_language_uid>
 		<l18n_parent>1</l18n_parent>
+		<l10n_source>1</l10n_source>
 		<deleted>0</deleted>
 		<t3ver_oid>0</t3ver_oid>
 		<t3ver_wsid>0</t3ver_wsid>
@@ -17,6 +18,7 @@
 		<pid>1</pid>
 		<sys_language_uid>1</sys_language_uid>
 		<l18n_parent>2</l18n_parent>
+		<l10n_source>2</l10n_source>
 		<deleted>0</deleted>
 		<t3ver_oid>0</t3ver_oid>
 		<t3ver_wsid>0</t3ver_wsid>
@@ -29,6 +31,7 @@
 		<pid>1</pid>
 		<sys_language_uid>1</sys_language_uid>
 		<l18n_parent>3</l18n_parent>
+		<l10n_source>3</l10n_source>
 		<deleted>0</deleted>
 		<t3ver_oid>0</t3ver_oid>
 		<t3ver_wsid>0</t3ver_wsid>
diff --git a/typo3/sysext/backend/Tests/Functional/Controller/Page/LocalizationControllerTest.php b/typo3/sysext/backend/Tests/Functional/Controller/Page/LocalizationControllerTest.php
index ef8b7891025b..6a7018d8386b 100644
--- a/typo3/sysext/backend/Tests/Functional/Controller/Page/LocalizationControllerTest.php
+++ b/typo3/sysext/backend/Tests/Functional/Controller/Page/LocalizationControllerTest.php
@@ -72,8 +72,7 @@ class LocalizationControllerTest extends \TYPO3\TestingFramework\Core\Functional
 
         $this->subject = $this->getMockBuilder(LocalizationController::class)
             ->setMethods(['getPageColumns'])
-            ->getMock()
-        ;
+            ->getMock();
     }
 
     /**
@@ -188,6 +187,38 @@ class LocalizationControllerTest extends \TYPO3\TestingFramework\Core\Functional
         $this->assertAssertionDataSet('CreatedElementOrdering');
     }
 
+    /**
+     * @test
+     */
+    public function defaultLanguageIsFoundAsOriginLanguage(): void
+    {
+        $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/backend/Tests/Functional/Controller/Page/Fixtures/tt_content-danish-language.xml');
+
+        // Create another content element in default language
+        $data = [
+            'tt_content' => [
+                'NEW123456' => [
+                    'sys_language_uid' => 0,
+                    'header' => 'New content element',
+                    'pid' => 1,
+                    'colPos' => 0,
+                ],
+            ],
+        ];
+        $dataHandler = new DataHandler();
+        $dataHandler->start($data, []);
+        $dataHandler->process_datamap();
+        $dataHandler->process_cmdmap();
+
+        $request = (new ServerRequest())->withQueryParams([
+            'pageId'         => 1, // page uid, the records are stored on
+            'languageId'     => 1  // current language id
+        ]);
+
+        $usedLanguages = (string)$this->subject->getUsedLanguagesInPage($request)->getBody();
+        $this->assertThat($usedLanguages, $this->stringContains('"uid":0'));
+    }
+
     /**
      * @test
      */
diff --git a/typo3/sysext/backend/Tests/Functional/Domain/Repository/Localization/LocalizationRepositoryTest.php b/typo3/sysext/backend/Tests/Functional/Domain/Repository/Localization/LocalizationRepositoryTest.php
index 9dbffed4f649..c11a6044bf30 100644
--- a/typo3/sysext/backend/Tests/Functional/Domain/Repository/Localization/LocalizationRepositoryTest.php
+++ b/typo3/sysext/backend/Tests/Functional/Domain/Repository/Localization/LocalizationRepositoryTest.php
@@ -50,7 +50,7 @@ class LocalizationRepositoryTest extends \TYPO3\TestingFramework\Core\Functional
     public function fetchOriginLanguageDataProvider(): array
     {
         return [
-            'default language returns false' => [
+            'default language returns empty array' => [
                 1,
                 0,
                 []
@@ -58,7 +58,9 @@ class LocalizationRepositoryTest extends \TYPO3\TestingFramework\Core\Functional
             'connected mode translated from default language' => [
                 1,
                 1,
-                []
+                [
+                    'sys_language_uid' => 0
+                ]
             ],
             'connected mode translated from non default language' => [
                 1,
@@ -70,7 +72,9 @@ class LocalizationRepositoryTest extends \TYPO3\TestingFramework\Core\Functional
             'free mode translated from default language' => [
                 2,
                 1,
-                []
+                [
+                    'sys_language_uid' => 0
+                ]
             ],
             'free mode translated from non default language' => [
                 2,
@@ -82,7 +86,9 @@ class LocalizationRepositoryTest extends \TYPO3\TestingFramework\Core\Functional
             'free mode copied from another page translated from default language' => [
                 3,
                 1,
-                []
+                [
+                    'sys_language_uid' => 0
+                ]
             ],
             'free mode copied from another page translated from non default language' => [
                 3,
-- 
GitLab