[BUGFIX] Better mocking in BackendUtility::viewOnClick test 48/24748/2
authorChristian Kuhn <lolli@schwarzbu.ch>
Mon, 14 Oct 2013 18:49:36 +0000 (20:49 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Mon, 14 Oct 2013 20:11:07 +0000 (22:11 +0200)
BackendUtility::viewOnClick() provides a hook to manipulate the
generated URL. ext:workspaces uses this. The patch adapts a
viewOnClick() test to unset possible registered hooks and prevents
unrelated code from messing with the test.

Change-Id: I4977575446bf898224583010ae7a2d34e145e147
Resolves: #52813
Releases: 6.2
Reviewed-on: https://review.typo3.org/24748
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
typo3/sysext/backend/Classes/Utility/BackendUtility.php
typo3/sysext/backend/Tests/Unit/Utility/BackendUtilityTest.php
typo3/sysext/core/Build/UnitTestsBootstrap.php

index fee13ba..6e557d5 100644 (file)
@@ -2564,7 +2564,10 @@ class BackendUtility {
                        $viewScript = $alternativeUrl;
                }
 
-               if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['viewOnClickClass']) && is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['viewOnClickClass'])) {
+               if (
+                       isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['viewOnClickClass'])
+                       && is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['viewOnClickClass'])
+               ) {
                        foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['viewOnClickClass'] as $funcRef) {
                                $hookObj = GeneralUtility::getUserObj($funcRef);
                                if (method_exists($hookObj, 'preProcess')) {
index e316abc..3e568fa 100644 (file)
@@ -681,9 +681,16 @@ class BackendUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function viewOnClickReturnsOnClickCodeWithAlternativeUrl() {
+               // Make sure the hook inside viewOnClick is not fired. This may be removed if unit tests
+               // bootstrap does not initialize TYPO3_CONF_VARS anymore.
+               unset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['viewOnClickClass']);
+
                $alternativeUrl = 'https://typo3.org/about/typo3-the-cms/the-history-of-typo3/#section';
                $onclickCode = 'var previewWin = window.open(\'' . $alternativeUrl . '\',\'newTYPO3frontendWindow\');';
-               $this->assertStringMatchesFormat($onclickCode, BackendUtility::viewOnClick(NULL, NULL, NULL, NULL, $alternativeUrl, NULL, FALSE));
+               $this->assertStringMatchesFormat(
+                       $onclickCode,
+                       BackendUtility::viewOnClick(NULL, NULL, NULL, NULL, $alternativeUrl, NULL, FALSE)
+               );
        }
 
        /**
index 35fcf9b..fb7adb6 100644 (file)
@@ -116,10 +116,4 @@ require PATH_site . '/typo3/sysext/core/Classes/Core/Bootstrap.php';
 $GLOBALS['BE_USER']->user = array(
        'uid' => 42,
        'username' => 'unit_test_fake_user',
-);
-
-/**
- * This is needed for the viewOnClick test not to fail if workspace extension is installed
- * TODO: properly mock these tests
- */
-$GLOBALS['BE_USER']->workspace = 0;
\ No newline at end of file
+);
\ No newline at end of file