‪TYPO3CMS  10.4
UriViewHelperTest.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 
26 class ‪UriViewHelperTest extends ViewHelperBaseTestcase
27 {
28 
32  protected ‪$viewHelper;
33 
37  protected ‪$uriBuilderMock;
38 
39  protected ‪$resetSingletonInstances = true;
40 
44  protected function ‪setUp(): void
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(self::exactly(3))->method('registerArgument')->withConsecutive(
63  ['route', 'string', self::anything()],
64  ['parameters', 'array', self::anything()],
65  ['referenceType', 'string', self::anything(), false, ‪UriBuilder::ABSOLUTE_PATH]
66  );
68  }
69 
73  public function ‪renderRendersTagWithHrefFromRoute()
74  {
75  $this->viewHelper->setArguments([
76  'route' => 'theRouteArgument',
77  'parameters' => ['parameter' => 'to pass'],
78  'referenceType' => 'theReferenceTypeArgument'
79  ]);
80 
81  GeneralUtility::setSingletonInstance(UriBuilder::class, $this->uriBuilderMock);
82 
83  $this->uriBuilderMock->expects(self::once())->method('buildUriFromRoute')
84  ->with('theRouteArgument', ['parameter' => 'to pass'], 'theReferenceTypeArgument')->willReturn('theUri');
85 
86  self::assertEquals('theUri', $this->viewHelper->render());
87  }
88 
93  {
94  $this->setArgumentsUnderTest(
95  $this->viewHelper,
96  [
97  'route' => 'theRouteArgument',
98  'referenceType' => 'theReferenceTypeArgument'
99  ]
100  );
101  GeneralUtility::setSingletonInstance(UriBuilder::class, $this->uriBuilderMock);
102 
103  $this->uriBuilderMock->expects(self::once())->method('buildUriFromRoute')
104  ->with('theRouteArgument', [], 'theReferenceTypeArgument')->willReturn('theUri');
105  $this->viewHelper->render();
106  }
107 }
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Be\UriViewHelperTest\renderPassesEmptyArrayToUriBuilderForNoParameters
‪renderPassesEmptyArrayToUriBuilderForNoParameters()
Definition: UriViewHelperTest.php:90
‪TYPO3\CMS\Fluid\ViewHelpers\Be\UriViewHelper
Definition: UriViewHelper.php:40
‪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:16
‪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:47
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Be\UriViewHelperTest\$resetSingletonInstances
‪$resetSingletonInstances
Definition: UriViewHelperTest.php:37
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:38
‪TYPO3\CMS\Fluid\ViewHelpers\Be\UriViewHelper\initializeArguments
‪initializeArguments()
Definition: UriViewHelper.php:47
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Be\UriViewHelperTest\renderRendersTagWithHrefFromRoute
‪renderRendersTagWithHrefFromRoute()
Definition: UriViewHelperTest.php:71
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Be\UriViewHelperTest
Definition: UriViewHelperTest.php:27
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Be\UriViewHelperTest\$viewHelper
‪UriViewHelper PHPUnit Framework MockObject MockObject TYPO3 TestingFramework Core AccessibleObjectInterface $viewHelper
Definition: UriViewHelperTest.php:31