[BUGFIX] Don't show duplicates in workspace preview 27/11127/12
authorTimo Webler <timo.webler@dkd.de>
Mon, 3 Dec 2012 08:51:02 +0000 (09:51 +0100)
committerStefan Neufeind <typo3.neufeind@speedpartner.de>
Mon, 23 Sep 2013 23:37:43 +0000 (01:37 +0200)
Fixed workspace filters in case of workspace preview
in TYPO3\CMS\Frontend\Page\PageRepository::enableFields().

Additionally cleared up the corresponding comments.

Change-Id: I088928a88cb673f18f218ef691a6c528019317c0
Fixes: #37065
Releases: 6.2, 6.1, 6.0, 4.5
Reviewed-on: https://review.typo3.org/11127
Reviewed-by: Sascha Egerer
Tested-by: Sascha Egerer
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
Reviewed-by: Stefan Neufeind
Tested-by: Stefan Neufeind
typo3/sysext/frontend/Classes/Page/PageRepository.php
typo3/sysext/frontend/Tests/Unit/Page/PageRepositoryTest.php

index 63c302c..9640cf3 100644 (file)
@@ -866,11 +866,28 @@ class PageRepository {
                        if ($ctrl['delete']) {
                                $query .= ' AND ' . $table . '.' . $ctrl['delete'] . '=0';
                        }
-                       // Filter out new place-holder records in case we are NOT in a versioning preview (that means we are online!)
-                       if ($ctrl['versioningWS'] && !$this->versioningPreview) {
-                               // Shadow state for new items MUST be ignored!
-                               $query .= ' AND ' . $table . '.t3ver_state<=0 AND ' . $table . '.pid<>-1';
+                       if ($ctrl['versioningWS']) {
+                               if (!$this->versioningPreview) {
+                                       // Filter out placeholder records (new/moved/deleted items)
+                                       // in case we are NOT in a versioning preview (that means we are online!)
+                                       $query .= ' AND ' . $table . '.t3ver_state<=0';
+                               } else {
+                                       if ($table !== 'pages') {
+                                               // show only records of live and of the current workspace
+                                               // in case we are in a versioning preview
+                                               $query .= ' AND (' .
+                                                                       $table . '.t3ver_wsid=0 OR ' .
+                                                                       $table . '.t3ver_wsid=' . intval($this->versioningWorkspaceId) .
+                                                                       ')';
+                                       }
+                               }
+
+                               // Filter out versioned records
+                               if (!$noVersionPreview) {
+                                       $query .= ' AND ' . $table . '.pid<>-1';
+                               }
                        }
+
                        // Enable fields:
                        if (is_array($ctrl['enablecolumns'])) {
                                // In case of versioning-preview, enableFields are ignored (checked in versionOL())
index 2aa2c31..a681bb4 100644 (file)
@@ -47,7 +47,8 @@ class PageRepositoryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        public function setUp() {
                $this->typo3DbBackup = $GLOBALS['TYPO3_DB'];
                $GLOBALS['TYPO3_DB'] = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection', array('exec_SELECTquery', 'sql_fetch_assoc', 'sql_free_result'));
-               $this->pageSelectObject = new \TYPO3\CMS\Frontend\Page\PageRepository();
+               $this->pageSelectObject = $this->getMock('TYPO3\\CMS\\Frontend\\Page\\PageRepository', array('getMultipleGroupsWhereClause'));
+               $this->pageSelectObject->expects($this->any())->method('getMultipleGroupsWhereClause')->will($this->returnValue(' AND 1=1'));
        }
 
        /**
@@ -119,6 +120,64 @@ class PageRepositoryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                )));
        }
 
+
+       ////////////////////////////////
+       // Tests concerning versioning
+       ////////////////////////////////
+
+       /**
+        * @test
+        */
+       public function enableFieldsHidesVersionedRecordsAndPlaceholders() {
+               $this->pageSelectObject->versioningPreview = FALSE;
+               $this->pageSelectObject->init(FALSE);
+
+               $conditions = $this->pageSelectObject->enableFields('tt_content');
+
+               $this->assertThat($conditions, $this->stringContains(' AND tt_content.t3ver_state<=0'), 'Versioning placeholders');
+               $this->assertThat($conditions, $this->stringContains(' AND tt_content.pid<>-1'), 'Records from page -1');
+       }
+
+       /**
+        * @test
+        */
+       public function enableFieldsDoesNotHidePlaceholdersInPreview() {
+               $this->pageSelectObject->versioningPreview = TRUE;
+               $this->pageSelectObject->init(FALSE);
+
+               $conditions = $this->pageSelectObject->enableFields('tt_content');
+
+               $this->assertThat($conditions, $this->logicalNot($this->stringContains(' AND tt_content.t3ver_state<=0')), 'No versioning placeholders');
+               $this->assertThat($conditions, $this->stringContains(' AND tt_content.pid<>-1'), 'Records from page -1');
+       }
+
+       /**
+        * @test
+        */
+       public function enableFieldsDoesFilterToCurrentAndLiveWorkspaceForRecordsInPreview() {
+               $this->pageSelectObject->versioningPreview = TRUE;
+               $this->pageSelectObject->versioningWorkspaceId = 2;
+               $this->pageSelectObject->init(FALSE);
+
+               $conditions = $this->pageSelectObject->enableFields('tt_content');
+
+               $this->assertThat($conditions, $this->stringContains(' AND (tt_content.t3ver_wsid=0 OR tt_content.t3ver_wsid=2)'), 'No versioning placeholders');
+       }
+
+       /**
+        * @test
+        */
+       public function enableFieldsDoesNotHideVersionedRecordsWhenCheckingVersionOverlays() {
+               $this->pageSelectObject->versioningPreview = TRUE;
+               $this->pageSelectObject->init(FALSE);
+
+               $conditions = $this->pageSelectObject->enableFields('tt_content', -1, array(), TRUE     );
+
+               $this->assertThat($conditions, $this->logicalNot($this->stringContains(' AND tt_content.t3ver_state<=0')), 'No versioning placeholders');
+               $this->assertThat($conditions, $this->logicalNot($this->stringContains(' AND tt_content.pid<>-1')), 'No ecords from page -1');
+       }
+
+
 }
 
 ?>
\ No newline at end of file