TYPO3 CMS  TYPO3_7-6
AbstractTemplateViewTest.php
Go to the documentation of this file.
1 <?php
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 
20 
25 {
29  protected $view;
30 
34  protected $renderingContext;
35 
40 
45 
51  protected function setUp()
52  {
53  $this->templateVariableContainer = $this->getMock(TemplateVariableContainer::class, ['exists', 'remove', 'add']);
54  $this->viewHelperVariableContainer = $this->getMock(ViewHelperVariableContainer::class, ['setView']);
55  $this->renderingContext = $this->getMock(RenderingContext::class, ['getViewHelperVariableContainer', 'getTemplateVariableContainer']);
56  $this->renderingContext->expects($this->any())->method('getViewHelperVariableContainer')->will($this->returnValue($this->viewHelperVariableContainer));
57  $this->renderingContext->expects($this->any())->method('getTemplateVariableContainer')->will($this->returnValue($this->templateVariableContainer));
58  $this->view = $this->getAccessibleMock(AbstractTemplateView::class, ['getTemplateSource', 'getLayoutSource', 'getPartialSource', 'canRender', 'getTemplateIdentifier', 'getLayoutIdentifier', 'getPartialIdentifier']);
59  $this->view->setRenderingContext($this->renderingContext);
60  }
61 
66  {
67  $this->viewHelperVariableContainer->expects($this->once())->method('setView')->with($this->view);
68  $this->view->setRenderingContext($this->renderingContext);
69  }
70 
75  {
76  $this->templateVariableContainer->expects($this->at(0))->method('exists')->with('foo')->will($this->returnValue(false));
77  $this->templateVariableContainer->expects($this->at(1))->method('add')->with('foo', 'FooValue');
78  $this->templateVariableContainer->expects($this->at(2))->method('exists')->with('bar')->will($this->returnValue(false));
79  $this->templateVariableContainer->expects($this->at(3))->method('add')->with('bar', 'BarValue');
80 
81  $this->view
82  ->assign('foo', 'FooValue')
83  ->assign('bar', 'BarValue');
84  }
85 
90  {
91  $this->templateVariableContainer->expects($this->at(0))->method('exists')->with('foo')->will($this->returnValue(false));
92  $this->templateVariableContainer->expects($this->at(1))->method('add')->with('foo', 'FooValue');
93  $this->templateVariableContainer->expects($this->at(2))->method('exists')->with('foo')->will($this->returnValue(true));
94  $this->templateVariableContainer->expects($this->at(3))->method('remove')->with('foo');
95  $this->templateVariableContainer->expects($this->at(4))->method('add')->with('foo', 'FooValueOverridden');
96 
97  $this->view->assign('foo', 'FooValue');
98  $this->view->assign('foo', 'FooValueOverridden');
99  }
100 
105  {
106  $this->templateVariableContainer->expects($this->at(0))->method('exists')->with('foo')->will($this->returnValue(false));
107  $this->templateVariableContainer->expects($this->at(1))->method('add')->with('foo', 'FooValue');
108  $this->templateVariableContainer->expects($this->at(2))->method('exists')->with('bar')->will($this->returnValue(false));
109  $this->templateVariableContainer->expects($this->at(3))->method('add')->with('bar', 'BarValue');
110  $this->templateVariableContainer->expects($this->at(4))->method('exists')->with('baz')->will($this->returnValue(false));
111  $this->templateVariableContainer->expects($this->at(5))->method('add')->with('baz', 'BazValue');
112 
113  $this->view
114  ->assignMultiple(['foo' => 'FooValue', 'bar' => 'BarValue'])
115  ->assignMultiple(['baz' => 'BazValue']);
116  }
117 
122  {
123  $this->templateVariableContainer->expects($this->at(0))->method('exists')->with('foo')->will($this->returnValue(false));
124  $this->templateVariableContainer->expects($this->at(1))->method('add')->with('foo', 'FooValue');
125  $this->templateVariableContainer->expects($this->at(2))->method('exists')->with('foo')->will($this->returnValue(true));
126  $this->templateVariableContainer->expects($this->at(3))->method('remove')->with('foo');
127  $this->templateVariableContainer->expects($this->at(4))->method('add')->with('foo', 'FooValueOverridden');
128  $this->templateVariableContainer->expects($this->at(5))->method('exists')->with('bar')->will($this->returnValue(false));
129  $this->templateVariableContainer->expects($this->at(6))->method('add')->with('bar', 'BarValue');
130 
131  $this->view->assign('foo', 'FooValue');
132  $this->view->assignMultiple(['foo' => 'FooValueOverridden', 'bar' => 'BarValue']);
133  }
134 
139  {
140  return [
141  'keeps ucfirst' => ['LayoutPath', 'LayoutPath'],
142  'creates ucfirst' => ['layoutPath', 'LayoutPath'],
143  'ucfirst on file name only' => ['some/path/layout', 'some/path/Layout'],
144  'keeps ucfirst on file name' => ['some/Path/Layout', 'some/Path/Layout'],
145  ];
146  }
147 
154  public function ucFileNameInPathProperlyUpperCasesFileNames($path, $expected)
155  {
156  $this->assertSame($expected, $this->view->_call('ucFileNameInPath', $path));
157  }
158 }
getAccessibleMock( $originalClassName, $methods=[], array $arguments=[], $mockClassName='', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)