[BUGFIX] Make showAccessRestrictedPages work 96/50696/8
authorClaus Due <claus@namelesscoder.net>
Thu, 17 Nov 2016 12:14:24 +0000 (13:14 +0100)
committerJan Helke <typo3@helke.de>
Fri, 2 Dec 2016 17:08:37 +0000 (18:08 +0100)
This patch fixes a problem where setting showAccessRestrictedPages
setting in HMENU etc. did not result in the correct behavior according
to documentation at https://docs.typo3.org/typo3cms/TyposcriptReference/MenuObjects/CommonProperties/Index.html.

The patch changes the behavior caused by using `NONE` as
keyword in the setting.

Before: using the option renders `<a>Page title</a>` when page is inaccessible.

After: using the option renders `<a href="index.php?id=123">Page title</a>`
when page is not accessible.

Change-Id: I4364f7ec9f44e1e0b70654830efc236f20e6bf30
Resolves: #17904
Releases: master, 7.6
Reviewed-on: https://review.typo3.org/50696
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Jan Helke <typo3@helke.de>
Tested-by: Jan Helke <typo3@helke.de>
typo3/sysext/core/Documentation/Changelog/master/Important-17904-ShowAccessRestrictedPagesDoesNotWorkWithSpecialMenus.rst [new file with mode: 0644]
typo3/sysext/frontend/Classes/ContentObject/Menu/AbstractMenuContentObject.php
typo3/sysext/frontend/Tests/Unit/ContentObject/Menu/AbstractMenuContentObjectTest.php

diff --git a/typo3/sysext/core/Documentation/Changelog/master/Important-17904-ShowAccessRestrictedPagesDoesNotWorkWithSpecialMenus.rst b/typo3/sysext/core/Documentation/Changelog/master/Important-17904-ShowAccessRestrictedPagesDoesNotWorkWithSpecialMenus.rst
new file mode 100644 (file)
index 0000000..537ffc0
--- /dev/null
@@ -0,0 +1,19 @@
+.. include:: ../../Includes.txt
+
+==============================================================================
+Important: #17904 - showAccessRestrictedPages does not work with special menus
+==============================================================================
+
+See :issue:`17904`
+
+Description
+===========
+
+HMENU setting `showAccessRestrictedPages`=NONE now acts as documented in https://docs.typo3.org/typo3cms/TyposcriptReference/MenuObjects/CommonProperties/Index.html.
+
+Before: using the option renders `<a>Page title</a>` when page is inaccessible.
+
+After: using the option renders `<a href="index.php?id=123">Page title</a>`
+when page is not accessible.
+
+.. index:: Frontend, TypoScript
\ No newline at end of file
index 21d5d74..b393990 100644 (file)
@@ -1627,7 +1627,7 @@ abstract class AbstractMenuContentObject
             $LD['totalURL'] = $this->parent_cObj->typoLink_URL([
                 'parameter' => $shortcut['uid'],
                 'additionalParams' => $addParams . $this->I['val']['additionalParams'] . $menuItem['_ADD_GETVARS'],
-                'linkAccessRestrictedPages' => $this->mconf['showAccessRestrictedPages'] && $this->mconf['showAccessRestrictedPages'] !== 'NONE'
+                'linkAccessRestrictedPages' => !empty($this->mconf['showAccessRestrictedPages'])
             ]);
         }
         if ($shortcut) {
@@ -2128,7 +2128,7 @@ abstract class AbstractMenuContentObject
         if ($page['sectionIndex_uid']) {
             $conf['section'] = $page['sectionIndex_uid'];
         }
-        $conf['linkAccessRestrictedPages'] = $this->mconf['showAccessRestrictedPages'] && $this->mconf['showAccessRestrictedPages'] !== 'NONE';
+        $conf['linkAccessRestrictedPages'] = !empty($this->mconf['showAccessRestrictedPages']);
         $this->parent_cObj->typoLink('|', $conf);
         $LD = $this->parent_cObj->lastTypoLinkLD;
         $LD['totalURL'] = $this->parent_cObj->lastTypoLinkUrl;
index 8c51e92..48afb14 100644 (file)
@@ -292,4 +292,253 @@ class AbstractMenuContentObjectTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
 
         $this->assertEquals($expectedResult, $this->subject->isItemState('IFSUB', 0));
     }
