[FEATURE] Improved translation handling for statement generation
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Persistence / Storage / Typo3DbBackendTest.php
index f69442a..004754b 100644 (file)
 
 class Tx_Extbase_Tests_Unit_Persistence_Storage_Typo3DbBackendTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
 
+       /**
+        * Enable backup of global and system variables
+        *
+        * @var boolean
+        */
+       protected $backupGlobals = true;
+
+       /**
+        * Exclude TYPO3_DB from backup/ restore of $GLOBALS
+        * because resource types cannot be handled during serializing
+        *
+        * @var array
+        */
+       protected $backupGlobalsBlacklist = array('TYPO3_DB');
+
        /**
         * This is the data provider for the statement generation with a basic comparison
         *
@@ -87,6 +102,118 @@ class Tx_Extbase_Tests_Unit_Persistence_Storage_Typo3DbBackendTest extends Tx_Ex
                $this->markTestIncomplete();
        }
 
+       /**
+        * @test
+        */
+       public function addSysLanguageStatementWorksForDefaultLanguage() {
+               $table = uniqid('tx_coretest_table');
+               $GLOBALS['TCA'][$table]['ctrl'] = array(
+                       'languageField' => 'sys_language_uid'
+               );
+
+               $tsfe = $this->getMock('tslib_fe', array(), array(), '', false);
+               $tsfe->sys_language_uid = 0;
+               $GLOBALS['TSFE'] = $tsfe;
+
+               $sql = array();
+               $mockTypo3DbBackend = $this->getMock(
+                       $this->buildAccessibleProxy('Tx_Extbase_Persistence_Storage_Typo3DbBackend'),
+                       array('dummy'),
+                       array(),
+                       '',
+                       false);
+               $mockTypo3DbBackend->_callRef('addSysLanguageStatement', $table, $sql);
+
+               $expectedSql = array('additionalWhereClause' => array('(' . $table . '.sys_language_uid IN (0,-1))'));
+
+               $this->assertSame($expectedSql, $sql);
+       }
+
+       /**
+        * @test
+        */
+       public function addSysLanguageStatementWorksForDefaultLanguageWithoutDeleteStatementReturned() {
+               $table = uniqid('tx_coretest_table');
+               $GLOBALS['TCA'][$table]['ctrl'] = array(
+                       'languageField' => 'sys_language_uid',
+                       'delete' => 'deleted'
+               );
+
+               $tsfe = $this->getMock('tslib_fe', array(), array(), '', false);
+               $tsfe->sys_language_uid = 0;
+               $GLOBALS['TSFE'] = $tsfe;
+
+               $sql = array();
+               $mockTypo3DbBackend = $this->getMock(
+                       $this->buildAccessibleProxy('Tx_Extbase_Persistence_Storage_Typo3DbBackend'),
+                       array('dummy'),
+                       array(),
+                       '',
+                       false);
+               $mockTypo3DbBackend->_callRef('addSysLanguageStatement', $table, $sql);
+
+               $expectedSql = array('additionalWhereClause' => array('(' . $table . '.sys_language_uid IN (0,-1))'));
+
+               $this->assertSame($expectedSql, $sql);
+       }
+
+       /**
+        * @test
+        */
+       public function addSysLanguageStatementWorksForForeignLanguageWithoutSubselection() {
+               $table = uniqid('tx_coretest_table');
+               $GLOBALS['TCA'][$table]['ctrl'] = array(
+                       'languageField' => 'sys_language_uid'
+               );
+
+               $tsfe = $this->getMock('tslib_fe', array(), array(), '', false);
+               $tsfe->sys_language_uid = 2;
+               $GLOBALS['TSFE'] = $tsfe;
+
+               $sql = array();
+               $mockTypo3DbBackend = $this->getMock(
+                       $this->buildAccessibleProxy('Tx_Extbase_Persistence_Storage_Typo3DbBackend'),
+                       array('dummy'),
+                       array(),
+                       '',
+                       false);
+               $mockTypo3DbBackend->_callRef('addSysLanguageStatement', $table, $sql);
+
+               $expectedSql = array('additionalWhereClause' => array('(' . $table . '.sys_language_uid IN (2,-1))'));
+
+               $this->assertSame($expectedSql, $sql);
+       }
+
+       /**
+        * @test
+        */
+       public function addSysLanguageStatementWorksForForeignLanguageWithSubselectionWithoutDeleteStatementReturned() {
+               $table = uniqid('tx_coretest_table');
+               $GLOBALS['TCA'][$table]['ctrl'] = array(
+                       'languageField' => 'sys_language_uid',
+                       'transOrigPointerField' => 'l18n_parent'
+               );
+
+               $tsfe = $this->getMock('tslib_fe', array(), array(), '', false);
+               $tsfe->sys_language_uid = 2;
+               $GLOBALS['TSFE'] = $tsfe;
+
+               $sql = array();
+               $mockTypo3DbBackend = $this->getMock(
+                       $this->buildAccessibleProxy('Tx_Extbase_Persistence_Storage_Typo3DbBackend'),
+                       array('dummy'),
+                       array(),
+                       '',
+                       false);
+               $mockTypo3DbBackend->_callRef('addSysLanguageStatement', $table, $sql);
+
+               $expectedSql = array('additionalWhereClause' => array('(' . $table . '.sys_language_uid IN (2,-1) OR (' .
+                       $table . '.sys_language_uid=0 AND ' . $table . '.uid NOT IN (SELECT ' . $table . '.l18n_parent FROM ' . $table .
+                       ' WHERE ' . $table . '.l18n_parent>0 AND ' . $table . '.sys_language_uid>0)))'));
+
+               $this->assertSame($expectedSql, $sql);
+       }
+
        /**
         * @test
         */
