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 index 0000000000000000000000000000000000000000..537ffc049d9f6ab505f95c630dc0af5a2c23de8f --- /dev/null +++ b/typo3/sysext/core/Documentation/Changelog/master/Important-17904-ShowAccessRestrictedPagesDoesNotWorkWithSpecialMenus.rst @@ -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 diff --git a/typo3/sysext/frontend/Classes/ContentObject/Menu/AbstractMenuContentObject.php b/typo3/sysext/frontend/Classes/ContentObject/Menu/AbstractMenuContentObject.php index 21d5d742fd25c51285d9d01b58a03c7c3e829138..b393990278b6155ba502c8b6098c1a330695b629 100644 --- a/typo3/sysext/frontend/Classes/ContentObject/Menu/AbstractMenuContentObject.php +++ b/typo3/sysext/frontend/Classes/ContentObject/Menu/AbstractMenuContentObject.php @@ -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; diff --git a/typo3/sysext/frontend/Tests/Unit/ContentObject/Menu/AbstractMenuContentObjectTest.php b/typo3/sysext/frontend/Tests/Unit/ContentObject/Menu/AbstractMenuContentObjectTest.php index 8c51e926930beb473bfce0b0e85152552dfd7d69..48afb14b12f6e9b193c4dbf811c1df9ee07edaf5 100644 --- a/typo3/sysext/frontend/Tests/Unit/ContentObject/Menu/AbstractMenuContentObjectTest.php +++ b/typo3/sysext/frontend/Tests/Unit/ContentObject/Menu/AbstractMenuContentObjectTest.php @@ -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); + } }