TYPO3 CMS  TYPO3_8-7
ExternalViewHelperTest.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
19 
23 class ExternalViewHelperTest extends ViewHelperBaseTestcase
24 {
28  protected $viewHelper;
29 
30  protected function setUp()
31  {
32  parent::setUp();
33  $this->viewHelper = $this->getAccessibleMock(\TYPO3\CMS\Fluid\ViewHelpers\Link\ExternalViewHelper::class, ['renderChildren']);
34  $this->injectDependenciesIntoViewHelper($this->viewHelper);
35  }
36 
41  {
42  $mockTagBuilder = $this->getMockBuilder(TagBuilder::class)
43  ->setMethods(['setTagName', 'addAttribute', 'setContent'])
44  ->getMock();
45  $mockTagBuilder->expects($this->once())->method('setTagName')->with('a');
46  $mockTagBuilder->expects($this->once())->method('addAttribute')->with('href', 'http://www.some-domain.tld');
47  $mockTagBuilder->expects($this->once())->method('setContent')->with('some content');
48  $this->viewHelper->_set('tag', $mockTagBuilder);
49 
50  $this->viewHelper->expects($this->any())->method('renderChildren')->will($this->returnValue('some content'));
51 
52  $this->setArgumentsUnderTest(
53  $this->viewHelper,
54  [
55  'uri' => 'http://www.some-domain.tld',
56  ]
57  );
58  $this->viewHelper->initialize();
59  $this->viewHelper->render();
60  }
61 
66  {
67  $mockTagBuilder = $this->getMockBuilder(TagBuilder::class)
68  ->setMethods(['setTagName', 'addAttribute', 'setContent'])
69  ->getMock();
70  $mockTagBuilder->expects($this->once())->method('setTagName')->with('a');
71  $mockTagBuilder->expects($this->once())->method('addAttribute')->with('href', 'http://www.some-domain.tld');
72  $mockTagBuilder->expects($this->once())->method('setContent')->with('some content');
73  $this->viewHelper->_set('tag', $mockTagBuilder);
74 
75  $this->viewHelper->expects($this->any())->method('renderChildren')->will($this->returnValue('some content'));
76 
77  $this->setArgumentsUnderTest(
78  $this->viewHelper,
79  [
80  'uri' => 'www.some-domain.tld',
81  ]
82  );
83  $this->viewHelper->initialize();
84  $this->viewHelper->render();
85  }
86 
91  {
92  $mockTagBuilder = $this->getMockBuilder(TagBuilder::class)
93  ->setMethods(['setTagName', 'addAttribute', 'setContent'])
94  ->getMock();
95  $mockTagBuilder->expects($this->once())->method('setTagName')->with('a');
96  $mockTagBuilder->expects($this->once())->method('addAttribute')->with('href', 'ftp://some-domain.tld');
97  $mockTagBuilder->expects($this->once())->method('setContent')->with('some content');
98  $this->viewHelper->_set('tag', $mockTagBuilder);
99 
100  $this->viewHelper->expects($this->any())->method('renderChildren')->will($this->returnValue('some content'));
101 
102  $this->setArgumentsUnderTest(
103  $this->viewHelper,
104  [
105  'uri' => 'some-domain.tld',
106  'defaultScheme' => 'ftp',
107  ]
108  );
109  $this->viewHelper->initialize();
110  $this->viewHelper->render();
111  }
112 
116  public function renderDoesNotAddEmptyScheme()
117  {
118  $mockTagBuilder = $this->getMockBuilder(TagBuilder::class)
119  ->setMethods(['setTagName', 'addAttribute', 'setContent'])
120  ->getMock();
121  $mockTagBuilder->expects($this->once())->method('setTagName')->with('a');
122  $mockTagBuilder->expects($this->once())->method('addAttribute')->with('href', 'some-domain.tld');
123  $mockTagBuilder->expects($this->once())->method('setContent')->with('some content');
124  $this->viewHelper->_set('tag', $mockTagBuilder);
125 
126  $this->viewHelper->expects($this->any())->method('renderChildren')->will($this->returnValue('some content'));
127 
128  $this->setArgumentsUnderTest(
129  $this->viewHelper,
130  [
131  'uri' => 'some-domain.tld',
132  'defaultScheme' => '',
133  ]
134  );
135  $this->viewHelper->initialize();
136  $this->viewHelper->render();
137  }
138 }