From 4166cde89162f2c0c620a538c788276a7002402f Mon Sep 17 00:00:00 2001 From: Elmar Hinz <t3elmar@gmail.com> Date: Fri, 31 Mar 2017 21:49:21 +0200 Subject: [PATCH] [TASK] Add unit test for Typolink resolveTargetAttribute Add a unit test for AbstractTypolinkBuilder::resolveTargetAttribute. Releases: master, 8.7 Resolves: #80618 Change-Id: I429900c036371be4f0bd57e75d841f9d0dfe7720 Reviewed-on: https://review.typo3.org/52305 Tested-by: TYPO3com <no-reply@typo3.com> Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de> Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de> Reviewed-by: Tymoteusz Motylewski <t.motylewski@gmail.com> Tested-by: Tymoteusz Motylewski <t.motylewski@gmail.com> --- .../Typolink/AbstractTypolinkBuilderTest.php | 120 ++++++++++++++++++ 1 file changed, 120 insertions(+) diff --git a/typo3/sysext/frontend/Tests/Unit/Typolink/AbstractTypolinkBuilderTest.php b/typo3/sysext/frontend/Tests/Unit/Typolink/AbstractTypolinkBuilderTest.php index f29908619243..f0a76a6bd2f5 100644 --- a/typo3/sysext/frontend/Tests/Unit/Typolink/AbstractTypolinkBuilderTest.php +++ b/typo3/sysext/frontend/Tests/Unit/Typolink/AbstractTypolinkBuilderTest.php @@ -234,4 +234,124 @@ class AbstractTypolinkBuilderTest extends UnitTestCase $this->assertEquals($expected, $subject->_call('forceAbsoluteUrl', $url, $configuration)); } + + /** + * Data provider for resolveTargetAttribute + * + * @return array [[$expected, $conf, $name, $respectFrameSetOption, $fallbackTarget],] + */ + public function resolveTargetAttributeDataProvider() : array + { + $targetName = $this->getUniqueId('name_'); + $target = $this->getUniqueId('target_'); + $fallback = $this->getUniqueId('fallback_'); + return [ + 'Take target from $conf, if $conf[$targetName] is set.' => + [ + $target, + [$targetName => $target], // $targetName is set + $targetName, + true, + $fallback, + 'other doctype' + ], + 'Else from fallback, if not $respectFrameSetOption ...' => + [ + $fallback, + [], + $targetName, + false, // $respectFrameSetOption false + $fallback, + 'other doctype' + ], + ' ... or no doctype ... ' => + [ + $fallback, + [], + $targetName, + true, + $fallback, + null // no $doctype + ], + ' ... or doctype xhtml_trans... ' => + [ + $fallback, + [], + $targetName, + true, + $fallback, + 'xhtml_trans' + ], + ' ... or doctype xhtml_basic... ' => + [ + $fallback, + [], + $targetName, + true, + $fallback, + 'xhtml_basic' + ], + ' ... or doctype html5... ' => + [ + $fallback, + [], + $targetName, + true, + $fallback, + 'html5' + ], + ' If all hopes fail, an empty string is returned. ' => + [ + '', + [], + $targetName, + true, + $fallback, + 'other doctype' + ], + 'It finally applies stdWrap' => + [ + 'wrap_target', + [$targetName . '.' => + [ 'ifEmpty' => 'wrap_target' ] + ], + $targetName, + true, + $fallback, + 'other doctype' + ], + ]; + } + + /** + * @test + * @dataProvider resolveTargetAttributeDataProvider + * @param string $expected + * @param array $conf + * @param string $name + * @param bool $respectFrameSetOption + * @param string $fallbackTarget + * @param string|null $doctype + */ + public function canResolveTheTargetAttribute( + string $expected, + array $conf, + string $name, + bool $respectFrameSetOption, + string $fallbackTarget, + $doctype + ) { + $this->frontendControllerMock->config = + ['config' => [ 'doctype' => $doctype]]; + $renderer = GeneralUtility::makeInstance(ContentObjectRenderer::class); + $subject = $this->getMockBuilder(AbstractTypolinkBuilder::class) + ->setConstructorArgs([$renderer]) + ->setMethods(['build']) + ->getMock(); + $actual = $this->callInaccessibleMethod( + $subject, 'resolveTargetAttribute', + $conf, $name, $respectFrameSetOption, $fallbackTarget + ); + $this->assertEquals($expected, $actual); + } } -- GitLab