[+BUGFIX] Fluid (Tests): Fixed Fluid unit tests!
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Tests / Unit / ViewHelpers / Link / EmailViewHelperTest.php
1 <?php
2
3 /* *
4 * This script is part of the TYPO3 project - inspiring people to share! *
5 * *
6 * TYPO3 is free software; you can redistribute it and/or modify it under *
7 * the terms of the GNU General Public License version 2 as published by *
8 * the Free Software Foundation. *
9 * *
10 * This script is distributed in the hope that it will be useful, but *
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
12 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General *
13 * Public License for more details. *
14 * */
15
16 require_once(dirname(__FILE__) . '/../ViewHelperBaseTestcase.php');
17
18 /**
19 * @license http://opensource.org/licenses/gpl-license.php GNU Public License, version 2
20 */
21 class Tx_Fluid_Tests_Unit_ViewHelpers_Link_EmailViewHelperTest extends Tx_Fluid_ViewHelpers_ViewHelperBaseTestcase {
22
23 /**
24 * var Tx_Fluid_ViewHelpers_Link_EmailViewHelper
25 */
26 protected $viewHelper;
27
28 /**
29 * @var tslib_cObj
30 */
31 protected $cObjBackup;
32
33 public function setUp() {
34 parent::setUp();
35
36 $this->cObjBackup = $GLOBALS['TSFE']->cObj;
37 $GLOBALS['TSFE']->cObj = $this->getMock('tslib_cObj', array(), array(), '', FALSE);
38
39 $this->viewHelper = $this->getMock($this->buildAccessibleProxy('Tx_Fluid_ViewHelpers_Link_EmailViewHelper'), array('renderChildren'));
40 $this->injectDependenciesIntoViewHelper($this->viewHelper);
41 $this->viewHelper->initializeArguments();
42 }
43
44 public function tearDown() {
45 $GLOBALS['TSFE']->cObj = $this->cObjBackup;
46 }
47
48 /**
49 * @test
50 * @author Bastian Waidelich <bastian@typo3.org>
51 */
52 public function renderCorrectlySetsTagNameAndAttributesAndContent() {
53 //$GLOBALS['TSFE']->cObj->expects($this->once())->method('getMailTo')->with('some@email.tld', 'some@email.tld')->will($this->returnValue(array('mailto:some@email.tld', 'some@email.tld')));
54
55 $mockTagBuilder = $this->getMock('Tx_Fluid_Core_ViewHelper_TagBuilder', array('setTagName', 'addAttribute', 'setContent'));
56 $mockTagBuilder->expects($this->once())->method('setTagName')->with('a');
57 $mockTagBuilder->expects($this->once())->method('addAttribute')->with('href', 'mailto:some@email.tld');
58 $mockTagBuilder->expects($this->once())->method('setContent')->with('some content');
59 $this->viewHelper->_set('tag', $mockTagBuilder);
60
61 $this->viewHelper->expects($this->any())->method('renderChildren')->will($this->returnValue('some content'));
62
63 $this->viewHelper->initialize();
64 $this->viewHelper->render('some@email.tld');
65 }
66
67 /**
68 * @test
69 * @author Bastian Waidelich <bastian@typo3.org>
70 */
71 public function renderSetsTagContentToEmailIfRenderChildrenReturnNull() {
72 //$GLOBALS['TSFE']->cObj->expects($this->once())->method('getMailTo')->with('some@email.tld', 'some@email.tld')->will($this->returnValue(array('mailto:some@email.tld', 'some@email.tld')));
73
74 $mockTagBuilder = $this->getMock('Tx_Fluid_Core_ViewHelper_TagBuilder', array('setTagName', 'addAttribute', 'setContent'));
75 $mockTagBuilder->expects($this->once())->method('setContent')->with('some@email.tld');
76 $this->viewHelper->_set('tag', $mockTagBuilder);
77
78 $this->viewHelper->expects($this->any())->method('renderChildren')->will($this->returnValue(NULL));
79
80 $this->viewHelper->initialize();
81 $this->viewHelper->render('some@email.tld');
82 }
83 }
84
85 ?>