‪TYPO3CMS  9.5
UriViewHelperTest.php
Go to the documentation of this file.
1 <?php
2 
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
21 use TYPO3\TestingFramework\Fluid\Unit\ViewHelpers\ViewHelperBaseTestcase;
22 
26 class ‪UriViewHelperTest extends ViewHelperBaseTestcase
27 {
28 
32  protected ‪$viewHelper;
33 
37  protected ‪$uriBuilderMock;
38 
39  protected ‪$resetSingletonInstances = true;
40 
44  protected function ‪setUp()
45  {
46  parent::setUp();
47  $this->viewHelper = new ‪UriViewHelper();
48  $this->injectDependenciesIntoViewHelper($this->viewHelper);
49 
50  $this->uriBuilderMock = $this->getMockBuilder(UriBuilder::class)->getMock();
51  }
52 
57  {
58  ‪$viewHelper = $this->getMockBuilder(UriViewHelper::class)
59  ->setMethods(['registerArgument'])
60  ->getMock();
61 
62  ‪$viewHelper->expects($this->at(0))->method('registerArgument')->with('route', 'string', $this->anything());
63  ‪$viewHelper->expects($this->at(1))->method('registerArgument')->with('parameters', 'array', $this->anything());
64  ‪$viewHelper->expects($this->at(2))->method('registerArgument')
65  ->with('referenceType', 'string', $this->anything(), false, ‪UriBuilder::ABSOLUTE_PATH);
67  }
68 
72  public function ‪renderRendersTagWithHrefFromRoute()
73  {
74  $this->viewHelper->setArguments([
75  'route' => 'theRouteArgument',
76  'parameters' => ['parameter' => 'to pass'],
77  'referenceType' => 'theReferenceTypeArgument'
78  ]);
79 
80  GeneralUtility::setSingletonInstance(UriBuilder::class, $this->uriBuilderMock);
81 
82  $this->uriBuilderMock->expects($this->once())->method('buildUriFromRoute')
83  ->with('theRouteArgument', ['parameter' => 'to pass'], 'theReferenceTypeArgument')->willReturn('theUri');
84 
85  $this->assertEquals('theUri', $this->viewHelper->render());
86  }
87 
92  {
93  $this->setArgumentsUnderTest(
94  $this->viewHelper,
95  [
96  'route' => 'theRouteArgument',
97  'referenceType' => 'theReferenceTypeArgument'
98  ]
99  );
100  GeneralUtility::setSingletonInstance(UriBuilder::class, $this->uriBuilderMock);
101 
102  $this->uriBuilderMock->expects($this->once())->method('buildUriFromRoute')
103  ->with('theRouteArgument', [], 'theReferenceTypeArgument')->willReturn('theUri');
104  $this->viewHelper->render();
105  }
106 }
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Be\UriViewHelperTest\renderPassesEmptyArrayToUriBuilderForNoParameters
‪renderPassesEmptyArrayToUriBuilderForNoParameters()
Definition: UriViewHelperTest.php:89
‪TYPO3\CMS\Fluid\ViewHelpers\Be\UriViewHelper
Definition: UriViewHelper.php:39
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Be\UriViewHelperTest\$viewHelper
‪UriViewHelper PHPUnit_Framework_MockObject_MockObject TYPO3 TestingFramework Core AccessibleObjectInterface $viewHelper
Definition: UriViewHelperTest.php:31
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Be\UriViewHelperTest\$uriBuilderMock
‪UriBuilder PHPUnit_Framework_MockObject_MockBuilder $uriBuilderMock
Definition: UriViewHelperTest.php:35
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Be
Definition: LinkViewHelperTest.php:3
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Be\UriViewHelperTest\setUp
‪setUp()
Definition: UriViewHelperTest.php:42
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Be\UriViewHelperTest\initializeArgumentsRegistersExpectedArguments
‪initializeArgumentsRegistersExpectedArguments()
Definition: UriViewHelperTest.php:54
‪TYPO3\CMS\Backend\Routing\UriBuilder\ABSOLUTE_PATH
‪const ABSOLUTE_PATH
Definition: UriBuilder.php:44
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Be\UriViewHelperTest\$resetSingletonInstances
‪$resetSingletonInstances
Definition: UriViewHelperTest.php:37
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:35
‪TYPO3\CMS\Fluid\ViewHelpers\Be\UriViewHelper\initializeArguments
‪initializeArguments()
Definition: UriViewHelper.php:46
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Be\UriViewHelperTest\renderRendersTagWithHrefFromRoute
‪renderRendersTagWithHrefFromRoute()
Definition: UriViewHelperTest.php:70
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Be\UriViewHelperTest
Definition: UriViewHelperTest.php:27