|
TYPO3 API
SVNRelease
|
00001 <?php 00002 00003 /* * 00004 * This script belongs to the FLOW3 package "Fluid". * 00005 * * 00006 * It is free software; you can redistribute it and/or modify it under * 00007 * the terms of the GNU Lesser General Public License as published by the * 00008 * Free Software Foundation, either version 3 of the License, or (at your * 00009 * option) any later version. * 00010 * * 00011 * This script is distributed in the hope that it will be useful, but * 00012 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- * 00013 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser * 00014 * General Public License for more details. * 00015 * * 00016 * You should have received a copy of the GNU Lesser General Public * 00017 * License along with the script. * 00018 * If not, see http://www.gnu.org/licenses/lgpl.html * 00019 * * 00020 * The TYPO3 project - inspiring people to share! * 00021 * */ 00022 00023 /** 00024 * Testcase for WidgetRequestBuilder 00025 * 00026 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later 00027 */ 00028 class Tx_Fluid_Tests_Unit_Core_Widget_WidgetRequestBuilderTest extends Tx_Extbase_Tests_Unit_BaseTestCase { 00029 00030 /** 00031 * @var Tx_Fluid_Core_Widget_WidgetRequestBuilder 00032 */ 00033 protected $widgetRequestBuilder; 00034 00035 /** 00036 * @var Tx_Extbase_Object_ObjectManagerInterface 00037 */ 00038 protected $mockObjectManager; 00039 00040 /** 00041 * @var Tx_Fluid_Core_Widget_WidgetRequest 00042 */ 00043 protected $mockWidgetRequest; 00044 00045 /** 00046 * @var Tx_Fluid_Core_Widget_AjaxWidgetContextHolder 00047 */ 00048 protected $mockAjaxWidgetContextHolder; 00049 00050 /** 00051 * @var Tx_Fluid_Core_Widget_WidgetContext 00052 */ 00053 protected $mockWidgetContext; 00054 00055 /** 00056 * @var array 00057 */ 00058 protected $serverBackup; 00059 00060 /** 00061 * @var array 00062 */ 00063 protected $getBackup; 00064 00065 /** 00066 * @var array 00067 */ 00068 protected $postBackup; 00069 00070 /** 00071 * @author Sebastian Kurfürst <sebastian@typo3.org> 00072 * @author Bastian Waidelich <bastian@typo3.org> 00073 */ 00074 public function setUp() { 00075 $this->serverBackup = $_SERVER; 00076 $this->getBackup = $_GET; 00077 $this->postBackup = $_POST; 00078 $this->widgetRequestBuilder = $this->getAccessibleMock('Tx_Fluid_Core_Widget_WidgetRequestBuilder', array('setArgumentsFromRawRequestData')); 00079 00080 $this->mockWidgetRequest = $this->getMock('Tx_Fluid_Core_Widget_WidgetRequest'); 00081 00082 $this->mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManagerInterface'); 00083 $this->mockObjectManager->expects($this->once())->method('create')->with('Tx_Fluid_Core_Widget_WidgetRequest')->will($this->returnValue($this->mockWidgetRequest)); 00084 00085 $this->widgetRequestBuilder->_set('objectManager', $this->mockObjectManager); 00086 00087 $this->mockWidgetContext = $this->getMock('Tx_Fluid_Core_Widget_WidgetContext'); 00088 00089 $this->mockAjaxWidgetContextHolder = $this->getMock('Tx_Fluid_Core_Widget_AjaxWidgetContextHolder'); 00090 $this->widgetRequestBuilder->injectAjaxWidgetContextHolder($this->mockAjaxWidgetContextHolder); 00091 $this->mockAjaxWidgetContextHolder->expects($this->once())->method('get')->will($this->returnValue($this->mockWidgetContext)); 00092 } 00093 00094 /** 00095 * @return void 00096 */ 00097 public function tearDown() { 00098 $_SERVER = $this->serverBackup; 00099 $_GET = $this->getBackup; 00100 $_POST = $this->postBackup; 00101 } 00102 00103 /** 00104 * @test 00105 * @author Bastian Waidelich <bastian@typo3.org> 00106 */ 00107 public function buildSetsRequestUri() { 00108 $requestUri = t3lib_div::getIndpEnv('TYPO3_REQUEST_URL'); 00109 $this->mockWidgetRequest->expects($this->once())->method('setRequestURI')->with($requestUri); 00110 00111 $this->widgetRequestBuilder->build(); 00112 } 00113 00114 /** 00115 * @test 00116 * @author Bastian Waidelich <bastian@typo3.org> 00117 */ 00118 public function buildSetsBaseUri() { 00119 $baseUri = t3lib_div::getIndpEnv('TYPO3_SITE_URL'); 00120 $this->mockWidgetRequest->expects($this->once())->method('setBaseURI')->with($baseUri); 00121 00122 $this->widgetRequestBuilder->build(); 00123 } 00124 00125 /** 00126 * @test 00127 * @author Sebastian Kurfürst <sebastian@typo3.org> 00128 * @author Bastian Waidelich <bastian@typo3.org> 00129 */ 00130 public function buildSetsRequestMethod() { 00131 $_SERVER['REQUEST_METHOD'] = 'POST'; 00132 $this->mockWidgetRequest->expects($this->once())->method('setMethod')->with('POST'); 00133 00134 $this->widgetRequestBuilder->build(); 00135 } 00136 00137 /** 00138 * @test 00139 * @author Bastian Waidelich <bastian@typo3.org> 00140 */ 00141 public function buildSetsPostArgumentsFromRequest() { 00142 $_SERVER['REQUEST_METHOD'] = 'POST'; 00143 $_GET = array('get' => 'foo'); 00144 $_POST = array('post' => 'bar'); 00145 $this->mockWidgetRequest->expects($this->once())->method('setArguments')->with($_POST); 00146 00147 $this->widgetRequestBuilder->build(); 00148 } 00149 00150 /** 00151 * @test 00152 * @author Bastian Waidelich <bastian@typo3.org> 00153 */ 00154 public function buildSetsGetArgumentsFromRequest() { 00155 $_SERVER['REQUEST_METHOD'] = 'GET'; 00156 $_GET = array('get' => 'foo'); 00157 $_POST = array('post' => 'bar'); 00158 $this->mockWidgetRequest->expects($this->once())->method('setArguments')->with($_GET); 00159 00160 $this->widgetRequestBuilder->build(); 00161 } 00162 00163 /** 00164 * @test 00165 * @author Sebastian Kurfürst <sebastian@typo3.org> 00166 * @author Bastian Waidelich <bastian@typo3.org> 00167 */ 00168 public function buildSetsControllerActionNameFromGetArguments() { 00169 $_GET = array('action' => 'myAction'); 00170 $this->mockWidgetRequest->expects($this->once())->method('setControllerActionName')->with('myAction'); 00171 00172 $this->widgetRequestBuilder->build(); 00173 } 00174 00175 /** 00176 * @test 00177 * @author Sebastian Kurfürst <sebastian@typo3.org> 00178 * @author Bastian Waidelich <bastian@typo3.org> 00179 */ 00180 public function buildSetsWidgetContext() { 00181 $_GET = array('fluid-widget-id' => '123'); 00182 $this->mockAjaxWidgetContextHolder->expects($this->once())->method('get')->with('123')->will($this->returnValue($this->mockWidgetContext)); 00183 $this->mockWidgetRequest->expects($this->once())->method('setWidgetContext')->with($this->mockWidgetContext); 00184 00185 $this->widgetRequestBuilder->build(); 00186 } 00187 00188 /** 00189 * @test 00190 * @author Sebastian Kurfürst <sebastian@typo3.org> 00191 */ 00192 public function buildReturnsRequest() { 00193 $expected = $this->mockWidgetRequest; 00194 $actual = $this->widgetRequestBuilder->build(); 00195 $this->assertSame($expected, $actual); 00196 } 00197 } 00198 ?>
1.8.0