TYPO3 CMS  TYPO3_6-2
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  public function setUp() {
55  $this->widgetRequestBuilder = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\Core\\Widget\\WidgetRequestBuilder', array('setArgumentsFromRawRequestData'));
56  $this->mockWidgetRequest = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Widget\\WidgetRequest');
57  $this->mockObjectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
58  $this->mockObjectManager->expects($this->once())->method('get')->with('TYPO3\\CMS\\Fluid\\Core\\Widget\\WidgetRequest')->will($this->returnValue($this->mockWidgetRequest));
59  $this->widgetRequestBuilder->_set('objectManager', $this->mockObjectManager);
60  $this->mockWidgetContext = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Widget\\WidgetContext');
61  $this->mockAjaxWidgetContextHolder = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Widget\\AjaxWidgetContextHolder', array(), array(), '', FALSE);
62  $this->widgetRequestBuilder->injectAjaxWidgetContextHolder($this->mockAjaxWidgetContextHolder);
63  $this->mockAjaxWidgetContextHolder->expects($this->once())->method('get')->will($this->returnValue($this->mockWidgetContext));
64  }
65 
69  public function buildSetsRequestUri() {
70  $requestUri = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL');
71  $this->mockWidgetRequest->expects($this->once())->method('setRequestURI')->with($requestUri);
72  $this->widgetRequestBuilder->build();
73  }
74 
78  public function buildSetsBaseUri() {
79  $baseUri = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
80  $this->mockWidgetRequest->expects($this->once())->method('setBaseURI')->with($baseUri);
81  $this->widgetRequestBuilder->build();
82  }
83 
87  public function buildSetsRequestMethod() {
88  $_SERVER['REQUEST_METHOD'] = 'POST';
89  $this->mockWidgetRequest->expects($this->once())->method('setMethod')->with('POST');
90  $this->widgetRequestBuilder->build();
91  }
92 
97  $_SERVER['REQUEST_METHOD'] = 'POST';
98  $_GET = array('get' => 'foo');
99  $_POST = array('post' => 'bar');
100  $this->mockWidgetRequest->expects($this->once())->method('setArguments')->with($_POST);
101  $this->widgetRequestBuilder->build();
102  }
103 
108  $_SERVER['REQUEST_METHOD'] = 'GET';
109  $_GET = array('get' => 'foo');
110  $_POST = array('post' => 'bar');
111  $this->mockWidgetRequest->expects($this->once())->method('setArguments')->with($_GET);
112  $this->widgetRequestBuilder->build();
113  }
114 
119  $_GET = array('action' => 'myAction');
120  $this->mockWidgetRequest->expects($this->once())->method('setControllerActionName')->with('myAction');
121  $this->widgetRequestBuilder->build();
122  }
123 
127  public function buildSetsWidgetContext() {
128  $_GET = array('fluid-widget-id' => '123');
129  $this->mockAjaxWidgetContextHolder->expects($this->once())->method('get')->with('123')->will($this->returnValue($this->mockWidgetContext));
130  $this->mockWidgetRequest->expects($this->once())->method('setWidgetContext')->with($this->mockWidgetContext);
131  $this->widgetRequestBuilder->build();
132  }
133 
137  public function buildReturnsRequest() {
138  $expected = $this->mockWidgetRequest;
139  $actual = $this->widgetRequestBuilder->build();
140  $this->assertSame($expected, $actual);
141  }
142 }
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)