TYPO3 API  SVNRelease
EmailViewHelperTest.php
Go to the documentation of this file.
00001 <?php
00002 
00003 /*                                                                        *
00004  * This script is part of the TYPO3 project - inspiring people to share!  *
00005  *                                                                        *
00006  * TYPO3 is free software; you can redistribute it and/or modify it under *
00007  * the terms of the GNU General Public License version 2 as published by  *
00008  * the Free Software Foundation.                                          *
00009  *                                                                        *
00010  * This script is distributed in the hope that it will be useful, but     *
00011  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-    *
00012  * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General      *
00013  * Public License for more details.                                       *
00014  *                                                                        */
00015 
00016 require_once(dirname(__FILE__) . '/../ViewHelperBaseTestcase.php');
00017 
00018 /**
00019  * @license http://opensource.org/licenses/gpl-license.php GNU Public License, version 2
00020  */
00021 class Tx_Fluid_Tests_Unit_ViewHelpers_Link_EmailViewHelperTest extends Tx_Fluid_ViewHelpers_ViewHelperBaseTestcase {
00022 
00023     /**
00024      * var Tx_Fluid_ViewHelpers_Link_EmailViewHelper
00025      */
00026     protected $viewHelper;
00027 
00028     /**
00029      * @var tslib_cObj
00030      */
00031     protected $cObjBackup;
00032 
00033     public function setUp() {
00034         parent::setUp();
00035 
00036         $this->cObjBackup = $GLOBALS['TSFE']->cObj;
00037         $GLOBALS['TSFE']->cObj = $this->getMock('tslib_cObj', array(), array(), '', FALSE);
00038 
00039         $this->viewHelper = $this->getMock($this->buildAccessibleProxy('Tx_Fluid_ViewHelpers_Link_EmailViewHelper'), array('renderChildren'));
00040         $this->injectDependenciesIntoViewHelper($this->viewHelper);
00041         $this->viewHelper->initializeArguments();
00042     }
00043 
00044     public function tearDown() {
00045         $GLOBALS['TSFE']->cObj = $this->cObjBackup;
00046     }
00047 
00048     /**
00049      * @test
00050      * @author Bastian Waidelich <bastian@typo3.org>
00051      */
00052     public function renderCorrectlySetsTagNameAndAttributesAndContent() {
00053         //$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')));
00054 
00055         $mockTagBuilder = $this->getMock('Tx_Fluid_Core_ViewHelper_TagBuilder', array('setTagName', 'addAttribute', 'setContent'));
00056         $mockTagBuilder->expects($this->once())->method('setTagName')->with('a');
00057         $mockTagBuilder->expects($this->once())->method('addAttribute')->with('href', 'mailto:some@email.tld');
00058         $mockTagBuilder->expects($this->once())->method('setContent')->with('some content');
00059         $this->viewHelper->_set('tag', $mockTagBuilder);
00060 
00061         $this->viewHelper->expects($this->any())->method('renderChildren')->will($this->returnValue('some content'));
00062 
00063         $this->viewHelper->initialize();
00064         $this->viewHelper->render('some@email.tld');
00065     }
00066 
00067     /**
00068      * @test
00069      * @author Bastian Waidelich <bastian@typo3.org>
00070      */
00071     public function renderSetsTagContentToEmailIfRenderChildrenReturnNull() {
00072         //$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')));
00073 
00074         $mockTagBuilder = $this->getMock('Tx_Fluid_Core_ViewHelper_TagBuilder', array('setTagName', 'addAttribute', 'setContent'));
00075         $mockTagBuilder->expects($this->once())->method('setContent')->with('some@email.tld');
00076         $this->viewHelper->_set('tag', $mockTagBuilder);
00077 
00078         $this->viewHelper->expects($this->any())->method('renderChildren')->will($this->returnValue(NULL));
00079 
00080         $this->viewHelper->initialize();
00081         $this->viewHelper->render('some@email.tld');
00082     }
00083 }
00084 
00085 ?>