[TASK] Test rendering of translated select MM relations in Extbase 11/57611/3
authorTymoteusz Motylewski <t.motylewski@gmail.com>
Mon, 16 Jul 2018 13:26:03 +0000 (15:26 +0200)
committerTymoteusz Motylewski <t.motylewski@gmail.com>
Mon, 16 Jul 2018 15:21:12 +0000 (17:21 +0200)
It's based on tt_content and categories.

Releases: master, 8.7
Resolves: #85493
Change-Id: Ie7222f38ea89536ab463ff46aabb94b8f834d599
Reviewed-on: https://review.typo3.org/57611
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
Tested-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example/Classes/Domain/Model/TtContent.php
typo3/sysext/extbase/Tests/Functional/Persistence/TranslatedContentTest.php
typo3/sysext/frontend/Tests/Functional/Rendering/DataSet/LiveDefaultElements.csv

index b8e14aa..f2bfa3e 100644 (file)
@@ -49,11 +49,17 @@ class TtContent extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
     protected $image;
 
     /**
+     * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\Category>
+     */
+    protected $categories;
+
+    /**
      * Constructs this post
      */
     public function __construct()
     {
         $this->image = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
+        $this->categories = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
     }
 
     /**
@@ -113,6 +119,46 @@ class TtContent extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
     }
 
     /**
+     * Add category to a CE
+     *
+     * @param \TYPO3\CMS\Extbase\Domain\Model\Category $category
+     */
+    public function addCategory(\TYPO3\CMS\Extbase\Domain\Model\Category $category)
+    {
+        $this->categories->attach($category);
+    }
+
+    /**
+     * Set categories
+     *
+     * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage $categories
+     */
+    public function setCategories($categories)
+    {
+        $this->categories = $categories;
+    }
+
+    /**
+     * Get categories
+     *
+     * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage
+     */
+    public function getCategories()
+    {
+        return $this->categories;
+    }
+
+    /**
+     * Remove category from a CE
+     *
+     * @param \TYPO3\CMS\Extbase\Domain\Model\Category $category
+     */
+    public function removeCategory(\TYPO3\CMS\Extbase\Domain\Model\Category $category)
+    {
+        $this->categories->detach($category);
+    }
+
+    /**
      * Returns this as a formatted string
      *
      * @return string
index d92f524..bb83d11 100644 (file)
@@ -207,6 +207,16 @@ class TranslatedContentTest extends \TYPO3\CMS\Core\Tests\Functional\DataHandlin
         $this->assertThat($responseSections, $this->getRequestSectionStructureDoesNotHaveRecordConstraint()
             ->setRecordIdentifier(self::TABLE_Content . ':298')->setRecordField('image')
             ->setTable('sys_file_reference')->setField('title')->setValues(...$this->getNonVisibleFileTitles($visibleFiles)));
+
+        //assert Categories
+        $visibleCategories = ['Category 1', 'Category 3 - not translated'];
+        $this->assertThat($responseSections, $this->getRequestSectionStructureHasRecordConstraint()
+            ->setRecordIdentifier(self::TABLE_Content . ':297')->setRecordField('categories')
+            ->setTable('sys_category')->setField('title')->setValues(...$visibleCategories));
+
+        $this->assertThat($responseSections, $this->getRequestSectionStructureDoesNotHaveRecordConstraint()
+            ->setRecordIdentifier(self::TABLE_Content . ':297')->setRecordField('categories')
+            ->setTable('sys_category')->setField('title')->setValues(...$this->getNonVisibleCategoryTitles($visibleCategories)));
     }
 
     /**
@@ -227,7 +237,7 @@ class TranslatedContentTest extends \TYPO3\CMS\Core\Tests\Functional\DataHandlin
                     297 => [
                         'header' => '[Translate to Dansk:] Regular Element #1',
                         'image' => ['T3BOARD'],
-
+                        'categories' => ['[Translate to Dansk:] Category 1', 'Category 3 - not translated'],
                     ],
                     298 => [
                         'header' => 'Regular Element #2',
@@ -235,7 +245,7 @@ class TranslatedContentTest extends \TYPO3\CMS\Core\Tests\Functional\DataHandlin
                     ],
                     299 => [
                         'header' => '[Translate to Dansk:] Regular Element #3',
-                        'image' => []
+                        'image' => [],
                     ],
                     303 => [
                         'header' => '[DK] Without default language',
@@ -254,6 +264,7 @@ class TranslatedContentTest extends \TYPO3\CMS\Core\Tests\Functional\DataHandlin
                     297 => [
                         'header' => '[Translate to Dansk:] Regular Element #1',
                         'image' => ['T3BOARD'],
+                        'categories' => ['[Translate to Dansk:] Category 1', 'Category 3 - not translated'],
 
                     ],
                     298 => [
@@ -281,7 +292,7 @@ class TranslatedContentTest extends \TYPO3\CMS\Core\Tests\Functional\DataHandlin
                     297 => [
                         'header' => '[Translate to Dansk:] Regular Element #1',
                         'image' => ['T3BOARD'],
-
+                        'categories' => ['[Translate to Dansk:] Category 1', 'Category 3 - not translated'],
                     ],
                     298 => [
                         'header' => 'Regular Element #2',
@@ -308,6 +319,7 @@ class TranslatedContentTest extends \TYPO3\CMS\Core\Tests\Functional\DataHandlin
                     297 => [
                         'header' => '[Translate to Dansk:] Regular Element #1',
                         'image' => [],
+                        'categories' => ['[Translate to Dansk:] Category 1'],
                     ],
                     299 => [
                         'header' => '[Translate to Dansk:] Regular Element #3',
@@ -326,6 +338,7 @@ class TranslatedContentTest extends \TYPO3\CMS\Core\Tests\Functional\DataHandlin
                     297 => [
                         'header' => '[Translate to Dansk:] Regular Element #1',
                         'image' => ['T3BOARD'],
+                        'categories' => ['[Translate to Dansk:] Category 1', 'Category 3 - not translated'],
 
                     ],
                     298 => [
@@ -353,6 +366,7 @@ class TranslatedContentTest extends \TYPO3\CMS\Core\Tests\Functional\DataHandlin
                     297 => [
                         'header' => '[Translate to Dansk:] Regular Element #1',
                         'image' => ['T3BOARD'],
+                        'categories' => ['[Translate to Dansk:] Category 1', 'Category 3 - not translated'],
 
                     ],
                     298 => [
@@ -373,8 +387,8 @@ class TranslatedContentTest extends \TYPO3\CMS\Core\Tests\Functional\DataHandlin
                     ],
                 ],
             ],
-//             Expected behaviour:
-//             Not translated element #2 is shown because sys_language_overlay = 1 (with sys_language_overlay = hideNonTranslated, it would be hidden)
+            // Expected behaviour:
+            // Not translated element #2 is shown because sys_language_overlay = 1 (with sys_language_overlay = hideNonTranslated, it would be hidden)
             [
                 'typoScript' => 'config.sys_language_overlay = 1
                                 config.sys_language_mode = content_fallback',
@@ -382,6 +396,7 @@ class TranslatedContentTest extends \TYPO3\CMS\Core\Tests\Functional\DataHandlin
                     297 => [
                         'header' => '[Translate to Dansk:] Regular Element #1',
                         'image' => ['T3BOARD'],
+                        'categories' => ['[Translate to Dansk:] Category 1', 'Category 3 - not translated'],
 
                     ],
                     298 => [
@@ -402,9 +417,8 @@ class TranslatedContentTest extends \TYPO3\CMS\Core\Tests\Functional\DataHandlin
                     ],
                 ],
             ],
-//             Expected behaviour:
-//             Same as config.sys_language_mode = content_fallback because we're requesting language 1, so no additional fallback possible
-
+            // Expected behaviour:
+            // Same as config.sys_language_mode = content_fallback because we're requesting language 1, so no additional fallback possible
             [
                 'typoScript' => 'config.sys_language_overlay = 1
                                 config.sys_language_mode = content_fallback;1,0',
@@ -412,6 +426,7 @@ class TranslatedContentTest extends \TYPO3\CMS\Core\Tests\Functional\DataHandlin
                     297 => [
                         'header' => '[Translate to Dansk:] Regular Element #1',
                         'image' => ['T3BOARD'],
+                        'categories' => ['[Translate to Dansk:] Category 1', 'Category 3 - not translated'],
                     ],
                     298 => [
                         'header' => 'Regular Element #2',
@@ -438,6 +453,7 @@ class TranslatedContentTest extends \TYPO3\CMS\Core\Tests\Functional\DataHandlin
                     297 => [
                         'header' => '[Translate to Dansk:] Regular Element #1',
                         'image' => [],
+                        'categories' => ['[Translate to Dansk:] Category 1'],
                     ],
                     299 => [
                         'header' => '[Translate to Dansk:] Regular Element #3',
@@ -456,7 +472,7 @@ class TranslatedContentTest extends \TYPO3\CMS\Core\Tests\Functional\DataHandlin
                     297 => [
                         'header' => '[Translate to Dansk:] Regular Element #1',
                         'image' => ['T3BOARD'],
-
+                        'categories' => ['[Translate to Dansk:] Category 1', 'Category 3 - not translated'],
                     ],
                     298 => [
                         'header' => 'Regular Element #2',
@@ -476,8 +492,10 @@ class TranslatedContentTest extends \TYPO3\CMS\Core\Tests\Functional\DataHandlin
                     ],
                 ],
             ],
-//             Expected behaviour:
-//             Non translated default language elements are not shown, because of hideNonTranslated
+            // Expected behaviour:
+            // Non translated default language elements are not shown, because of hideNonTranslated.
+            // Here we see it's not working - Regular Element #2 is still shown despite it's not translated to Dansk
+            // The same with relations (images and categories)
             10 => [
                 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
                                 config.sys_language_mode =',
@@ -485,7 +503,7 @@ class TranslatedContentTest extends \TYPO3\CMS\Core\Tests\Functional\DataHandlin
                     297 => [
                         'header' => '[Translate to Dansk:] Regular Element #1',
                         'image' => ['T3BOARD'],
-
+                        'categories' => ['[Translate to Dansk:] Category 1', 'Category 3 - not translated'],
                     ],
                     298 => [
                         'header' => 'Regular Element #2',
@@ -512,7 +530,7 @@ class TranslatedContentTest extends \TYPO3\CMS\Core\Tests\Functional\DataHandlin
                     297 => [
                         'header' => '[Translate to Dansk:] Regular Element #1',
                         'image' => ['T3BOARD'],
-
+                        'categories' => ['[Translate to Dansk:] Category 1', 'Category 3 - not translated'],
                     ],
                     298 => [
                         'header' => 'Regular Element #2',
@@ -539,7 +557,7 @@ class TranslatedContentTest extends \TYPO3\CMS\Core\Tests\Functional\DataHandlin
                     297 => [
                         'header' => '[Translate to Dansk:] Regular Element #1',
                         'image' => ['T3BOARD'],
-
+                        'categories' => ['[Translate to Dansk:] Category 1', 'Category 3 - not translated'],
                     ],
                     298 => [
                         'header' => 'Regular Element #2',
@@ -559,7 +577,9 @@ class TranslatedContentTest extends \TYPO3\CMS\Core\Tests\Functional\DataHandlin
                     ],
                 ],
             ],
-//            Setting sys_language_mode = strict has the same effect as previous data sets, because the translation of the page exists
+            // Expected behaviour: Setting sys_language_mode = strict has the same effect as previous data sets,
+            // because the translation of the page exists
+            // This is not true in Extbase unfortunately. As visible here: sys_language_mode = strict, works like overlay = 0 in TypoScript rendering.
             [
                 'typoScript' => 'config.sys_language_overlay = hideNonTranslated
                                 config.sys_language_mode = strict',
@@ -567,6 +587,7 @@ class TranslatedContentTest extends \TYPO3\CMS\Core\Tests\Functional\DataHandlin
                     297 => [
                         'header' => '[Translate to Dansk:] Regular Element #1',
                         'image' => [],
+                        'categories' => ['[Translate to Dansk:] Category 1'],
                     ],
                     299 => [
                         'header' => '[Translate to Dansk:] Regular Element #3',
@@ -585,6 +606,7 @@ class TranslatedContentTest extends \TYPO3\CMS\Core\Tests\Functional\DataHandlin
                     297 => [
                         'header' => '[Translate to Dansk:] Regular Element #1',
                         'image' => ['T3BOARD'],
+                        'categories' => ['[Translate to Dansk:] Category 1', 'Category 3 - not translated'],
                     ],
                     298 => [
                         'header' => 'Regular Element #2',
@@ -648,6 +670,16 @@ class TranslatedContentTest extends \TYPO3\CMS\Core\Tests\Functional\DataHandlin
             $this->assertThat($responseSections, $this->getRequestSectionStructureDoesNotHaveRecordConstraint()
                 ->setRecordIdentifier(self::TABLE_Content . ':' . $ttContentUid)->setRecordField('image')
                 ->setTable('sys_file_reference')->setField('title')->setValues(...$this->getNonVisibleFileTitles($visibleFileTitles)));
+
+            $visibleCategoryTitles = $properties['categories'] ?? [];
+            if (!empty($visibleCategoryTitles)) {
+                $this->assertThat($responseSections, $this->getRequestSectionStructureHasRecordConstraint()
+                    ->setRecordIdentifier(self::TABLE_Content . ':' . $ttContentUid)->setRecordField('categories')
+                    ->setTable('sys_category')->setField('title')->setValues(...$visibleCategoryTitles));
+            }
+            $this->assertThat($responseSections, $this->getRequestSectionStructureDoesNotHaveRecordConstraint()
+                ->setRecordIdentifier(self::TABLE_Content . ':' . $ttContentUid)->setRecordField('categories')
+                ->setTable('sys_category')->setField('title')->setValues(...$this->getNonVisibleCategoryTitles($visibleCategoryTitles)));
         }
     }
 
@@ -1155,4 +1187,21 @@ class TranslatedContentTest extends \TYPO3\CMS\Core\Tests\Functional\DataHandlin
         ];
         return array_diff($allElements, $visibleTitles);
     }
+
+    /**
+     * Helper function to ease asserting that rest of the data set is not visible
+     *
+     * @param array $visibleTitles
+     * @return array
+     */
+    protected function getNonVisibleCategoryTitles(array $visibleTitles): array
+    {
+        $allElements = [
+            'Category 1',
+            '[Translate to Dansk:] Category 1',
+            'Category 3 - not translated',
+            'Category 4',
+        ];
+        return array_diff($allElements, $visibleTitles);
+    }
 }
