[BUGFIX] Standalone- and TemplateView must not require ucfirst file names
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Tests / Unit / View / AbstractTemplateViewTest.php
1 <?php
2 namespace TYPO3\CMS\Fluid\Tests\Unit\View;
3
4 /* *
5 * This script is backported from the TYPO3 Flow 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 * The TYPO3 project - inspiring people to share! *
12 * */
13
14 use TYPO3\CMS\Core\Tests\AccessibleObjectInterface;
15 use TYPO3\CMS\Core\Tests\UnitTestCase;
16 use TYPO3\CMS\Fluid\Core\Rendering\RenderingContext;
17 use TYPO3\CMS\Fluid\Core\ViewHelper\TemplateVariableContainer;
18 use TYPO3\CMS\Fluid\Core\ViewHelper\ViewHelperVariableContainer;
19 use TYPO3\CMS\Fluid\View\AbstractTemplateView;
20
21 /**
22 * Test case
23 */
24 class AbstractTemplateViewTest extends UnitTestCase {
25
26 /**
27 * @var AbstractTemplateView|AccessibleObjectInterface
28 */
29 protected $view;
30
31 /**
32 * @var RenderingContext|\PHPUnit_Framework_MockObject_MockObject
33 */
34 protected $renderingContext;
35
36 /**
37 * @var ViewHelperVariableContainer|\PHPUnit_Framework_MockObject_MockObject
38 */
39 protected $viewHelperVariableContainer;
40
41 /**
42 * @var TemplateVariableContainer|\PHPUnit_Framework_MockObject_MockObject
43 */
44 protected $templateVariableContainer;
45
46 /**
47 * Sets up this test case
48 *
49 * @return void
50 */
51 public function setUp() {
52 $this->templateVariableContainer = $this->getMock(TemplateVariableContainer::class, array('exists', 'remove', 'add'));
53 $this->viewHelperVariableContainer = $this->getMock(ViewHelperVariableContainer::class, array('setView'));
54 $this->renderingContext = $this->getMock(RenderingContext::class, array('getViewHelperVariableContainer', 'getTemplateVariableContainer'));
55 $this->renderingContext->expects($this->any())->method('getViewHelperVariableContainer')->will($this->returnValue($this->viewHelperVariableContainer));
56 $this->renderingContext->expects($this->any())->method('getTemplateVariableContainer')->will($this->returnValue($this->templateVariableContainer));
57 $this->view = $this->getAccessibleMock(AbstractTemplateView::class, array('getTemplateSource', 'getLayoutSource', 'getPartialSource', 'canRender', 'getTemplateIdentifier', 'getLayoutIdentifier', 'getPartialIdentifier'));
58 $this->view->setRenderingContext($this->renderingContext);
59 }
60
61 /**
62 * @test
63 */
64 public function viewIsPlacedInViewHelperVariableContainer() {
65 $this->viewHelperVariableContainer->expects($this->once())->method('setView')->with($this->view);
66 $this->view->setRenderingContext($this->renderingContext);
67 }
68
69 /**
70 * @test
71 */
72 public function assignAddsValueToTemplateVariableContainer() {
73 $this->templateVariableContainer->expects($this->at(0))->method('exists')->with('foo')->will($this->returnValue(FALSE));
74 $this->templateVariableContainer->expects($this->at(1))->method('add')->with('foo', 'FooValue');
75 $this->templateVariableContainer->expects($this->at(2))->method('exists')->with('bar')->will($this->returnValue(FALSE));
76 $this->templateVariableContainer->expects($this->at(3))->method('add')->with('bar', 'BarValue');
77
78 $this->view
79 ->assign('foo', 'FooValue')
80 ->assign('bar', 'BarValue');
81 }
82
83 /**
84 * @test
85 */
86 public function assignCanOverridePreviouslyAssignedValues() {
87 $this->templateVariableContainer->expects($this->at(0))->method('exists')->with('foo')->will($this->returnValue(FALSE));
88 $this->templateVariableContainer->expects($this->at(1))->method('add')->with('foo', 'FooValue');
89 $this->templateVariableContainer->expects($this->at(2))->method('exists')->with('foo')->will($this->returnValue(TRUE));
90 $this->templateVariableContainer->expects($this->at(3))->method('remove')->with('foo');
91 $this->templateVariableContainer->expects($this->at(4))->method('add')->with('foo', 'FooValueOverridden');
92
93 $this->view->assign('foo', 'FooValue');
94 $this->view->assign('foo', 'FooValueOverridden');
95 }
96
97 /**
98 * @test
99 */
100 public function assignMultipleAddsValuesToTemplateVariableContainer() {
101 $this->templateVariableContainer->expects($this->at(0))->method('exists')->with('foo')->will($this->returnValue(FALSE));
102 $this->templateVariableContainer->expects($this->at(1))->method('add')->with('foo', 'FooValue');
103 $this->templateVariableContainer->expects($this->at(2))->method('exists')->with('bar')->will($this->returnValue(FALSE));
104 $this->templateVariableContainer->expects($this->at(3))->method('add')->with('bar', 'BarValue');
105 $this->templateVariableContainer->expects($this->at(4))->method('exists')->with('baz')->will($this->returnValue(FALSE));
106 $this->templateVariableContainer->expects($this->at(5))->method('add')->with('baz', 'BazValue');
107
108 $this->view
109 ->assignMultiple(array('foo' => 'FooValue', 'bar' => 'BarValue'))
110 ->assignMultiple(array('baz' => 'BazValue'));
111 }
112
113 /**
114 * @test
115 */
116 public function assignMultipleCanOverridePreviouslyAssignedValues() {
117 $this->templateVariableContainer->expects($this->at(0))->method('exists')->with('foo')->will($this->returnValue(FALSE));
118 $this->templateVariableContainer->expects($this->at(1))->method('add')->with('foo', 'FooValue');
119 $this->templateVariableContainer->expects($this->at(2))->method('exists')->with('foo')->will($this->returnValue(TRUE));
120 $this->templateVariableContainer->expects($this->at(3))->method('remove')->with('foo');
121 $this->templateVariableContainer->expects($this->at(4))->method('add')->with('foo', 'FooValueOverridden');
122 $this->templateVariableContainer->expects($this->at(5))->method('exists')->with('bar')->will($this->returnValue(FALSE));
123 $this->templateVariableContainer->expects($this->at(6))->method('add')->with('bar', 'BarValue');
124
125 $this->view->assign('foo', 'FooValue');
126 $this->view->assignMultiple(array('foo' => 'FooValueOverridden', 'bar' => 'BarValue'));
127 }
128
129 /**
130 * @return array
131 */
132 public function ucFileNameInPathProperlyUpperCasesFileNamesDataProvider() {
133 return [
134 'keeps ucfirst' => ['LayoutPath', 'LayoutPath'],
135 'creates ucfirst' => ['layoutPath', 'LayoutPath'],
136 'ucfirst on file name only' => ['some/path/layout', 'some/path/Layout'],
137 'keeps ucfirst on file name' => ['some/Path/Layout', 'some/Path/Layout'],
138 ];
139 }
140
141 /**
142 * @param string $path
143 * @param string $expected
144 * @dataProvider ucFileNameInPathProperlyUpperCasesFileNamesDataProvider
145 * @test
146 */
147 public function ucFileNameInPathProperlyUpperCasesFileNames($path, $expected) {
148 $this->assertSame($expected, $this->view->_call('ucFileNameInPath', $path));
149 }
150
151 }