[TASK] Add unit tests for spamProtectEmailAddresses 15/44815/2
authorOliver Hader <oliver@typo3.org>
Fri, 20 Nov 2015 10:24:15 +0000 (11:24 +0100)
committerGeorg Ringer <georg.ringer@gmail.com>
Fri, 20 Nov 2015 10:39:02 +0000 (11:39 +0100)
Adding unit tests for TypoScript config property
spamProtectEmailAddresses and its variations.

Resolves: #71716
Releases: master, 6.2
Change-Id: I368806cdfcdb9c2cc05641892df56f3127190789
Reviewed-on: https://review.typo3.org/44815
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php

index 618d0c8..20e8d70 100644 (file)
@@ -4125,6 +4125,122 @@ class ContentObjectRendererTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
     }
 
     /**
+     * @param array $settings
+     * @param string $linkText
+     * @param string $mailAddress
+     * @param string $expected
+     * @dataProvider typoLinkEncodesMailAddressForSpamProtectionDataProvider
+     * @test
+     */
+    public function typoLinkEncodesMailAddressForSpamProtection(array $settings, $linkText, $mailAddress, $expected)
+    {
+        $this->getFrontendController()->spamProtectEmailAddresses = $settings['spamProtectEmailAddresses'];
+        $this->getFrontendController()->config['config'] = $settings;
+        $typoScript = array('parameter' => $mailAddress);
+
+        $this->assertEquals($expected, $this->subject->typoLink($linkText, $typoScript));
+    }
+
+    /**
+     * @return array
+     */
+    public function typoLinkEncodesMailAddressForSpamProtectionDataProvider()
+    {
+        return array(
+            'plain mail without mailto scheme' => array(
+                array(
+                    'spamProtectEmailAddresses' => '',
+                    'spamProtectEmailAddresses_atSubst' => '',
+                    'spamProtectEmailAddresses_lastDotSubst' => '',
+                ),
+                'some.body@test.typo3.org',
+                'some.body@test.typo3.org',
+                '<a href="mailto:some.body@test.typo3.org">some.body@test.typo3.org</a>',
+            ),
+            'plain mail with mailto scheme' => array(
+                array(
+                    'spamProtectEmailAddresses' => '',
+                    'spamProtectEmailAddresses_atSubst' => '',
+                    'spamProtectEmailAddresses_lastDotSubst' => '',
+                ),
+                'some.body@test.typo3.org',
+                'mailto:some.body@test.typo3.org',
+                '<a href="mailto:some.body@test.typo3.org">some.body@test.typo3.org</a>',
+            ),
+            'plain with at and dot substitution' => array(
+                array(
+                    'spamProtectEmailAddresses' => '0',
+                    'spamProtectEmailAddresses_atSubst' => '(at)',
+                    'spamProtectEmailAddresses_lastDotSubst' => '(dot)',
+                ),
+                'some.body@test.typo3.org',
+                'mailto:some.body@test.typo3.org',
+                '<a href="mailto:some.body@test.typo3.org">some.body@test.typo3.org</a>',
+            ),
+            'mono-alphabetic substitution offset +1' => array(
+                array(
+                    'spamProtectEmailAddresses' => '1',
+                    'spamProtectEmailAddresses_atSubst' => '',
+                    'spamProtectEmailAddresses_lastDotSubst' => '',
+                ),
+                'some.body@test.typo3.org',
+                'mailto:some.body@test.typo3.org',
+                '<a href="javascript:linkTo_UnCryptMailto(\'nbjmup+tpnf\/cpezAuftu\/uzqp4\/psh\');">some.body(at)test.typo3.org</a>',
+            ),
+            'mono-alphabetic substitution offset +1 with at substitution' => array(
+                array(
+                    'spamProtectEmailAddresses' => '1',
+                    'spamProtectEmailAddresses_atSubst' => '@',
+                    'spamProtectEmailAddresses_lastDotSubst' => '',
+                ),
+                'some.body@test.typo3.org',
+                'mailto:some.body@test.typo3.org',
+                '<a href="javascript:linkTo_UnCryptMailto(\'nbjmup+tpnf\/cpezAuftu\/uzqp4\/psh\');">some.body@test.typo3.org</a>',
+            ),
+            'mono-alphabetic substitution offset +1 with at and dot substitution' => array(
+                array(
+                    'spamProtectEmailAddresses' => '1',
+                    'spamProtectEmailAddresses_atSubst' => '(at)',
+                    'spamProtectEmailAddresses_lastDotSubst' => '(dot)',
+                ),
+                'some.body@test.typo3.org',
+                'mailto:some.body@test.typo3.org',
+                '<a href="javascript:linkTo_UnCryptMailto(\'nbjmup+tpnf\/cpezAuftu\/uzqp4\/psh\');">some.body(at)test.typo3(dot)org</a>',
+            ),
+            'mono-alphabetic substitution offset -1 with at and dot substitution' => array(
+                array(
+                    'spamProtectEmailAddresses' => '-1',
+                    'spamProtectEmailAddresses_atSubst' => '(at)',
+                    'spamProtectEmailAddresses_lastDotSubst' => '(dot)',
+                ),
+                'some.body@test.typo3.org',
+                'mailto:some.body@test.typo3.org',
+                '<a href="javascript:linkTo_UnCryptMailto(\'lzhksn9rnld-ancxZsdrs-sxon2-nqf\');">some.body(at)test.typo3(dot)org</a>',
+            ),
+            'entity substitution with at and dot substitution' => array(
+                array(
+                    'spamProtectEmailAddresses' => 'ascii',
+                    'spamProtectEmailAddresses_atSubst' => '',
+                    'spamProtectEmailAddresses_lastDotSubst' => '',
+                ),
+                'some.body@test.typo3.org',
+                'mailto:some.body@test.typo3.org',
+                '<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#115;&#111;&#109;&#101;&#46;&#98;&#111;&#100;&#121;&#64;&#116;&#101;&#115;&#116;&#46;&#116;&#121;&#112;&#111;&#51;&#46;&#111;&#114;&#103;">some.body(at)test.typo3.org</a>',
+            ),
+            'entity substitution with at and dot substitution with at and dot substitution' => array(
+                array(
+                    'spamProtectEmailAddresses' => 'ascii',
+                    'spamProtectEmailAddresses_atSubst' => '(at)',
+                    'spamProtectEmailAddresses_lastDotSubst' => '(dot)',
+                ),
+                'some.body@test.typo3.org',
+                'mailto:some.body@test.typo3.org',
+                '<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#115;&#111;&#109;&#101;&#46;&#98;&#111;&#100;&#121;&#64;&#116;&#101;&#115;&#116;&#46;&#116;&#121;&#112;&#111;&#51;&#46;&#111;&#114;&#103;">some.body(at)test.typo3(dot)org</a>',
+            ),
+        );
+    }
+
+    /**
      * @test
      * @param string $linkText
      * @param array $configuration
@@ -4362,4 +4478,12 @@ class ContentObjectRendererTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
 
         \TYPO3\CMS\Core\Utility\GeneralUtility::unlink_tempfile($fileNameAndPath);
     }
+
+    /**
+     * @return \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
+     */
+    protected function getFrontendController() {
+        return $GLOBALS['TSFE'];
+    }
+
 }