@@ -99,7 +226,7 @@ class Tx_Extbase_Tests_Unit_Persistence_Storage_Typo3DbBackendTest extends Tx_Ex
                $mockDataMapper->expects($this->once())->method('convertPropertyNameToColumnName')->with('fooProperty', 'Tx_MyExt_ClassName')->will($this->returnValue('converted_fieldname'));
 
                $sql = array();
-               $orderings = array('fooProperty' => Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_ORDER_ASCENDING);
+               $orderings = array('fooProperty' => Tx_Extbase_Persistence_QueryInterface::ORDER_ASCENDING);
                $mockTypo3DbBackend = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Persistence_Storage_Typo3DbBackend'), array('parserOrderings'), array(), '', FALSE);
                $mockTypo3DbBackend->_set('dataMapper', $mockDataMapper);
                $mockTypo3DbBackend->_callRef('parseOrderings', $orderings, $mockSource, $sql);
@@ -140,8 +267,8 @@ class Tx_Extbase_Tests_Unit_Persistence_Storage_Typo3DbBackendTest extends Tx_Ex
 
                $sql = array();
                $orderings = array(
-                       'fooProperty' => Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_ORDER_ASCENDING,
-                       'barProperty' => Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_ORDER_DESCENDING
+                       'fooProperty' => Tx_Extbase_Persistence_QueryInterface::ORDER_ASCENDING,
+                       'barProperty' => Tx_Extbase_Persistence_QueryInterface::ORDER_DESCENDING
                        );
                $mockTypo3DbBackend = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Persistence_Storage_Typo3DbBackend'), array('parserOrderings'), array(), '', FALSE);
                $mockTypo3DbBackend->_set('dataMapper', $mockDataMapper);
@@ -151,5 +278,53 @@ class Tx_Extbase_Tests_Unit_Persistence_Storage_Typo3DbBackendTest extends Tx_Ex
                $this->assertSame($expecedSql, $sql);
        }
 
+       /**
+        * @test
+        */
+       public function doLanguageAndWorkspaceOverlayChangesUidIfInPreview() {
+               $comparisonRow = array(
+                       'uid' => '43',
+                       'pid' => '42',
+                       '_ORIG_pid' => '-1',
+                       '_ORIG_uid' => '43'
+               );
+
+               $row = array(
+                       'uid' => '42',
+                       'pid' => '42',
+               );
+
+               $workspaceVersion = array(
+                       'uid' => '43',
+                       'pid' => '-1',
+               );
+
+               $languageUid = 2;
+               $workspaceUid = 2;
+
+               $sourceMock = new Tx_Extbase_Persistence_QOM_Selector('tx_foo', 'Tx_Foo');
+
+               /** @var $pageSelectMock t3lib_pageSelect|PHPUnit_Framework_MockObject_MockObject */
+               $pageSelectMock = $this->getMock('t3lib_pageSelect', array('movePlhOL', 'getWorkspaceVersionOfRecord'));
+               $pageSelectMock->versioningPreview = TRUE;
+
+               $pageSelectMock->expects($this->once())
+                       ->method('getWorkspaceVersionOfRecord')
+                       ->with($workspaceUid, 'tx_foo', '42')
+                       ->will($this->returnValue($workspaceVersion));
+
+               $mockTypo3DbBackend = $this->getAccessibleMock(
+                       'Tx_Extbase_Persistence_Storage_Typo3DbBackend',
+                       array('dummy'),
+                       array(), '', FALSE);
+
+
+               $mockTypo3DbBackend->_set('pageSelectObject', $pageSelectMock);
+
+               $this->assertSame(
+                       array($comparisonRow),
+                       $mockTypo3DbBackend->_call('doLanguageAndWorkspaceOverlay', $sourceMock, array($row), $languageUid, $workspaceUid)
+               );
+       }
 }
 ?>
\ No newline at end of file