[BUGFIX] Make LocalizationRepository handle copied records 06/51406/7
authorTymoteusz Motylewski <t.motylewski@gmail.com>
Tue, 28 Feb 2017 21:25:52 +0000 (22:25 +0100)
committerTymoteusz Motylewski <t.motylewski@gmail.com>
Wed, 1 Mar 2017 09:13:59 +0000 (10:13 +0100)
Improve LocalizationRepository queries to handle case
when records were copied from another page (thus t3_origuid)
is pointing to records from the other page.

Now LocalizationRepository uses l10n_source field instead of t3_origuid.
Tests for LocalizationRepository covering the case were added.

Resolves: #79443
Resolves: #78599

Releases: master, 7.6
Change-Id: Ibae4a276ea814f0ce3d453cffef1d22afeff1eb9
Reviewed-on: https://review.typo3.org/51406
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Markus M├Ąchler <admin@bithost.ch>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Daniel Goerz <ervaude@gmail.com>
Tested-by: Daniel Goerz <ervaude@gmail.com>
Reviewed-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
Tested-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
typo3/sysext/backend/Classes/Domain/Repository/Localization/LocalizationRepository.php
typo3/sysext/backend/Classes/View/PageLayoutView.php
typo3/sysext/backend/Tests/Functional/Domain/Repository/Localization/Fixtures/DefaultPagesAndContent.csv [new file with mode: 0644]
typo3/sysext/backend/Tests/Functional/Domain/Repository/Localization/LocalizationRepositoryTest.php [new file with mode: 0644]

index dba66f8..27f9e3b 100644 (file)
@@ -63,7 +63,7 @@ class LocalizationRepository
                 'tt_content',
                 'tt_content_orig',
                 $queryBuilder->expr()->eq(
-                    'tt_content.t3_origuid',
+                    'tt_content.l10n_source',
                     $queryBuilder->quoteIdentifier('tt_content_orig.uid')
                 )
             )
