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