‪TYPO3CMS  10.4
LinkViewHelperTest.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 
21 use TYPO3\TestingFramework\Fluid\Unit\ViewHelpers\ViewHelperBaseTestcase;
22 use TYPO3Fluid\Fluid\Core\ViewHelper\TagBuilder;
23 
27 class ‪LinkViewHelperTest extends ViewHelperBaseTestcase
28 {
29 
33  protected ‪$viewHelper;
34 
38  protected ‪$uriBuilderMock;
39 
40  protected ‪$resetSingletonInstances = true;
41 
45  protected function ‪setUp(): void
46  {
47  parent::setUp();
48  $this->viewHelper = $this->getAccessibleMock(LinkViewHelper::class, ['renderChildren']);
49  $this->injectDependenciesIntoViewHelper($this->viewHelper);
50 
51  $this->uriBuilderMock = $this->getMockBuilder(UriBuilder::class)->getMock();
52 
53  $this->tagBuilder = $this->getMockBuilder(TagBuilder::class)->setMethods([
54  'addAttribute',
55  'setContent',
56  'forceClosingTag',
57  'render'
58  ])->getMock();
59 
60  $this->viewHelper->setTagBuilder($this->tagBuilder);
61  }
62 
66  public function ‪renderRendersTagWithHrefFromRoute()
67  {
68  $this->viewHelper->setArguments([
69  'route' => 'theRouteArgument',
70  'parameters' => ['parameter' => 'to pass'],
71  'referenceType' => 'theReferenceTypeArgument'
72  ]);
73 
74  GeneralUtility::setSingletonInstance(UriBuilder::class, $this->uriBuilderMock);
75 
76  $this->uriBuilderMock->expects(self::once())->method('buildUriFromRoute')
77  ->with('theRouteArgument', ['parameter' => 'to pass'], 'theReferenceTypeArgument')->willReturn('theUri');
78 
79  $this->tagBuilder->expects(self::once())->method('addAttribute')->with('href', 'theUri');
80  $this->tagBuilder->expects(self::once())->method('setContent');
81  $this->tagBuilder->expects(self::once())->method('forceClosingTag')->with(true);
82  $this->tagBuilder->expects(self::once())->method('render');
83 
84  $this->viewHelper->render();
85  }
86 
91  {
92  $this->setArgumentsUnderTest(
93  $this->viewHelper,
94  [
95  'route' => 'theRouteArgument',
96  'referenceType' => 'theReferenceTypeArgument'
97  ]
98  );
99  GeneralUtility::setSingletonInstance(UriBuilder::class, $this->uriBuilderMock);
100 
101  $this->uriBuilderMock->expects(self::once())->method('buildUriFromRoute')
102  ->with('theRouteArgument', [], 'theReferenceTypeArgument')->willReturn('theUri');
103  $this->viewHelper->render();
104  }
105 }
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Be
Definition: LinkViewHelperTest.php:16
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:38
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46