TYPO3 CMS  TYPO3_8-7
CObjectViewHelperTest.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
22 
26 class CObjectViewHelperTest extends ViewHelperBaseTestcase
27 {
31  protected $viewHelper;
32 
37 
42 
46  protected function setUp()
47  {
48  parent::setUp();
49  $this->viewHelper = new CObjectViewHelper();
50  $this->injectDependenciesIntoViewHelper($this->viewHelper);
51 
52  $this->configurationManager = $this->prophesize(ConfigurationManagerInterface::class);
53  $this->contentObjectRenderer = $this->prophesize(ContentObjectRenderer::class);
54  }
55 
60  {
61  $this->stubBaseDependencies();
62 
63  $this->setArgumentsUnderTest(
64  $this->viewHelper,
65  [
66  'data' => 'foo',
67  ]
68  );
69  $this->contentObjectRenderer->start(['foo'], '')->willReturn();
70  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
71  $this->assertSame('', $actualResult);
72  }
73 
78  {
79  $this->stubBaseDependencies();
80 
81  $this->viewHelper->setRenderChildrenClosure(
82  function () {
83  return 'foo';
84  }
85  );
86  $this->setArgumentsUnderTest(
87  $this->viewHelper,
88  []
89  );
90  $this->contentObjectRenderer->start(['foo'], '')->willReturn();
91  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
92  $this->assertSame('', $actualResult);
93  }
94 
99  {
100  $this->stubBaseDependencies();
101  $this->contentObjectRenderer->start(Argument::cetera())->willReturn();
102 
103  $this->setArgumentsUnderTest(
104  $this->viewHelper,
105  [
106  'data' => 'foo',
107  'typoscriptObjectPath' => 'test.path',
108  ]
109  );
110  $this->expectException(\TYPO3\CMS\Fluid\Core\ViewHelper\Exception::class);
111  $this->expectExceptionCode(1253191023);
112  $this->viewHelper->initializeArgumentsAndRender();
113  }
114 
119  {
120  $this->setArgumentsUnderTest(
121  $this->viewHelper,
122  [
123  'typoscriptObjectPath' => 'test',
124  'data' => 'foo',
125  'table' => 'table',
126  ]
127  );
128 
129  $subConfigArray = [
130  'value' => 'Hello World',
131  'wrap' => 'ab | cd',
132  ];
133 
134  $configArray = [
135  'test' => 'TEXT',
136  'test.' => $subConfigArray,
137  ];
138 
139  $this->configurationManager->getConfiguration(Argument::any())->willReturn($configArray);
140  $this->viewHelper->injectConfigurationManager($this->configurationManager->reveal());
141 
142  $this->contentObjectRenderer->start(['foo'], 'table')->willReturn();
143  $this->contentObjectRenderer->setCurrentVal('foo')->willReturn();
144  $this->contentObjectRenderer->cObjGetSingle('TEXT', $subConfigArray)->willReturn('Hello World');
145  $this->viewHelper->injectContentObjectRenderer($this->contentObjectRenderer->reveal());
146 
147  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
148  $expectedResult = 'Hello World';
149  $this->assertSame($expectedResult, $actualResult);
150  }
151 
155  protected function stubBaseDependencies()
156  {
157  $this->configurationManager->getConfiguration(Argument::any())->willReturn([]);
158  $this->viewHelper->injectConfigurationManager($this->configurationManager->reveal());
159 
160  $this->contentObjectRenderer->setCurrentVal(Argument::cetera())->willReturn();
161  $this->contentObjectRenderer->cObjGetSingle(Argument::cetera())->willReturn('');
162  $this->viewHelper->injectContentObjectRenderer($this->contentObjectRenderer->reveal());
163  }
164 }