[TASK] Add unit test for Typolink resolveTargetAttribute 05/52305/16
authorElmar Hinz <t3elmar@gmail.com>
Fri, 31 Mar 2017 19:49:21 +0000 (21:49 +0200)
committerTymoteusz Motylewski <t.motylewski@gmail.com>
Thu, 11 May 2017 12:10:50 +0000 (14:10 +0200)
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>
typo3/sysext/frontend/Tests/Unit/Typolink/AbstractTypolinkBuilderTest.php

index f299086..f0a76a6 100644 (file)
@@ -234,4 +234,124 @@ class AbstractTypolinkBuilderTest extends UnitTestCase
 
         $this->assertEquals($expected, $subject->_call('forceAbsoluteUrl', $url, $configuration));
     }
 
         $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);
+    }
 }
 }