‪TYPO3CMS  11.5
EmailViewHelperTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
25 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
26 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
27 
28 class ‪EmailViewHelperTest extends FunctionalTestCase
29 {
31 
32  protected const ‪LANGUAGE_PRESETS = [];
33 
37  public function ‪renderCreatesProperMarkupInBackend(): void
38  {
39  ‪$GLOBALS['TYPO3_REQUEST'] = (new ‪ServerRequest())
40  ->withAttribute('applicationType', ‪SystemEnvironmentBuilder::REQUESTTYPE_BE);
41  $view = new ‪StandaloneView();
42  $view->setTemplateSource('<f:uri.email email="foo@example.com" />');
43  self::assertEquals('mailto:foo@example.com', $view->render());
44  }
45 
46  public function ‪renderEncodesEmailInFrontendDataProvider(): array
47  {
48  return [
49  'Plain email' => [
50  '<f:uri.email email="some@email.tld" />',
51  0,
52  'mailto:some@email.tld',
53  ],
54  'Plain email with spam protection' => [
55  '<f:uri.email email="some@email.tld" />',
56  1,
57  'javascript:linkTo_UnCryptMailto(%27nbjmup%2BtpnfAfnbjm%5C%2Fume%27,-1);',
58  ],
59  'Susceptible email' => [
60  '<f:uri.email email="\"><script>alert(\'email\')</script>" />',
61  0,
62  'mailto:&quot;&gt;&lt;script&gt;alert(&#039;email&#039;)&lt;/script&gt;',
63  ],
64  'Susceptible email with spam protection' => [
65  '<f:uri.email email="\"><script>alert(\'email\')</script>" />',
66  1,
67  'javascript:linkTo_UnCryptMailto(%27nbjmup%2B%5Cu0022%5Cu003E%5Cu003Ctdsjqu%5Cu003Ebmfsu%28%5Cu0027fnbjm%5Cu0027%29%5Cu003C0tdsjqu%5Cu003E%27,-1);',
68  ],
69  ];
70  }
71 
76  public function ‪renderEncodesEmailInFrontend(string $template, $spamProtectEmailAddresses, string $expected): void
77  {
78  $this->importCSVDataSet(__DIR__ . '/../../Fixtures/pages.csv');
80  'test',
81  $this->‪buildSiteConfiguration(1, '/'),
82  );
83  (new ‪ConnectionPool())->getConnectionForTable('sys_template')->insert('sys_template', [
84  'pid' => 1,
85  'root' => 1,
86  'clear' => 1,
87  'config' => <<<EOT
88 config.spamProtectEmailAddresses = $spamProtectEmailAddresses
89 page = PAGE
90 page.10 = FLUIDTEMPLATE
91 page.10 {
92  template = TEXT
93  template.value = $template
94 }
95 EOT
96  ]);
97  $response = $this->executeFrontendSubRequest((new InternalRequest())->withPageId(1));
98  self::assertStringContainsString($expected, (string)$response->getBody());
99  }
100 }
‪TYPO3\CMS\Core\Core\SystemEnvironmentBuilder
Definition: SystemEnvironmentBuilder.php:41
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait
Definition: SiteBasedTestTrait.php:36
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\writeSiteConfiguration
‪writeSiteConfiguration(string $identifier, array $site=[], array $languages=[], array $errorHandling=[])
Definition: SiteBasedTestTrait.php:58
‪TYPO3\CMS\Core\Core\SystemEnvironmentBuilder\REQUESTTYPE_BE
‪const REQUESTTYPE_BE
Definition: SystemEnvironmentBuilder.php:45
‪TYPO3\CMS\Fluid\Tests\FunctionalDeprecated\ViewHelpers\Uri\EmailViewHelperTest\renderEncodesEmailInFrontendDataProvider
‪renderEncodesEmailInFrontendDataProvider()
Definition: EmailViewHelperTest.php:45
‪TYPO3\CMS\Fluid\Tests\FunctionalDeprecated\ViewHelpers\Uri\EmailViewHelperTest
Definition: EmailViewHelperTest.php:29
‪TYPO3\CMS\Fluid\Tests\FunctionalDeprecated\ViewHelpers\Uri\EmailViewHelperTest\LANGUAGE_PRESETS
‪const LANGUAGE_PRESETS
Definition: EmailViewHelperTest.php:31
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:37
‪TYPO3\CMS\Fluid\Tests\FunctionalDeprecated\ViewHelpers\Uri\EmailViewHelperTest\renderEncodesEmailInFrontend
‪renderEncodesEmailInFrontend(string $template, $spamProtectEmailAddresses, string $expected)
Definition: EmailViewHelperTest.php:75
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:31
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildSiteConfiguration
‪array buildSiteConfiguration(int $rootPageId, string $base='')
Definition: SiteBasedTestTrait.php:111
‪TYPO3\CMS\Fluid\Tests\FunctionalDeprecated\ViewHelpers\Uri
Definition: EmailViewHelperTest.php:18
‪TYPO3\CMS\Fluid\Tests\FunctionalDeprecated\ViewHelpers\Uri\EmailViewHelperTest\renderCreatesProperMarkupInBackend
‪renderCreatesProperMarkupInBackend()
Definition: EmailViewHelperTest.php:36
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46