d0063ff759d5810ef6f17ea9314c01093e065591
[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 /**
15 * Test case
16 */
17 class AbstractTemplateViewTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
18
19 /**
20 * @var \TYPO3\CMS\Fluid\View\AbstractTemplateView
21 */
22 protected $view;
23
24 /**
25 * @var \TYPO3\CMS\Fluid\Core\Rendering\RenderingContext
26 */
27 protected $renderingContext;
28
29 /**
30 * @var \TYPO3\CMS\Fluid\Core\ViewHelper\ViewHelperVariableContainer
31 */
32 protected $viewHelperVariableContainer;
33
34 /**
35 * @var \TYPO3\CMS\Fluid\Core\ViewHelper\TemplateVariableContainer
36 */
37 protected $templateVariableContainer;
38
39 /**
40 * Sets up this test case
41 *
42 * @return void
43 */
44 public function setUp() {
45 $this->templateVariableContainer = $this->getMock(\TYPO3\CMS\Fluid\Core\ViewHelper\TemplateVariableContainer::class, array('exists', 'remove', 'add'));
46 $this->viewHelperVariableContainer = $this->getMock(\TYPO3\CMS\Fluid\Core\ViewHelper\ViewHelperVariableContainer::class, array('setView'));
47 $this->renderingContext = $this->getMock(\TYPO3\CMS\Fluid\Core\Rendering\RenderingContext::class, array('getViewHelperVariableContainer', 'getTemplateVariableContainer'));
48 $this->renderingContext->expects($this->any())->method('getViewHelperVariableContainer')->will($this->returnValue($this->viewHelperVariableContainer));
49 $this->renderingContext->expects($this->any())->method('getTemplateVariableContainer')->will($this->returnValue($this->templateVariableContainer));
50 $this->view = $this->getMock(\TYPO3\CMS\Fluid\View\AbstractTemplateView::class, array('getTemplateSource', 'getLayoutSource', 'getPartialSource', 'canRender', 'getTemplateIdentifier', 'getLayoutIdentifier', 'getPartialIdentifier'));
51 $this->view->setRenderingContext($this->renderingContext);
52 }
53
54 /**
55 * @test
56 */
57 public function viewIsPlacedInViewHelperVariableContainer() {
58 $this->viewHelperVariableContainer->expects($this->once())->method('setView')->with($this->view);
59 $this->view->setRenderingContext($this->renderingContext);
60 }
61
62 /**
63 * @test
64 */
65 public function assignAddsValueToTemplateVariableContainer() {
66 $this->templateVariableContainer->expects($this->at(0))->method('exists')->with('foo')->will($this->returnValue(FALSE));
67 $this->templateVariableContainer->expects($this->at(1))->method('add')->with('foo', 'FooValue');
68 $this->templateVariableContainer->expects($this->at(2))->method('exists')->with('bar')->will($this->returnValue(FALSE));
69 $this->templateVariableContainer->expects($this->at(3))->method('add')->with('bar', 'BarValue');
70
71 $this->view
72 ->assign('foo', 'FooValue')
73 ->assign('bar', 'BarValue');
74 }
75
76 /**
77 * @test
78 */
79 public function assignCanOverridePreviouslyAssignedValues() {
80 $this->templateVariableContainer->expects($this->at(0))->method('exists')->with('foo')->will($this->returnValue(FALSE));
81 $this->templateVariableContainer->expects($this->at(1))->method('add')->with('foo', 'FooValue');
82 $this->templateVariableContainer->expects($this->at(2))->method('exists')->with('foo')->will($this->returnValue(TRUE));
83 $this->templateVariableContainer->expects($this->at(3))->method('remove')->with('foo');
84 $this->templateVariableContainer->expects($this->at(4))->method('add')->with('foo', 'FooValueOverridden');
85
86 $this->view->assign('foo', 'FooValue');
87 $this->view->assign('foo', 'FooValueOverridden');
88 }
89
90 /**
91 * @test
92 */
93 public function assignMultipleAddsValuesToTemplateVariableContainer() {
94 $this->templateVariableContainer->expects($this->at(0))->method('exists')->with('foo')->will($this->returnValue(FALSE));
95 $this->templateVariableContainer->expects($this->at(1))->method('add')->with('foo', 'FooValue');
96 $this->templateVariableContainer->expects($this->at(2))->method('exists')->with('bar')->will($this->returnValue(FALSE));
97 $this->templateVariableContainer->expects($this->at(3))->method('add')->with('bar', 'BarValue');
98 $this->templateVariableContainer->expects($this->at(4))->method('exists')->with('baz')->will($this->returnValue(FALSE));
99 $this->templateVariableContainer->expects($this->at(5))->method('add')->with('baz', 'BazValue');
100
101 $this->view
102 ->assignMultiple(array('foo' => 'FooValue', 'bar' => 'BarValue'))
103 ->assignMultiple(array('baz' => 'BazValue'));
104 }
105
106 /**
107 * @test
108 */
109 public function assignMultipleCanOverridePreviouslyAssignedValues() {
110 $this->templateVariableContainer->expects($this->at(0))->method('exists')->with('foo')->will($this->returnValue(FALSE));
111 $this->templateVariableContainer->expects($this->at(1))->method('add')->with('foo', 'FooValue');
112 $this->templateVariableContainer->expects($this->at(2))->method('exists')->with('foo')->will($this->returnValue(TRUE));
113 $this->templateVariableContainer->expects($this->at(3))->method('remove')->with('foo');
114 $this->templateVariableContainer->expects($this->at(4))->method('add')->with('foo', 'FooValueOverridden');
115 $this->templateVariableContainer->expects($this->at(5))->method('exists')->with('bar')->will($this->returnValue(FALSE));
116 $this->templateVariableContainer->expects($this->at(6))->method('add')->with('bar', 'BarValue');
117
118 $this->view->assign('foo', 'FooValue');
119 $this->view->assignMultiple(array('foo' => 'FooValueOverridden', 'bar' => 'BarValue'));
120 }
121
122 }