[+FEATURE] Fluid (ViewHelpers): prepend URIs with scheme if it's not specified in...
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Tests / Unit / ViewHelpers / Link / ExternalViewHelperTest.php
1 <?php
2
3 /* *
4 * This script belongs to the FLOW3 package "Fluid". *
5 * *
6 * It is free software; you can redistribute it and/or modify it under *
7 * the terms of the GNU Lesser General Public License as published by the *
8 * Free Software Foundation, either version 3 of the License, or (at your *
9 * option) any later version. *
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 Lesser *
14 * General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Lesser General Public *
17 * License along with the script. *
18 * If not, see http://www.gnu.org/licenses/lgpl.html *
19 * *
20 * The TYPO3 project - inspiring people to share! *
21 * */
22
23 require_once(dirname(__FILE__) . '/../ViewHelperBaseTestcase.php');
24
25 /**
26 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
27 */
28 class Tx_Fluid_Tests_Unit_ViewHelpers_Link_ExternalViewHelperTest extends Tx_Fluid_ViewHelpers_ViewHelperBaseTestcase {
29
30 /**
31 * var Tx_Fluid_ViewHelpers_Link_EmailViewHelper
32 */
33 protected $viewHelper;
34
35 public function setUp() {
36 parent::setUp();
37 $this->viewHelper = $this->getAccessibleMock('Tx_Fluid_ViewHelpers_Link_ExternalViewHelper', array('renderChildren'));
38 $this->injectDependenciesIntoViewHelper($this->viewHelper);
39 $this->viewHelper->initializeArguments();
40 }
41
42 /**
43 * @test
44 * @author Bastian Waidelich <bastian@typo3.org>
45 */
46 public function renderCorrectlySetsTagNameAndAttributesAndContent() {
47 $mockTagBuilder = $this->getMock('Tx_Fluid_Core_ViewHelper_TagBuilder', array('setTagName', 'addAttribute', 'setContent'));
48 $mockTagBuilder->expects($this->once())->method('setTagName')->with('a');
49 $mockTagBuilder->expects($this->once())->method('addAttribute')->with('href', 'http://www.some-domain.tld');
50 $mockTagBuilder->expects($this->once())->method('setContent')->with('some content');
51 $this->viewHelper->_set('tag', $mockTagBuilder);
52
53 $this->viewHelper->expects($this->any())->method('renderChildren')->will($this->returnValue('some content'));
54
55 $this->viewHelper->initialize();
56 $this->viewHelper->render('http://www.some-domain.tld');
57 }
58
59 /**
60 * @test
61 * @author Bastian Waidelich <bastian@typo3.org>
62 */
63 public function renderAddsHttpPrefixIfSpecifiedUriDoesNotContainScheme() {
64 $mockTagBuilder = $this->getMock('Tx_Fluid_Core_ViewHelper_TagBuilder', array('setTagName', 'addAttribute', 'setContent'));
65 $mockTagBuilder->expects($this->once())->method('setTagName')->with('a');
66 $mockTagBuilder->expects($this->once())->method('addAttribute')->with('href', 'http://www.some-domain.tld');
67 $mockTagBuilder->expects($this->once())->method('setContent')->with('some content');
68 $this->viewHelper->_set('tag', $mockTagBuilder);
69
70 $this->viewHelper->expects($this->any())->method('renderChildren')->will($this->returnValue('some content'));
71
72 $this->viewHelper->initialize();
73 $this->viewHelper->render('www.some-domain.tld');
74 }
75
76 /**
77 * @test
78 * @author Bastian Waidelich <bastian@typo3.org>
79 */
80 public function renderAddsSpecifiedSchemeIfUriDoesNotContainScheme() {
81 $mockTagBuilder = $this->getMock('Tx_Fluid_Core_ViewHelper_TagBuilder', array('setTagName', 'addAttribute', 'setContent'));
82 $mockTagBuilder->expects($this->once())->method('setTagName')->with('a');
83 $mockTagBuilder->expects($this->once())->method('addAttribute')->with('href', 'ftp://some-domain.tld');
84 $mockTagBuilder->expects($this->once())->method('setContent')->with('some content');
85 $this->viewHelper->_set('tag', $mockTagBuilder);
86
87 $this->viewHelper->expects($this->any())->method('renderChildren')->will($this->returnValue('some content'));
88
89 $this->viewHelper->initialize();
90 $this->viewHelper->render('some-domain.tld', 'ftp');
91 }
92
93 /**
94 * @test
95 * @author Bastian Waidelich <bastian@typo3.org>
96 */
97 public function renderDoesNotAddEmptyScheme() {
98 $mockTagBuilder = $this->getMock('Tx_Fluid_Core_ViewHelper_TagBuilder', array('setTagName', 'addAttribute', 'setContent'));
99 $mockTagBuilder->expects($this->once())->method('setTagName')->with('a');
100 $mockTagBuilder->expects($this->once())->method('addAttribute')->with('href', 'some-domain.tld');
101 $mockTagBuilder->expects($this->once())->method('setContent')->with('some content');
102 $this->viewHelper->_set('tag', $mockTagBuilder);
103
104 $this->viewHelper->expects($this->any())->method('renderChildren')->will($this->returnValue('some content'));
105
106 $this->viewHelper->initialize();
107 $this->viewHelper->render('some-domain.tld', '');
108 }
109 }
110
111 ?>