[BUGFIX] Fix failing test in StorageRepositoryTest 36/22836/9
authorAnja Leichsenring <aleichsenring@ab-softlab.de>
Tue, 6 Aug 2013 08:18:00 +0000 (10:18 +0200)
committerNicole Cordes <typo3@cordes.co>
Tue, 6 Aug 2013 12:18:24 +0000 (14:18 +0200)
With #50803 the usage of the constant TYPO3_MODE was introduced. This
leads to the failing test, after the constant can not be redefined
for test purposes.

To work around this, a method that can be mocked is introduced, and
specifically set to "FE" for this test to work again.

Resolves: #50809
Relates: #50803
Releases: 6.2, 6.1, 6.0
Change-Id: I7319d8ccef530feff69a7f9885df24dba0beed4d
Reviewed-on: https://review.typo3.org/22836
Reviewed-by: Ernesto Baschny
Tested-by: Ernesto Baschny
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
Reviewed-by: Nicole Cordes
Tested-by: Nicole Cordes
typo3/sysext/core/Classes/Resource/StorageRepository.php
typo3/sysext/core/Tests/Unit/Resource/StorageRepositoryTest.php

index 5c91824..ea07d20 100644 (file)
@@ -206,7 +206,7 @@ class StorageRepository extends AbstractRepository {
         * @return string the additional where clause, something like " AND deleted=0 AND hidden=0"
         */
        protected function getWhereClauseForEnabledFields() {
-               if (TYPO3_MODE === 'FE') {
+               if ($this->getEnvironmentMode() === 'FE') {
                        // frontend context
                        $whereClause = $GLOBALS['TSFE']->sys_page->enableFields($this->table);
                        $whereClause .= $GLOBALS['TSFE']->sys_page->deleteClause($this->table);
@@ -217,6 +217,16 @@ class StorageRepository extends AbstractRepository {
                }
                return $whereClause;
        }
+
+       /**
+        * Function to return the current TYPO3_MODE.
+        * This function can be mocked in unit tests to be able to test frontend behaviour.
+        *
+        * @return string
+        */
+       protected function getEnvironmentMode() {
+               return TYPO3_MODE;
+       }
 }
 
 
index a577281..50346aa 100644 (file)
@@ -60,11 +60,12 @@ class StorageRepositoryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                        ->with('sys_file_storage');
                $storageRepositoryMock = $this->getAccessibleMock(
                        'TYPO3\\CMS\\Core\\Resource\\StorageRepository',
-                       array('dummy'),
+                       array('getEnvironmentMode'),
                        array(),
                        '',
                        FALSE
                );
+               $storageRepositoryMock->expects($this->any())->method('getEnvironmentMode')->will($this->returnValue('FE'));
                $storageRepositoryMock->_call('getWhereClauseForEnabledFields');
        }
 }