Extbase:
[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 script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 class Tx_Extbase_MVC_Web_RequestBuilder_testcase extends Tx_Extbase_Base_testcase {
26
27 public function __construct() {
28 require_once(t3lib_extMgm::extPath('extbase', 'Classes/MVC/Web/RequestBuilder.php'));
29 }
30
31 public function setUp() {
32 $this->configuration = array(
33 'userFunc' => 'Tx_Extbase_Dispatcher->dispatch',
34 'pluginName' => 'pi1',
35 'extensionName' => 'MyExtension',
36 'controller' => 'TheFirstController',
37 'action' => 'show',
38 'switchableControllerActions.' => array(
39 '1.' => array(
40 'controller' => 'TheFirstController',
41 'actions' => ',show,index, ,new,create,delete,edit,update,setup,test'
42 ),
43 '2.' => array(
44 'controller' => 'TheSecondController',
45 'actions' => 'show, index'
46 ),
47 '3.' => array(
48 'controller' => 'TheThirdController',
49 'actions' => 'delete,create'
50 )
51 )
52 );
53 $this->builder = new Tx_Extbase_MVC_Web_RequestBuilder;
54 }
55
56 public function test_BuildReturnsAWebRequestObject() {
57 $this->builder->initialize($this->configuration);
58 $request = $this->builder->build();
59 $this->assertEquals('Tx_Extbase_MVC_Web_Request', get_class($request));
60 $this->assertEquals('pi1', $request->getPluginName());
61 $this->assertEquals('MyExtension', $request->getControllerExtensionName());
62 $this->assertEquals('TheFirstController', $request->getControllerName());
63 $this->assertEquals('show', $request->getControllerActionName());
64 }
65
66 public function test_BuildWithoutConfigurationReturnsAWebRequestObjectWithDefaultSettings() {
67 $request = $this->builder->build();
68 $this->assertEquals('plugin', $request->getPluginName());
69 $this->assertEquals('Extbase', $request->getControllerExtensionName());
70 $this->assertEquals('Default', $request->getControllerName());
71 $this->assertEquals('index', $request->getControllerActionName());
72 }
73
74 public function test_BuildWithMissingControllerConfigurationsReturnsAWebRequestObjectWithDefaultControllerSettings() {
75 $configuration = $this->configuration;
76 unset($configuration['controller']);
77 unset($configuration['action']);
78 unset($configuration['switchableControllerActions.']);
79 $this->builder->initialize($configuration);
80 $request = $this->builder->build();
81 $this->assertEquals('pi1', $request->getPluginName());
82 $this->assertEquals('MyExtension', $request->getControllerExtensionName());
83 $this->assertEquals('Default', $request->getControllerName());
84 $this->assertEquals('index', $request->getControllerActionName());
85 }
86
87 public function test_BuildWithMissingActionsReturnsAWebRequestObjectWithDefaultControllerSettings() {
88 $configuration = $this->configuration;
89 unset($configuration['controller']);
90 unset($configuration['action']);
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('TheFirstController', $request->getControllerName());
96 $this->assertEquals('show', $request->getControllerActionName());
97 }
98
99 public function test_BuildSetsTheRequestURIInTheRequestObject() {
100 $this->builder->initialize($this->configuration);
101 $request = $this->builder->build();
102 $this->assertEquals(t3lib_div::getIndpEnv('TYPO3_REQUEST_URL'), $request->getRequestURI());
103 }
104
105 }
106 ?>