[BUGFIX] Regression of "better condition in versionOL of t3lib_tstemplate"
authorandy.grunwald <andygrunwald@gmail.com>
Wed, 9 May 2012 08:45:56 +0000 (10:45 +0200)
committerSusanne Moog <typo3@susannemoog.de>
Sun, 20 May 2012 11:03:14 +0000 (13:03 +0200)
versionOL in t3lib_tstemplate can cause a fatal error for
scripts like eID that run in frontend mode, but without a full
blown frontend environment.

The patch replaces the frontend check with a more specific test
for the required methods.

Change-Id: Ib3f9ebf355ee820e5144dd484d9a3a5e7708ebd4
Related: #31139, #25144
Resolves: #36981
Releases: 6.0, 4.7, 4.6, 4.5
Reviewed-on: http://review.typo3.org/11096
Reviewed-by: Susanne Moog
Tested-by: Susanne Moog
t3lib/class.t3lib_tstemplate.php
tests/Unit/t3lib/class.t3lib_tstemplateTest.php [new file with mode: 0644]

index d27d714..f3e739a 100644 (file)
@@ -688,16 +688,26 @@ class t3lib_TStemplate {
        }
 
        /**
-        * Creating versioning overlay of a sys_template record. This will use either frontend or backend overlay functionality depending on environment.
+        * Creating versioning overlay of a sys_template record.
+        * This will use either frontend or backend overlay functionality depending on environment.
         *
         * @param array $row Row to overlay (passed by reference)
         * @return void
         */
        function versionOL(&$row) {
-                       // Frontend:
-               if (TYPO3_MODE === 'FE') {
+                       // Distinguish frontend and backend call:
+                       // To do the fronted call a full frontend is required, just checking for
+                       // TYPO3_MODE === 'FE' is not enough. This could otherwise lead to fatals in
+                       // eId scripts that run in frontend scope, but do not have a full blown frontend.
+               if (
+                       is_object($GLOBALS['TSFE']) === TRUE
+                       && property_exists($GLOBALS['TSFE'], 'sys_page') === TRUE
+                       && method_exists($GLOBALS['TSFE']->sys_page, 'versionOL') === TRUE
+               ) {
+                               // Frontend
                        $GLOBALS['TSFE']->sys_page->versionOL('sys_template', $row);
-               } else { // Backend:
+               } else {
+                               // Backend
                        t3lib_BEfunc::workspaceOL('sys_template', $row);
                }
        }
diff --git a/tests/Unit/t3lib/class.t3lib_tstemplateTest.php b/tests/Unit/t3lib/class.t3lib_tstemplateTest.php
new file mode 100644 (file)
index 0000000..8eba72a
--- /dev/null
@@ -0,0 +1,63 @@
+<?php
+/***************************************************************
+* Copyright notice
+*
+* (c) 2012 Christian Kuhn <lolli@schwarzbu.ch>
+* All rights reserved
+*
+* This script is part of the TYPO3 project. The TYPO3 project is
+* free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation; either version 2 of the License, or
+* (at your option) any later version.
+*
+* The GNU General Public License can be found at
+* http://www.gnu.org/copyleft/gpl.html.
+*
+* This script is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU General Public License for more details.
+*
+* This copyright notice MUST APPEAR in all copies of the script!
+***************************************************************/
+
+/**
+ * Testcase for the t3lib_tstemplate class in the TYPO3 core.
+ *
+ * @package TYPO3
+ * @subpackage t3lib
+ * @author Christian Kuhn <lolli@schwarzbu.ch>
+ */
+class t3lib_tstemplateTest extends tx_phpunit_testcase {
+
+       /**
+        * 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');
+
+       /**
+        * @test
+        */
+       public function versionOlCallsVersionOlOfPageSelectClassWithGivenRow() {
+               $row = array('foo');
+               $GLOBALS['TSFE'] = new stdClass();
+               $sysPageMock = $this->getMock('t3lib_pageSelect');
+               $sysPageMock->expects($this->once())->method('versionOL')->with('sys_template', $row);
+               $GLOBALS['TSFE']->sys_page = $sysPageMock;
+
+               $instance = new t3lib_TStemplate();
+               $instance->versionOL($row);
+       }
+}
+?>
\ No newline at end of file