TYPO3 CMS  TYPO3_6-2
EmailViewHelperTest.php
Go to the documentation of this file.
1 <?php
3 
4 /* *
5  * This script is part of the TYPO3 project - inspiring people to share! *
6  * *
7  * TYPO3 is free software; you can redistribute it and/or modify it under *
8  * the terms of the GNU General Public License version 2 as published by *
9  * the Free Software Foundation. *
10  * *
11  * This script is distributed in the hope that it will be useful, but *
12  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
13  * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General *
14  * Public License for more details. *
15  * */
16 
21 
25  protected $viewHelper;
26 
30  protected $cObjBackup;
31 
32  public function setUp() {
33  parent::setUp();
34  $GLOBALS['TSFE'] = new \stdClass();
35  $GLOBALS['TSFE']->cObj = $this->getMock('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer', array(), array(), '', FALSE);
36  $this->viewHelper = $this->getMock($this->buildAccessibleProxy('TYPO3\\CMS\\Fluid\\ViewHelpers\\Link\\EmailViewHelper'), array('renderChildren'));
37  $this->injectDependenciesIntoViewHelper($this->viewHelper);
38  $this->viewHelper->initializeArguments();
39  }
40 
45  $mockTagBuilder = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\ViewHelper\\TagBuilder', array('setTagName', 'addAttribute', 'setContent'));
46  $mockTagBuilder->expects($this->once())->method('setTagName')->with('a');
47  $mockTagBuilder->expects($this->once())->method('addAttribute')->with('href', 'mailto:some@email.tld');
48  $mockTagBuilder->expects($this->once())->method('setContent')->with('some content');
49  $this->viewHelper->_set('tag', $mockTagBuilder);
50  $this->viewHelper->expects($this->any())->method('renderChildren')->will($this->returnValue('some content'));
51  $this->viewHelper->initialize();
52  $this->viewHelper->render('some@email.tld');
53  }
54 
59  $mockTagBuilder = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\ViewHelper\\TagBuilder', array('setTagName', 'addAttribute', 'setContent'));
60  $mockTagBuilder->expects($this->once())->method('setContent')->with('some@email.tld');
61  $this->viewHelper->_set('tag', $mockTagBuilder);
62  $this->viewHelper->expects($this->any())->method('renderChildren')->will($this->returnValue(NULL));
63  $this->viewHelper->initialize();
64  $this->viewHelper->render('some@email.tld');
65  }
66 
71  return array(
72  'Plain email' => array(
73  'some@email.tld',
74  0,
75  '<a href="mailto:some@email.tld">some@email.tld</a>',
76  ),
77  'Plain email with spam protection' => array(
78  'some@email.tld',
79  1,
80  '<a href="javascript:linkTo_UnCryptMailto(\'nbjmup+tpnfAfnbjm/ume\');">some(at)email.tld</a>',
81  ),
82  'Plain email with ascii spam protection' => array(
83  'some@email.tld',
84  'ascii',
85  '<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#115;&#111;&#109;&#101;&#64;&#101;&#109;&#97;&#105;&#108;&#46;&#116;&#108;&#100;">some(at)email.tld</a>',
86  ),
87  'Susceptible email' => array(
88  '"><script>alert(\'email\')</script>',
89  0,
90  '<a href="mailto:&quot;&gt;&lt;script&gt;alert(\'email\')&lt;/script&gt;">&quot;&gt;&lt;script&gt;alert(\'email\')&lt;/script&gt;</a>',
91  ),
92  'Susceptible email with spam protection' => array(
93  '"><script>alert(\'email\')</script>',
94  1,
95  '<a href="javascript:linkTo_UnCryptMailto(\'nbjmup+&quot;&gt;&lt;tdsjqu&gt;bmfsu(\'fnbjm\')&lt;0tdsjqu&gt;\');">&quot;&gt;&lt;script&gt;alert(\'email\')&lt;/script&gt;</a>',
96  ),
97  'Susceptible email with ascii spam protection' => array(
98  '"><script>alert(\'email\')</script>',
99  'ascii',
100  '<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#34;&#62;&#60;&#115;&#99;&#114;&#105;&#112;&#116;&#62;&#97;&#108;&#101;&#114;&#116;&#40;&#39;&#101;&#109;&#97;&#105;&#108;&#39;&#41;&#60;&#47;&#115;&#99;&#114;&#105;&#112;&#116;&#62;">&quot;&gt;&lt;script&gt;alert(\'email\')&lt;/script&gt;</a>',
101  ),
102  );
103  }
104 
112  public function renderEncodesEmailInFrontend($email, $spamProtectEmailAddresses, $expected) {
114  $tsfe = $this->getMock('TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController', array('dummy'), array(), '', false);
115  $tsfe->cObj = new \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer();
116  $tsfe->spamProtectEmailAddresses = $spamProtectEmailAddresses;
117  $tsfe->config = array(
118  'config' => array(
119  'spamProtectEmailAddresses_atSubst' => '',
120  'spamProtectEmailAddresses_lastDotSubst' => '',
121  ),
122  );
123  $GLOBALS['TSFE'] = $tsfe;
124  $mockTagBuilder = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\ViewHelper\\TagBuilder', array('dummy'));
125  $mockTagBuilder->setTagName = 'a';
126  $viewHelper = $this->getMock($this->buildAccessibleProxy('TYPO3\\CMS\\Fluid\\ViewHelpers\\Link\\EmailViewHelper'), array('isFrontendAvailable', 'renderChildren'));
127  $viewHelper->_set('tag', $mockTagBuilder);
128  $viewHelper->expects($this->once())->method('isFrontendAvailable')->willReturn(true);
129  $viewHelper->expects($this->once())->method('renderChildren')->willReturn(null);
130  $viewHelper->initialize();
131  $this->assertSame(
132  $expected,
133  $viewHelper->render($email)
134  );
135  }
136 
137 }
injectDependenciesIntoViewHelper(\TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper $viewHelper)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]