TYPO3 CMS  TYPO3_7-6
WidgetRequestBuilderTest.php
Go to the documentation of this file.
1 <?php
3 
4 /* *
5  * This script is backported from the FLOW3 package "TYPO3.Fluid". *
6  * *
7  * It is free software; you can redistribute it and/or modify it under *
8  * the terms of the GNU Lesser General Public License, either version 3 *
9  * of the License, or (at your option) any later version. *
10  * *
11  * *
12  * This script is distributed in the hope that it will be useful, but *
13  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
14  * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
15  * General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU Lesser General Public *
18  * License along with the script. *
19  * If not, see http://www.gnu.org/licenses/lgpl.html *
20  * *
21  * The TYPO3 project - inspiring people to share! *
22  * */
23 
28 {
33 
37  protected $mockObjectManager;
38 
42  protected $mockWidgetRequest;
43 
48 
52  protected $mockWidgetContext;
53 
54  protected function setUp()
55  {
56  $this->widgetRequestBuilder = $this->getAccessibleMock(\TYPO3\CMS\Fluid\Core\Widget\WidgetRequestBuilder::class, ['setArgumentsFromRawRequestData']);
57  $this->mockWidgetRequest = $this->getMock(\TYPO3\CMS\Fluid\Core\Widget\WidgetRequest::class);
58  $this->mockObjectManager = $this->getMock(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface::class);
59  $this->mockObjectManager->expects($this->once())->method('get')->with(\TYPO3\CMS\Fluid\Core\Widget\WidgetRequest::class)->will($this->returnValue($this->mockWidgetRequest));
60  $this->widgetRequestBuilder->_set('objectManager', $this->mockObjectManager);
61  $this->mockWidgetContext = $this->getMock(\TYPO3\CMS\Fluid\Core\Widget\WidgetContext::class);
62  $this->mockAjaxWidgetContextHolder = $this->getMock(\TYPO3\CMS\Fluid\Core\Widget\AjaxWidgetContextHolder::class, [], [], '', false);
63  $this->widgetRequestBuilder->injectAjaxWidgetContextHolder($this->mockAjaxWidgetContextHolder);
64  $this->mockAjaxWidgetContextHolder->expects($this->once())->method('get')->will($this->returnValue($this->mockWidgetContext));
65  }
66 
70  public function buildSetsRequestUri()
71  {
72  $requestUri = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL');
73  $this->mockWidgetRequest->expects($this->once())->method('setRequestURI')->with($requestUri);
74  $this->widgetRequestBuilder->build();
75  }
76 
80  public function buildSetsBaseUri()
81  {
82  $baseUri = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
83  $this->mockWidgetRequest->expects($this->once())->method('setBaseURI')->with($baseUri);
84  $this->widgetRequestBuilder->build();
85  }
86 
90  public function buildSetsRequestMethod()
91  {
92  $_SERVER['REQUEST_METHOD'] = 'POST';
93  $this->mockWidgetRequest->expects($this->once())->method('setMethod')->with('POST');
94  $this->widgetRequestBuilder->build();
95  }
96 
101  {
102  $_SERVER['REQUEST_METHOD'] = 'POST';
103  $_GET = ['get' => 'foo'];
104  $_POST = ['post' => 'bar'];
105  $this->mockWidgetRequest->expects($this->once())->method('setArguments')->with($_POST);
106  $this->widgetRequestBuilder->build();
107  }
108 
113  {
114  $_SERVER['REQUEST_METHOD'] = 'GET';
115  $_GET = ['get' => 'foo'];
116  $_POST = ['post' => 'bar'];
117  $this->mockWidgetRequest->expects($this->once())->method('setArguments')->with($_GET);
118  $this->widgetRequestBuilder->build();
119  }
120 
125  {
126  $_GET = ['action' => 'myAction'];
127  $this->mockWidgetRequest->expects($this->once())->method('setControllerActionName')->with('myAction');
128  $this->widgetRequestBuilder->build();
129  }
130 
134  public function buildSetsWidgetContext()
135  {
136  $_GET = ['fluid-widget-id' => '123'];
137  $this->mockAjaxWidgetContextHolder->expects($this->once())->method('get')->with('123')->will($this->returnValue($this->mockWidgetContext));
138  $this->mockWidgetRequest->expects($this->once())->method('setWidgetContext')->with($this->mockWidgetContext);
139  $this->widgetRequestBuilder->build();
140  }
141 
145  public function buildReturnsRequest()
146  {
147  $expected = $this->mockWidgetRequest;
148  $actual = $this->widgetRequestBuilder->build();
149  $this->assertSame($expected, $actual);
150  }
151 }
getAccessibleMock( $originalClassName, $methods=[], array $arguments=[], $mockClassName='', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)