+
+    /**
+     * @return array
+     */
+    public function menuTypoLinkCreatesExpectedTypoLinkConfiurationDataProvider()
+    {
+        return [
+            'standard parameter without access protected setting' => [
+                [
+                    'parameter' => 1,
+                    'linkAccessRestrictedPages' => false,
+                    'useCacheHash' => true
+                ],
+                [
+                    'showAccessRestrictedPages' => false
+                ],
+                true,
+                ['uid' => 1],
+                '',
+                0,
+                '',
+                '',
+                '',
+                ''
+            ],
+            'standard parameter with access protected setting' => [
+                [
+                    'parameter' => 10,
+                    'linkAccessRestrictedPages' => true,
+                    'useCacheHash' => true
+                ],
+                [
+                    'showAccessRestrictedPages' => true
+                ],
+                true,
+                ['uid' => 10],
+                '',
+                0,
+                '',
+                '',
+                '',
+                ''
+            ],
+            'standard parameter with access protected setting "NONE" casts to boolean linkAccessRestrictedPages (delegates resolving to typoLink method internals)' => [
+                [
+                    'parameter' => 10,
+                    'linkAccessRestrictedPages' => true,
+                    'useCacheHash' => true
+                ],
+                [
+                    'showAccessRestrictedPages' => 'NONE'
+                ],
+                true,
+                ['uid' => 10],
+                '',
+                0,
+                '',
+                '',
+                '',
+                ''
+            ],
+            'standard parameter with access protected setting (int)67 casts to boolean linkAccessRestrictedPages (delegates resolving to typoLink method internals)' => [
+                [
+                    'parameter' => 10,
+                    'linkAccessRestrictedPages' => true,
+                    'useCacheHash' => true
+                ],
+                [
+                    'showAccessRestrictedPages' => 67
+                ],
+                true,
+                ['uid' => 10],
+                '',
+                0,
+                '',
+                '',
+                '',
+                ''
+            ],
+            'standard parameter with target' => [
+                [
+                    'parameter' => 1,
+                    'target' => '_blank',
+                    'linkAccessRestrictedPages' => false,
+                    'useCacheHash' => true
+                ],
+                [
+                    'showAccessRestrictedPages' => false
+                ],
+                true,
+                ['uid' => 1],
+                '_blank',
+                0,
+                '',
+                '',
+                '',
+                ''
+            ],
+            'parameter with typeOverride=10' => [
+                [
+                    'parameter' => '10,10',
+                    'linkAccessRestrictedPages' => false,
+                    'useCacheHash' => true
+                ],
+                [
+                    'showAccessRestrictedPages' => false
+                ],
+                true,
+                ['uid' => 10],
+                '',
+                0,
+                '',
+                '',
+                '',
+                10
+            ],
+            'parameter with target and typeOverride=10' => [
+                [
+                    'parameter' => '10,10',
+                    'linkAccessRestrictedPages' => false,
+                    'useCacheHash' => true,
+                    'target' => '_self'
+                ],
+                [
+                    'showAccessRestrictedPages' => false
+                ],
+                true,
+                ['uid' => 10],
+                '_self',
+                0,
+                '',
+                '',
+                '',
+                10
+            ],
+            'parameter with invalid value in typeOverride=foobar ignores typeOverride' => [
+                [
+                    'parameter' => 20,
+                    'linkAccessRestrictedPages' => false,
+                    'useCacheHash' => true,
+                    'target' => '_self'
+                ],
+                [
+                    'showAccessRestrictedPages' => false
+                ],
+                true,
+                ['uid' => 20],
+                '_self',
+                0,
+                '',
+                '',
+                '',
+                'foobar'
+            ],
+            'standard parameter with section name' => [
+                [
+                    'parameter' => 10,
+                    'target' => '_blank',
+                    'linkAccessRestrictedPages' => false,
+                    'no_cache' => true,
+                    'section' => 'section-name'
+                ],
+                [
+                    'showAccessRestrictedPages' => false
+                ],
+                true,
+                [
+                    'uid' => 10,
+                    'sectionIndex_uid' => 'section-name'
+                ],
+                '_blank',
+                1,
+                '',
+                '',
+                '',
+                ''
+            ],
+            'standard parameter with additional parameters' => [
+                [
+                    'parameter' => 10,
+                    'linkAccessRestrictedPages' => false,
+                    'no_cache' => true,
+                    'section' => 'section-name',
+                    'additionalParams' => '&test=foobar'
+                ],
+                [
+                    'showAccessRestrictedPages' => false
+                ],
+                true,
+                [
+                    'uid' => 10,
+                    'sectionIndex_uid' => 'section-name'
+                ],
+                '',
+                1,
+                '',
+                '',
+                '&test=foobar',
+                ''
+            ],
+            'overridden page array uid value gets used as parameter' => [
+                [
+                    'parameter' => 99,
+                    'linkAccessRestrictedPages' => false,
+                    'no_cache' => true,
+                    'section' => 'section-name'
+                ],
+                [
+                    'showAccessRestrictedPages' => false
+                ],
+                true,
+                [
+                    'uid' => 10,
+                    'sectionIndex_uid' => 'section-name'
+                ],
+                '',
+                1,
+                '',
+                ['uid' => 99],
+                '',
+                ''
+            ],
+        ];
+    }
+
+    /**
+     * @test
+     * @dataProvider menuTypoLinkCreatesExpectedTypoLinkConfiurationDataProvider
+     * @param array $expected
+     * @param array $mconf
+     * @param bool $useCacheHash
+     * @param array $page
+     * @param mixed $oTarget
+     * @param int $no_cache
+     * @param string $script
+     * @param string $overrideArray
+     * @param string $addParams
+     * @param string $typeOverride
+     */
+    public function menuTypoLinkCreatesExpectedTypoLinkConfiguration(array $expected, array $mconf, $useCacheHash = true, array $page, $oTarget, $no_cache, $script, $overrideArray = '', $addParams = '', $typeOverride = '')
+    {
+        $this->subject->parent_cObj = $this->getMockBuilder(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class)
+            ->setMethods(['typoLink'])
+            ->getMock();
+        $this->subject->mconf = $mconf;
+        $this->subject->_set('useCacheHash', $useCacheHash);
+        $this->subject->parent_cObj->expects($this->once())->method('typoLink')->with('|', $expected);
+        $this->subject->menuTypoLink($page, $oTarget, $no_cache, $script, $overrideArray, $addParams, $typeOverride);
+    }
 }