‪TYPO3CMS  10.4
PageViewHelperTest.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 
24 use TYPO3\TestingFramework\Fluid\Unit\ViewHelpers\ViewHelperBaseTestcase;
25 use TYPO3Fluid\Fluid\Core\ViewHelper\TagBuilder;
26 
30 class ‪PageViewHelperTest extends ViewHelperBaseTestcase
31 {
35  protected ‪$viewHelper;
36 
40  protected ‪$uriBuilder;
41 
45  protected function ‪setUp(): void
46  {
47  parent::setUp();
48  $this->uriBuilder = $this->createMock(UriBuilder::class);
49  $this->uriBuilder->expects(self::any())->method('reset')->willReturn($this->uriBuilder);
50  $this->uriBuilder->expects(self::any())->method('setArguments')->willReturn($this->uriBuilder);
51  $this->uriBuilder->expects(self::any())->method('setSection')->willReturn($this->uriBuilder);
52  $this->uriBuilder->expects(self::any())->method('setFormat')->willReturn($this->uriBuilder);
53  $this->uriBuilder->expects(self::any())->method('setCreateAbsoluteUri')->willReturn($this->uriBuilder);
54  $this->uriBuilder->expects(self::any())->method('setLanguage')->willReturn($this->uriBuilder);
55  $this->uriBuilder->expects(self::any())->method('setAddQueryString')->willReturn($this->uriBuilder);
56  $this->uriBuilder->expects(self::any())->method('setArgumentsToBeExcludedFromQueryString')->willReturn($this->uriBuilder);
57  $this->uriBuilder->expects(self::any())->method('setLinkAccessRestrictedPages')->willReturn($this->uriBuilder);
58  $this->uriBuilder->expects(self::any())->method('setTargetPageUid')->willReturn($this->uriBuilder);
59  $this->uriBuilder->expects(self::any())->method('setTargetPageType')->willReturn($this->uriBuilder);
60  $this->uriBuilder->expects(self::any())->method('setNoCache')->willReturn($this->uriBuilder);
61  $this->uriBuilder->expects(self::any())->method('setAddQueryStringMethod')->willReturn($this->uriBuilder);
62 
63  // reset parent controller context and uri builder @todo: remove once fluid-cleanup is merged in testing framework
64  $this->controllerContext = $this->createMock(ControllerContext::class);
65  $this->controllerContext->expects(self::any())->method('getUriBuilder')->willReturn($this->uriBuilder);
66  $this->controllerContext->expects(self::any())->method('getRequest')->willReturn($this->request->reveal());
67  $this->arguments = [];
68  $this->renderingContext = $this->getMockBuilder(RenderingContext::class)
69  ->onlyMethods(['getControllerContext'])
70  ->disableOriginalConstructor()
71  ->getMock();
72  $this->renderingContext->expects(self::any())->method('getControllerContext')->willReturn($this->controllerContext);
73  // until here
74 
75  $this->renderingContext->setControllerContext($this->controllerContext);
76 
77  $this->viewHelper = $this->getAccessibleMock(PageViewHelper::class, ['renderChildren']);
78  $this->injectDependenciesIntoViewHelper($this->viewHelper);
79  $this->viewHelper->initializeArguments();
80  $this->tagBuilder = $this->createMock(TagBuilder::class);
81  $this->viewHelper->_set('tag', $this->tagBuilder);
82  }
83 
88  {
89  $this->uriBuilder->expects(self::once())->method('build')->willReturn('index.php');
90  $this->tagBuilder->expects(self::once())->method('render');
91  $this->viewHelper->render();
92  }
93 
98  {
99  $this->uriBuilder->expects(self::once())->method('build')->willReturn('');
100  $this->tagBuilder->expects(self::never())->method('render');
101  $this->viewHelper->render();
102  }
103 }
‪TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder
Definition: UriBuilder.php:39
‪TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext
Definition: ControllerContext.php:28
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext
Definition: RenderingContext.php:39