index 173d9be..837a3fd 100644 (file)
@@ -4,20 +4,20 @@
 ,2,0,0,"Deutsch","de",,,,,,,,,,,,,,,,,,
 ,3,0,0,"Polski","pl",,,,,,,,,,,,,,,,,,
 "tt_content",,,,,,,,,,,,,,,,,,,,,,,
-,"uid","pid","header","image","sorting","deleted","hidden","sys_language_uid","l18n_parent","l10n_source","t3_origuid","t3ver_wsid","t3ver_state","t3ver_stage","t3ver_oid","t3ver_move_id",,,,,,,
-,297,89,"Regular Element #1",1,256,0,0,0,0,0,0,0,0,0,0,0,,,,,,,
-,298,89,"Regular Element #2",1,512,0,0,0,0,0,0,0,0,0,0,0,,,,,,,
-,299,89,"Regular Element #3",0,768,0,0,0,0,0,0,0,0,0,0,0,,,,,,,
-,300,89,"[Translate to Dansk:] Regular Element #3",2,1024,0,0,1,299,299,299,0,0,0,0,0,,,,,,,
-,301,89,"[Translate to Dansk:] Regular Element #1",0,384,0,0,1,297,297,297,0,0,0,0,0,,,,,,,
-,302,89,"[Translate to Deutsch:] [Translate to Dansk:] Regular Element #1",1,448,0,0,2,297,301,301,0,0,0,0,0,,,,,,,
-,303,89,"[DK] Without default language",1,1250,0,0,1,0,0,0,0,0,0,0,0,,,,,,,
-,304,89,"[DE] Without default language",0,1250,0,0,2,0,0,0,0,0,0,0,0,,,,,,,
-,305,89,"[Translate to Polski:] Regular Element #1",0,512,0,0,3,297,297,297,0,0,0,0,0,,,,,,,
-,306,89,"[PL] Without default language",0,1024,0,0,3,0,0,0,0,0,0,0,0,,,,,,,
-,307,89,"Hidden Element #4",0,128,0,1,0,0,0,0,0,0,0,0,0,,,,,,,
-,308,89,"[DK] UnHidden Element #4",0,128,0,0,1,307,307,307,0,0,0,0,0,,,,,,,
-,309,89,"[PL] Hidden Regular Element #2",0,512,0,1,3,298,298,298,0,0,0,0,0,,,,,,,
+,"uid","pid","header","image","sorting","deleted","hidden","sys_language_uid","l18n_parent","l10n_source","t3_origuid","t3ver_wsid","t3ver_state","t3ver_stage","t3ver_oid","t3ver_move_id","categories",,,,,,
+,297,89,"Regular Element #1",1,256,0,0,0,0,0,0,0,0,0,0,0,2,,,,,,
+,298,89,"Regular Element #2",1,512,0,0,0,0,0,0,0,0,0,0,0,0,,,,,,
+,299,89,"Regular Element #3",0,768,0,0,0,0,0,0,0,0,0,0,0,0,,,,,,
+,300,89,"[Translate to Dansk:] Regular Element #3",2,1024,0,0,1,299,299,299,0,0,0,0,0,0,,,,,,
+,301,89,"[Translate to Dansk:] Regular Element #1",0,384,0,0,1,297,297,297,0,0,0,0,0,2,,,,,,
+,302,89,"[Translate to Deutsch:] [Translate to Dansk:] Regular Element #1",1,448,0,0,2,297,301,301,0,0,0,0,0,0,,,,,,
+,303,89,"[DK] Without default language",1,1250,0,0,1,0,0,0,0,0,0,0,0,0,,,,,,
+,304,89,"[DE] Without default language",0,1250,0,0,2,0,0,0,0,0,0,0,0,0,,,,,,
+,305,89,"[Translate to Polski:] Regular Element #1",0,512,0,0,3,297,297,297,0,0,0,0,0,0,,,,,,
+,306,89,"[PL] Without default language",0,1024,0,0,3,0,0,0,0,0,0,0,0,0,,,,,,
+,307,89,"Hidden Element #4",0,128,0,1,0,0,0,0,0,0,0,0,0,0,,,,,,
+,308,89,"[DK] UnHidden Element #4",0,128,0,0,1,307,307,307,0,0,0,0,0,0,,,,,,
+,309,89,"[PL] Hidden Regular Element #2",0,512,0,1,3,298,298,298,0,0,0,0,0,0,,,,,,
 ,,,,,,,,,,,,,,,,,,,,,,,
 ,,,,,,,,,,,,,,,,,,,,,,,
 ,,,,,,,,,,,,,,,,,,,,,,,
 ,129,89,"[T3BOARD] Image added in Dansk (without parent)",1,300,1,0,0,0,0,0,0,0,0,0,"tt_content","image",2,"sys_file",,,,
 ,130,89,"[T3BOARD] Image added to DK element without default language",1,303,1,0,0,0,0,0,0,0,0,0,"tt_content","image",1,"sys_file",,,,
 ,131,89,"[T3BOARD] image translated to DE from DK",1,302,2,0,0,0,0,0,0,0,0,0,"tt_content","image",1,"sys_file",,,,
