‪TYPO3CMS  9.5
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 
17 use TYPO3\TestingFramework\Fluid\Unit\ViewHelpers\ViewHelperBaseTestcase;
18 use TYPO3Fluid\Fluid\Core\ViewHelper\TagBuilder;
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->atLeastOnce())->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->setTagBuilder($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->initializeArgumentsAndRender();
59  }
60 
65  {
66  $mockTagBuilder = $this->getMockBuilder(TagBuilder::class)
67  ->setMethods(['setTagName', 'addAttribute', 'setContent'])
68  ->getMock();
69  $mockTagBuilder->expects($this->atLeastOnce())->method('setTagName')->with('a');
70  $mockTagBuilder->expects($this->once())->method('addAttribute')->with('href', 'http://www.some-domain.tld');
71  $mockTagBuilder->expects($this->once())->method('setContent')->with('some content');
72  $this->viewHelper->setTagBuilder($mockTagBuilder);
73 
74  $this->viewHelper->expects($this->any())->method('renderChildren')->will($this->returnValue('some content'));
75 
76  $this->setArgumentsUnderTest(
77  $this->viewHelper,
78  [
79  'uri' => 'www.some-domain.tld',
80  ]
81  );
82  $this->viewHelper->initializeArgumentsAndRender();
83  }
84 
89  {
90  $mockTagBuilder = $this->getMockBuilder(TagBuilder::class)
91  ->setMethods(['setTagName', 'addAttribute', 'setContent'])
92  ->getMock();
93  $mockTagBuilder->expects($this->atLeastOnce())->method('setTagName')->with('a');
94  $mockTagBuilder->expects($this->once())->method('addAttribute')->with('href', 'ftp://some-domain.tld');
95  $mockTagBuilder->expects($this->once())->method('setContent')->with('some content');
96  $this->viewHelper->setTagBuilder($mockTagBuilder);
97 
98  $this->viewHelper->expects($this->any())->method('renderChildren')->will($this->returnValue('some content'));
99 
100  $this->setArgumentsUnderTest(
101  $this->viewHelper,
102  [
103  'uri' => 'some-domain.tld',
104  'defaultScheme' => 'ftp',
105  ]
106  );
107  $this->viewHelper->initializeArgumentsAndRender();
108  }
109 
113  public function ‪renderDoesNotAddEmptyScheme()
114  {
115  $mockTagBuilder = $this->getMockBuilder(TagBuilder::class)
116  ->setMethods(['setTagName', 'addAttribute', 'setContent'])
117  ->getMock();
118  $mockTagBuilder->expects($this->atLeastOnce())->method('setTagName')->with('a');
119  $mockTagBuilder->expects($this->once())->method('addAttribute')->with('href', 'some-domain.tld');
120  $mockTagBuilder->expects($this->once())->method('setContent')->with('some content');
121  $this->viewHelper->setTagBuilder($mockTagBuilder);
122 
123  $this->viewHelper->expects($this->any())->method('renderChildren')->will($this->returnValue('some content'));
124 
125  $this->setArgumentsUnderTest(
126  $this->viewHelper,
127  [
128  'uri' => 'some-domain.tld',
129  'defaultScheme' => '',
130  ]
131  );
132  $this->viewHelper->initializeArgumentsAndRender();
133  }
134 }
‪TYPO3