diff --git a/typo3/sysext/frontend/Classes/Page/PageRepository.php b/typo3/sysext/frontend/Classes/Page/PageRepository.php index 63c302c24faecfb45c9dfc24c8bf7879b6dc9136..9640cf3d3ccc84d0e1e0f82474ff9d6fa4ffd9af 100644 --- a/typo3/sysext/frontend/Classes/Page/PageRepository.php +++ b/typo3/sysext/frontend/Classes/Page/PageRepository.php @@ -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()) diff --git a/typo3/sysext/frontend/Tests/Unit/Page/PageRepositoryTest.php b/typo3/sysext/frontend/Tests/Unit/Page/PageRepositoryTest.php index 2aa2c316c35dee748dfd2e5773aadffc7cd3d1d0..a681bb4e3fd2efdd96e5b4fd9059853a78930a8b 100644 --- a/typo3/sysext/frontend/Tests/Unit/Page/PageRepositoryTest.php +++ b/typo3/sysext/frontend/Tests/Unit/Page/PageRepositoryTest.php @@ -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