85320176b4c6d8545e8c9c014b196f35738572e7
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / MVC / Web / RequestBuilder_testcase.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
6 * All rights reserved
7 *
8 * This class is a backport of the corresponding class of FLOW3.
9 * All credits go to the v5 team.
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 class Tx_Extbase_MVC_Web_RequestBuilder_testcase extends Tx_Extbase_Base_testcase {
29
30 public function __construct() {
31 require_once(t3lib_extMgm::extPath('extbase', 'Classes/MVC/Web/RequestBuilder.php'));
32 }
33
34 public function setUp() {
35 $this->configuration = array(
36 'userFunc' => 'Tx_Extbase_Dispatcher->dispatch',
37 'pluginName' => 'pi1',
38 'extensionName' => 'MyExtension',
39 'controller' => 'TheFirstController',
40 'action' => 'show',
41 'switchableControllerActions.' => array(
42 '1.' => array(
43 'controller' => 'TheFirstController',
44 'actions' => ',show,index, ,new,create,delete,edit,update,setup,test'
45 ),
46 '2.' => array(
47 'controller' => 'TheSecondController',
48 'actions' => 'show, index'
49 ),
50 '3.' => array(
51 'controller' => 'TheThirdController',
52 'actions' => 'delete,create'
53 )
54 )
55 );
56 $this->builder = new Tx_Extbase_MVC_Web_RequestBuilder;
57 }
58
59 /**
60 * @test
61 */
62 public function buildReturnsAWebRequestObject() {
63 $this->builder->initialize($this->configuration);
64 $request = $this->builder->build();
65 $this->assertEquals('Tx_Extbase_MVC_Web_Request', get_class($request));
66 $this->assertEquals('pi1', $request->getPluginName());
67 $this->assertEquals('MyExtension', $request->getControllerExtensionName());
68 $this->assertEquals('TheFirstController', $request->getControllerName());
69 $this->assertEquals('show', $request->getControllerActionName());
70 }
71
72 /**
73 * @test
74 */
75 public function buildWithoutConfigurationReturnsAWebRequestObjectWithDefaultSettings() {
76 $request = $this->builder->build();
77 $this->assertEquals('plugin', $request->getPluginName());
78 $this->assertEquals('Extbase', $request->getControllerExtensionName());
79 $this->assertEquals('Standard', $request->getControllerName());
80 $this->assertEquals('index', $request->getControllerActionName());
81 }
82
83 /**
84 * @test
85 */
86 public function buildWithMissingControllerConfigurationsReturnsAWebRequestObjectWithDefaultControllerSettings() {
87 $configuration = $this->configuration;
88 unset($configuration['controller']);
89 unset($configuration['action']);
90 unset($configuration['switchableControllerActions.']);
91 $this->builder->initialize($configuration);
92 $request = $this->builder->build();
93 $this->assertEquals('pi1', $request->getPluginName());
94 $this->assertEquals('MyExtension', $request->getControllerExtensionName());
95 $this->assertEquals('Standard', $request->getControllerName());
96 $this->assertEquals('index', $request->getControllerActionName());
97 }
98
99 /**
100 * @test
101 */
102 public function buildWithMissingActionsReturnsAWebRequestObjectWithDefaultControllerSettings() {
103 $configuration = $this->configuration;
104 unset($configuration['controller']);
105 unset($configuration['action']);
106 $this->builder->initialize($configuration);
107 $request = $this->builder->build();
108 $this->assertEquals('pi1', $request->getPluginName());
109 $this->assertEquals('MyExtension', $request->getControllerExtensionName());
110 $this->assertEquals('TheFirstController', $request->getControllerName());
111 $this->assertEquals('show', $request->getControllerActionName());
112 }
113
114 /**
115 * @test
116 */
117 public function buildSetsTheRequestURIInTheRequestObject() {
118 $this->builder->initialize($this->configuration);
119 $request = $this->builder->build();
120 $this->assertEquals(t3lib_div::getIndpEnv('TYPO3_REQUEST_URL'), $request->getRequestURI());
121 }
122
123 }
124 ?>