[CLEANUP] Rework/simplify copyright header and remove @package
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Tests / Unit / Core / Widget / WidgetRequestBuilderTest.php
1 <?php
2 namespace TYPO3\CMS\Fluid\Tests\Unit\Core\Widget;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is backported from the TYPO3 Flow package "TYPO3.Fluid".
8 *
9 * It is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License, either version 2
11 * of the License, or any later version.
12 *
13 * For the full copyright and license information, please read the
14 * LICENSE.txt file that was distributed with this source code.
15 *
16 * The TYPO3 project - inspiring people to share!
17 */
18
19 /**
20 * Test case
21 */
22 class WidgetRequestBuilderTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
23
24 /**
25 * @var \TYPO3\CMS\Fluid\Core\Widget\WidgetRequestBuilder
26 */
27 protected $widgetRequestBuilder;
28
29 /**
30 * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
31 */
32 protected $mockObjectManager;
33
34 /**
35 * @var \TYPO3\CMS\Fluid\Core\Widget\WidgetRequest
36 */
37 protected $mockWidgetRequest;
38
39 /**
40 * @var \TYPO3\CMS\Fluid\Core\Widget\AjaxWidgetContextHolder
41 */
42 protected $mockAjaxWidgetContextHolder;
43
44 /**
45 * @var \TYPO3\CMS\Fluid\Core\Widget\WidgetContext
46 */
47 protected $mockWidgetContext;
48
49 public function setUp() {
50 $this->widgetRequestBuilder = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\Core\\Widget\\WidgetRequestBuilder', array('setArgumentsFromRawRequestData'));
51 $this->mockWidgetRequest = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Widget\\WidgetRequest');
52 $this->mockObjectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
53 $this->mockObjectManager->expects($this->once())->method('get')->with('TYPO3\\CMS\\Fluid\\Core\\Widget\\WidgetRequest')->will($this->returnValue($this->mockWidgetRequest));
54 $this->widgetRequestBuilder->_set('objectManager', $this->mockObjectManager);
55 $this->mockWidgetContext = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Widget\\WidgetContext');
56 $this->mockAjaxWidgetContextHolder = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Widget\\AjaxWidgetContextHolder', array(), array(), '', FALSE);
57 $this->widgetRequestBuilder->injectAjaxWidgetContextHolder($this->mockAjaxWidgetContextHolder);
58 $this->mockAjaxWidgetContextHolder->expects($this->once())->method('get')->will($this->returnValue($this->mockWidgetContext));
59 }
60
61 /**
62 * @test
63 */
64 public function buildSetsRequestUri() {
65 $requestUri = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL');
66 $this->mockWidgetRequest->expects($this->once())->method('setRequestURI')->with($requestUri);
67 $this->widgetRequestBuilder->build();
68 }
69
70 /**
71 * @test
72 */
73 public function buildSetsBaseUri() {
74 $baseUri = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
75 $this->mockWidgetRequest->expects($this->once())->method('setBaseURI')->with($baseUri);
76 $this->widgetRequestBuilder->build();
77 }
78
79 /**
80 * @test
81 */
82 public function buildSetsRequestMethod() {
83 $_SERVER['REQUEST_METHOD'] = 'POST';
84 $this->mockWidgetRequest->expects($this->once())->method('setMethod')->with('POST');
85 $this->widgetRequestBuilder->build();
86 }
87
88 /**
89 * @test
90 */
91 public function buildSetsPostArgumentsFromRequest() {
92 $_SERVER['REQUEST_METHOD'] = 'POST';
93 $_GET = array('get' => 'foo');
94 $_POST = array('post' => 'bar');
95 $this->mockWidgetRequest->expects($this->once())->method('setArguments')->with($_POST);
96 $this->widgetRequestBuilder->build();
97 }
98
99 /**
100 * @test
101 */
102 public function buildSetsGetArgumentsFromRequest() {
103 $_SERVER['REQUEST_METHOD'] = 'GET';
104 $_GET = array('get' => 'foo');
105 $_POST = array('post' => 'bar');
106 $this->mockWidgetRequest->expects($this->once())->method('setArguments')->with($_GET);
107 $this->widgetRequestBuilder->build();
108 }
109
110 /**
111 * @test
112 */
113 public function buildSetsControllerActionNameFromGetArguments() {
114 $_GET = array('action' => 'myAction');
115 $this->mockWidgetRequest->expects($this->once())->method('setControllerActionName')->with('myAction');
116 $this->widgetRequestBuilder->build();
117 }
118
119 /**
120 * @test
121 */
122 public function buildSetsWidgetContext() {
123 $_GET = array('fluid-widget-id' => '123');
124 $this->mockAjaxWidgetContextHolder->expects($this->once())->method('get')->with('123')->will($this->returnValue($this->mockWidgetContext));
125 $this->mockWidgetRequest->expects($this->once())->method('setWidgetContext')->with($this->mockWidgetContext);
126 $this->widgetRequestBuilder->build();
127 }
128
129 /**
130 * @test
131 */
132 public function buildReturnsRequest() {
133 $expected = $this->mockWidgetRequest;
134 $actual = $this->widgetRequestBuilder->build();
135 $this->assertSame($expected, $actual);
136 }
137 }