+"sys_category",,,,,,,,,,,,,,,,,,,,,,,
+,"uid","pid","title","sys_language_uid","l10n_parent","t3ver_wsid","t3ver_state","t3ver_stage","t3ver_oid","t3ver_move_id","deleted",,,,,,,,,,,,
+,1,89,"Category 1",0,0,0,0,0,0,0,0,,,,,,,,,,,,
+,2,89,"[Translate to Dansk:] Category 1",1,1,0,0,0,0,0,0,,,,,,,,,,,,
+,3,89,"Category 3 - not translated",0,0,0,0,0,0,0,0,,,,,,,,,,,,
+,4,89,"Category 4",0,0,0,0,0,0,0,0,,,,,,,,,,,,
+"sys_category_record_mm",,,,,,,,,,,,,,,,,,,,,,,
+,"uid_local","uid_foreign","tablenames","fieldname","sorting","sorting_foreign",,,,,,,,,,,,,,,,,
+,1,297,"tt_content","categories",0,1,,,,,,,,,,,,,,,,,
+,3,297,"tt_content","categories",0,1,,,,,,,,,,,,,,,,,
+,1,301,"tt_content","categories",0,1,,,,,,,,,,,,,,,,,
+,4,301,"tt_content","categories",0,1,,,,,,,,,,,,,,,,,