@@ -83,6 +83,9 @@ class LocalizationRepository
     }
 
     /**
+     * Returns number of localized records in given page, colPos and language
+     * Records which were added to the language directly (not through translation) are not counted.
+     *
      * @param int $pageId
      * @param int $colPos
      * @param int $languageId
@@ -108,7 +111,7 @@ class LocalizationRepository
                     $queryBuilder->createNamedParameter($pageId, \PDO::PARAM_INT)
                 ),
                 $queryBuilder->expr()->neq(
-                    'tt_content.t3_origuid',
+                    'tt_content.l10n_source',
                     $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
                 )
             )
@@ -251,7 +254,7 @@ class LocalizationRepository
         $queryBuilder = $this->getQueryBuilderWithWorkspaceRestriction('tt_content');
 
         $originalUidsStatement = $queryBuilder
-            ->select('t3_origuid')
+            ->select('l10n_source')
             ->from('tt_content')
             ->where(
                 $queryBuilder->expr()->eq(
index 19fd03f..10748d4 100644 (file)
@@ -1994,7 +1994,7 @@ class PageLayoutView extends \TYPO3\CMS\Recordlist\RecordList\AbstractDatabaseRe
 
         if (isset($this->contentElementCache[$lP][$colPos]) && is_array($this->contentElementCache[$lP][$colPos])) {
             foreach ($this->contentElementCache[$lP][$colPos] as $record) {
-                $key = array_search($record['t3_origuid'], $defaultLanguageUids);
+                $key = array_search($record['l10n_source'], $defaultLanguageUids);
                 if ($key !== false) {
                     unset($defaultLanguageUids[$key]);
                 }
diff --git a/typo3/sysext/backend/Tests/Functional/Domain/Repository/Localization/Fixtures/DefaultPagesAndContent.csv b/typo3/sysext/backend/Tests/Functional/Domain/Repository/Localization/Fixtures/DefaultPagesAndContent.csv
new file mode 100644 (file)
index 0000000..249feab
--- /dev/null
@@ -0,0 +1,23 @@
+pages,,,,,,,,,
+,uid,pid,sorting,deleted,t3_origuid,title,,,
+,1,0,256,0,0,Connected mode,,,
+,2,0,512,0,0,Free mode,,,
+,3,0,768,0,0,Free mode CE copied from pid 2,,,
+sys_language,,,,,,,,,
+,uid,pid,hidden,title,flag,,,,
+,1,0,0,Dansk,dk,,,,
+,2,0,0,Deutsch,de,,,,
+tt_content,,,,,,,,,
+,uid,pid,sorting,deleted,sys_language_uid,l18n_parent,l10n_source,t3_origuid,header
+,297,1,256,0,0,0,0,0,Regular Element #1
+,298,1,512,0,0,0,0,0,Regular Element #2
+,299,1,768,0,0,0,0,0,Regular Element #3
+,300,1,1024,0,1,299,299,299,[Translate to Dansk:] Regular Element #3
+,301,1,384,0,1,297,297,297,[Translate to Dansk:] Regular Element #1
+,302,1,448,0,2,297,301,301,[Translate to Deutsch:] [Translate to Dansk:] Regular Element #1
+,310,2,256,0,0,0,0,0,Regular Element #10
+,311,2,512,0,1,0,310,310,[Translate to Dansk:] Regular Element #10
+,312,2,768,0,2,0,311,311,[Translate to Deutsch:] [Translate to Dansk:] Regular Element #10
+,313,3,128,0,0,0,0,310,Regular Element #10
+,314,3,256,0,1,0,313,311,[Translate to Dansk:] Regular Element #10
+,315,3,512,0,2,0,314,312,[Translate to Deutsch:] [Translate to Dansk:] Regular Element #10
diff --git a/typo3/sysext/backend/Tests/Functional/Domain/Repository/Localization/LocalizationRepositoryTest.php b/typo3/sysext/backend/Tests/Functional/Domain/Repository/Localization/LocalizationRepositoryTest.php
new file mode 100644 (file)
index 0000000..92a504a
--- /dev/null
@@ -0,0 +1,236 @@
+<?php
+namespace TYPO3\CMS\Backend\Tests\Functional\Domain\Repository\Localization;
+
+/*
+ * 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\Domain\Repository\Localization\LocalizationRepository;
+use TYPO3\CMS\Core\Core\Bootstrap;
+
+/**
+ * Test case for TYPO3\CMS\Backend\Domain\Repository\Localization\LocalizationRepository
+ */
+class LocalizationRepositoryTest extends \TYPO3\TestingFramework\Core\Functional\FunctionalTestCase
+{
+    /**
+     * @var LocalizationRepository
+     */
+    protected $subject;
+
+    /**
+     * Sets up this test case.
+     *
+     * @return void
+     */
+    protected function setUp()
+    {
+        parent::setUp();
+
+        $this->setUpBackendUserFromFixture(1);
+        Bootstrap::getInstance()->initializeLanguageObject();
+
+        $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3/sysext/backend/Tests/Functional/Domain/Repository/Localization/Fixtures/DefaultPagesAndContent.csv');
+
+        $this->subject = new LocalizationRepository();
+    }
+
+    public function fetchOriginLanguageDataProvider()
+    {
+        return [
+            'default language returns false' => [
+                1,
+                0,
+                0,
+                false
+            ],
+            'connected mode translated from default language' => [
+                1,
+                0,
+                1,
+                false
+            ],
+            'connected mode translated from non default language' => [
+                1,
+                0,
+                2,
+                [
+                    'sys_language_uid' => 1
+                ]
+            ],
+            'free mode translated from default language' => [
+                2,
+                0,
+                1,
+                false
+            ],
+            'free mode translated from non default language' => [
+                2,
+                0,
+                2,
+                [
+                    'sys_language_uid' => 1
+                ]
+            ],
+            'free mode copied from another page translated from default language' => [
+                3,
+                0,
+                1,
+                false
+            ],
+            'free mode copied from another page translated from non default language' => [
+                3,
+                0,
+                2,
+                [
+                    'sys_language_uid' => 1
+                ]
+            ]
+        ];
+    }
+
+    /**
+     * @dataProvider fetchOriginLanguageDataProvider
+     * @test
+     *
+     * @param $pageId
+     * @param $colPos
+     * @param $localizedLanguage
+     * @param $expectedResult
+     */
+    public function fetchOriginLanguage($pageId, $colPos, $localizedLanguage, $expectedResult)
+    {
+        $result = $this->subject->fetchOriginLanguage($pageId, $colPos, $localizedLanguage);
+        $this->assertEquals($expectedResult, $result);
+    }
+
+    public function getLocalizedRecordCountDataProvider()
+    {
+        return [
+            'default language returns 0 always' => [
+                1,
+                0,
+                0,
+                0
+            ],
+            'connected mode translated from default language' => [
+                1,
+                0,
+                1,
+                2
+            ],
+            'connected mode translated from non default language' => [
+                1,
+                0,
+                2,
+                1
+            ],
+            'free mode translated from default language' => [
+                2,
+                0,
+                1,
+                1
+            ],
+            'free mode translated from non default language' => [
+                2,
+                0,
+                2,
+                1
+            ],
+            'free mode copied from another page translated from default language' => [
+                3,
+                0,
+                1,
+                1
+            ],
+            'free mode copied from another page translated from non default language' => [
+                3,
+                0,
+                2,
+                1
+            ]
+        ];
+    }
+
+    /**
+     * @dataProvider getLocalizedRecordCountDataProvider
+     * @test
+     */
+    public function getLocalizedRecordCount($pageId, $colPos, $localizedLanguage, $expectedResult)
+    {
+        $result = $this->subject->getLocalizedRecordCount($pageId, $colPos, $localizedLanguage);
+        $this->assertEquals($expectedResult, $result);
+    }
+
+    public function getRecordsToCopyDatabaseResultDataProvider()
+    {
+        return [
+            'from language 0 to 1 connected mode' => [
+                1,
+                0,
+                1,
+                0,
+                [
+                    ['uid' => 298]
+                ]
+            ],
+            'from language 1 to 2 connected mode' => [
+                1,
+                0,
+                2,
+                1,
+                [
+                    ['uid' => 300]
+                ]
+            ],
+            'from language 0 to 1 free mode' => [
+                2,
+                0,
+                1,
+                0,
+                []
+            ],
+            'from language 1 to 2 free mode' => [
+                2,
+                0,
+                2,
+                1,
+                []
+            ],
+            'from language 0 to 1 free mode copied' => [
+                3,
+                0,
+                1,
+                0,
+                []
+            ],
+            'from language 1 to 2 free mode  mode copied' => [
+                3,
+                0,
+                2,
+                1,
+                []
+            ],
+        ];
+    }
+
+    /**
+     * @dataProvider getRecordsToCopyDatabaseResultDataProvider
+     * @test
+     */
+    public function getRecordsToCopyDatabaseResult($pageId, $colPos, $destLanguageId, $languageId, $expectedResult)
+    {
+        $result = $this->subject->getRecordsToCopyDatabaseResult($pageId, $colPos, $destLanguageId, $languageId, 'uid');
+        $result = $result->fetchAll();
+        $this->assertEquals($expectedResult, $result);
+    }
+}