TYPO3 API  SVNRelease
ExternalViewHelperTest.php
Go to the documentation of this file.
00001 <?php
00002 
00003 /*                                                                        *
00004  * This script belongs to the FLOW3 package "Fluid".                      *
00005  *                                                                        *
00006  * It is free software; you can redistribute it and/or modify it under    *
00007  * the terms of the GNU Lesser General Public License as published by the *
00008  * Free Software Foundation, either version 3 of the License, or (at your *
00009  * option) any later version.                                             *
00010  *                                                                        *
00011  * This script is distributed in the hope that it will be useful, but     *
00012  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-    *
00013  * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser       *
00014  * General Public License for more details.                               *
00015  *                                                                        *
00016  * You should have received a copy of the GNU Lesser General Public       *
00017  * License along with the script.                                         *
00018  * If not, see http://www.gnu.org/licenses/lgpl.html                      *
00019  *                                                                        *
00020  * The TYPO3 project - inspiring people to share!                         *
00021  *                                                                        */
00022 
00023 require_once(dirname(__FILE__) . '/../ViewHelperBaseTestcase.php');
00024 
00025 /**
00026  * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
00027  */
00028 class Tx_Fluid_Tests_Unit_ViewHelpers_Link_ExternalViewHelperTest extends Tx_Fluid_ViewHelpers_ViewHelperBaseTestcase {
00029 
00030     /**
00031      * var Tx_Fluid_ViewHelpers_Link_EmailViewHelper
00032      */
00033     protected $viewHelper;
00034 
00035     public function setUp() {
00036         parent::setUp();
00037         $this->viewHelper = $this->getAccessibleMock('Tx_Fluid_ViewHelpers_Link_ExternalViewHelper', array('renderChildren'));
00038         $this->injectDependenciesIntoViewHelper($this->viewHelper);
00039         $this->viewHelper->initializeArguments();
00040     }
00041 
00042     /**
00043      * @test
00044      * @author Bastian Waidelich <bastian@typo3.org>
00045      */
00046     public function renderCorrectlySetsTagNameAndAttributesAndContent() {
00047         $mockTagBuilder = $this->getMock('Tx_Fluid_Core_ViewHelper_TagBuilder', array('setTagName', 'addAttribute', 'setContent'));
00048         $mockTagBuilder->expects($this->once())->method('setTagName')->with('a');
00049         $mockTagBuilder->expects($this->once())->method('addAttribute')->with('href', 'http://www.some-domain.tld');
00050         $mockTagBuilder->expects($this->once())->method('setContent')->with('some content');
00051         $this->viewHelper->_set('tag', $mockTagBuilder);
00052 
00053         $this->viewHelper->expects($this->any())->method('renderChildren')->will($this->returnValue('some content'));
00054 
00055         $this->viewHelper->initialize();
00056         $this->viewHelper->render('http://www.some-domain.tld');
00057     }
00058 
00059     /**
00060      * @test
00061      * @author Bastian Waidelich <bastian@typo3.org>
00062      */
00063     public function renderAddsHttpPrefixIfSpecifiedUriDoesNotContainScheme() {
00064         $mockTagBuilder = $this->getMock('Tx_Fluid_Core_ViewHelper_TagBuilder', array('setTagName', 'addAttribute', 'setContent'));
00065         $mockTagBuilder->expects($this->once())->method('setTagName')->with('a');
00066         $mockTagBuilder->expects($this->once())->method('addAttribute')->with('href', 'http://www.some-domain.tld');
00067         $mockTagBuilder->expects($this->once())->method('setContent')->with('some content');
00068         $this->viewHelper->_set('tag', $mockTagBuilder);
00069 
00070         $this->viewHelper->expects($this->any())->method('renderChildren')->will($this->returnValue('some content'));
00071 
00072         $this->viewHelper->initialize();
00073         $this->viewHelper->render('www.some-domain.tld');
00074     }
00075 
00076     /**
00077      * @test
00078      * @author Bastian Waidelich <bastian@typo3.org>
00079      */
00080     public function renderAddsSpecifiedSchemeIfUriDoesNotContainScheme() {
00081         $mockTagBuilder = $this->getMock('Tx_Fluid_Core_ViewHelper_TagBuilder', array('setTagName', 'addAttribute', 'setContent'));
00082         $mockTagBuilder->expects($this->once())->method('setTagName')->with('a');
00083         $mockTagBuilder->expects($this->once())->method('addAttribute')->with('href', 'ftp://some-domain.tld');
00084         $mockTagBuilder->expects($this->once())->method('setContent')->with('some content');
00085         $this->viewHelper->_set('tag', $mockTagBuilder);
00086 
00087         $this->viewHelper->expects($this->any())->method('renderChildren')->will($this->returnValue('some content'));
00088 
00089         $this->viewHelper->initialize();
00090         $this->viewHelper->render('some-domain.tld', 'ftp');
00091     }
00092 
00093     /**
00094      * @test
00095      * @author Bastian Waidelich <bastian@typo3.org>
00096      */
00097     public function renderDoesNotAddEmptyScheme() {
00098         $mockTagBuilder = $this->getMock('Tx_Fluid_Core_ViewHelper_TagBuilder', array('setTagName', 'addAttribute', 'setContent'));
00099         $mockTagBuilder->expects($this->once())->method('setTagName')->with('a');
00100         $mockTagBuilder->expects($this->once())->method('addAttribute')->with('href', 'some-domain.tld');
00101         $mockTagBuilder->expects($this->once())->method('setContent')->with('some content');
00102         $this->viewHelper->_set('tag', $mockTagBuilder);
00103 
00104         $this->viewHelper->expects($this->any())->method('renderChildren')->will($this->returnValue('some content'));
00105 
00106         $this->viewHelper->initialize();
00107         $this->viewHelper->render('some-domain.tld', '');
00108     }
00109 }
00110 
00111 ?>