‪TYPO3CMS  ‪main
UriViewHelperTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
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 
19 
20 use PHPUnit\Framework\Attributes\Test;
28 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
29 use TYPO3Fluid\Fluid\View\TemplateView;
30 
31 final class ‪UriViewHelperTest extends FunctionalTestCase
32 {
33  protected bool ‪$initializeDatabase = false;
34 
35  #[Test]
36  public function ‪renderRendersTagWithHrefFromRoute(): void
37  {
38  // Mock Uribuilder in this functional test so we don't have to work with existing routes
39  $formProtectionFactoryMock = $this->createMock(FormProtectionFactory::class);
40  $backendEntryPointResolver = new ‪BackendEntryPointResolver();
41  $requestContextFactory = new ‪RequestContextFactory($backendEntryPointResolver);
42  $router = new ‪Router($requestContextFactory, $backendEntryPointResolver);
43  $uriBuilderMock = $this->getMockBuilder(UriBuilder::class)->setConstructorArgs([$router, $formProtectionFactoryMock, $requestContextFactory])->getMock();
44  $uriBuilderMock->expects(self::once())->method('buildUriFromRoute')
45  ->with('theRouteArgument', ['parameter' => 'to pass'], 'theReferenceTypeArgument')->willReturn('theUri');
46  GeneralUtility::setSingletonInstance(UriBuilder::class, $uriBuilderMock);
47 
48  $context = $this->get(RenderingContextFactory::class)->create();
49  $context->getTemplatePaths()->setTemplateSource(
50  '<f:be.uri route="theRouteArgument" parameters="{parameter: \'to pass\'}" referenceType="theReferenceTypeArgument">foo</f:be.uri>'
51  );
52  self::assertEquals('theUri', (new TemplateView($context))->render());
53  }
54 
55  #[Test]
57  {
58  // Mock Uribuilder in this functional test so we don't have to work with existing routes
59  $formProtectionFactoryMock = $this->createMock(FormProtectionFactory::class);
60  $backendEntryPointResolver = new ‪BackendEntryPointResolver();
61  $requestContextFactory = new ‪RequestContextFactory($backendEntryPointResolver);
62  $router = new ‪Router($requestContextFactory, $backendEntryPointResolver);
63  $uriBuilderMock = $this->getMockBuilder(UriBuilder::class)->setConstructorArgs([$router, $formProtectionFactoryMock, $requestContextFactory])->getMock();
64  $uriBuilderMock->expects(self::once())->method('buildUriFromRoute')
65  ->with('theRouteArgument', [], 'theReferenceTypeArgument')->willReturn('theUri');
66  GeneralUtility::setSingletonInstance(UriBuilder::class, $uriBuilderMock);
67 
68  $context = $this->get(RenderingContextFactory::class)->create();
69  $context->getTemplatePaths()->setTemplateSource('<f:be.uri route="theRouteArgument" referenceType="theReferenceTypeArgument">foo</f:be.uri>');
70  self::assertEquals('theUri', (new TemplateView($context))->render());
71  }
72 }
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Be\UriViewHelperTest\renderPassesEmptyArrayToUriBuilderForNoParameters
‪renderPassesEmptyArrayToUriBuilderForNoParameters()
Definition: UriViewHelperTest.php:56
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Be\UriViewHelperTest
Definition: UriViewHelperTest.php:32
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Be\UriViewHelperTest\renderRendersTagWithHrefFromRoute
‪renderRendersTagWithHrefFromRoute()
Definition: UriViewHelperTest.php:36
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:44
‪TYPO3\CMS\Core\FormProtection\FormProtectionFactory
Definition: FormProtectionFactory.php:43
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContextFactory
Definition: RenderingContextFactory.php:51
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Be\UriViewHelperTest\$initializeDatabase
‪bool $initializeDatabase
Definition: UriViewHelperTest.php:33
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Be
Definition: LinkViewHelperTest.php:18
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Backend\Routing\Router
Definition: Router.php:40
‪TYPO3\CMS\Core\Routing\BackendEntryPointResolver
Definition: BackendEntryPointResolver.php:29
‪TYPO3\CMS\Core\Routing\RequestContextFactory
Definition: RequestContextFactory.php:30