‪TYPO3CMS  10.4
CObjectViewHelperTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Prophecy\Argument;
27 use TYPO3\TestingFramework\Fluid\Unit\ViewHelpers\ViewHelperBaseTestcase;
28 use TYPO3Fluid\Fluid\Core\ViewHelper\Exception;
29 
33 class ‪CObjectViewHelperTest extends ViewHelperBaseTestcase
34 {
38  protected ‪$resetSingletonInstances = true;
39 
43  protected ‪$viewHelper;
44 
48  protected ‪$configurationManager;
49 
53  protected ‪$contentObjectRenderer;
54 
58  protected function ‪setUp(): void
59  {
60  parent::setUp();
61  $this->viewHelper = new ‪CObjectViewHelper();
62  $this->injectDependenciesIntoViewHelper($this->viewHelper);
63 
64  $this->configurationManager = $this->prophesize(ConfigurationManagerInterface::class);
65  $this->contentObjectRenderer = $this->prophesize(ContentObjectRenderer::class);
66  }
67 
72  {
73  $this->‪stubBaseDependencies();
74 
75  $this->setArgumentsUnderTest(
76  $this->viewHelper,
77  [
78  'typoscriptObjectPath' => 'test',
79  'data' => 'foo',
80  ]
81  );
82  $configArray = [
83  'test' => 'TEXT',
84  'test.' => [],
85  ];
86  $this->configurationManager->getConfiguration(Argument::any())->willReturn($configArray);
87 
88  $this->contentObjectRenderer->start(['foo'], '')->willReturn();
89  $this->viewHelper->initializeArgumentsAndRender();
90  }
91 
96  {
97  $this->‪stubBaseDependencies();
98 
99  $this->viewHelper->setRenderChildrenClosure(
100  function () {
101  return 'foo';
102  }
103  );
104  $this->setArgumentsUnderTest(
105  $this->viewHelper,
106  [
107  'typoscriptObjectPath' => 'test',
108  ]
109  );
110  $configArray = [
111  'test' => 'TEXT',
112  'test.' => [],
113  ];
114  $this->configurationManager->getConfiguration(Argument::any())->willReturn($configArray);
115 
116  $this->contentObjectRenderer->start(['foo'], '')->willReturn();
117  $this->viewHelper->initializeArgumentsAndRender();
118  }
119 
121  {
122  return [
123  'Single path' => [
124  'test',
125  1540246570
126  ],
127  'Multi path' => [
128  'test.path',
129  1253191023
130  ],
131  ];
132  }
133 
138  public function ‪renderThrowsExceptionIfTypoScriptObjectPathDoesNotExist(string $objectPath, int $exceptionCode)
139  {
140  $this->‪stubBaseDependencies();
141  $this->contentObjectRenderer->start(Argument::cetera())->willReturn();
142 
143  $this->setArgumentsUnderTest(
144  $this->viewHelper,
145  [
146  'data' => 'foo',
147  'typoscriptObjectPath' => $objectPath,
148  ]
149  );
150 
151  $this->expectException(Exception::class);
152  $this->expectExceptionCode($exceptionCode);
153  $this->viewHelper->initializeArgumentsAndRender();
154  }
155 
157  {
158  $subConfigArray = [
159  'value' => 'Hello World',
160  'wrap' => 'ab | cd',
161  ];
162  return [
163  'Single path' => [
164  'test',
165  [
166  'test' => 'TEXT',
167  'test.' => $subConfigArray,
168  ],
169  $subConfigArray
170  ],
171  'Single path no config' => [
172  'test',
173  [
174  'test' => 'TEXT',
175  ],
176  []
177  ],
178  'Multi path' => [
179  'plugin.test',
180  [
181  'plugin.' => [
182  'test' => 'TEXT',
183  'test.' => $subConfigArray,
184  ]
185  ],
186  $subConfigArray
187  ],
188  'Multi path no config' => [
189  'plugin.test',
190  [
191  'plugin.' => [
192  'test' => 'TEXT',
193  ]
194  ],
195  []
196  ],
197  ];
198  }
199 
207  public function ‪renderReturnsSimpleTypoScriptValue(string $objectPath, array $configArray, array $subConfigArray)
208  {
209  $this->‪stubBaseDependencies();
210  $this->setArgumentsUnderTest(
211  $this->viewHelper,
212  [
213  'typoscriptObjectPath' => $objectPath,
214  'data' => 'foo',
215  'table' => 'table',
216  ]
217  );
218 
219  $this->configurationManager->getConfiguration(Argument::any())->willReturn($configArray);
220 
221  $this->contentObjectRenderer->start(['foo'], 'table')->willReturn();
222  $this->contentObjectRenderer->setCurrentVal('foo')->willReturn();
223  $this->contentObjectRenderer->cObjGetSingle('TEXT', $subConfigArray, Argument::any())->willReturn('Hello World');
224 
225  $objectManager = $this->prophesize(ObjectManager::class);
226  $objectManager->get(ConfigurationManagerInterface::class)->willReturn($this->configurationManager->reveal());
227  GeneralUtility::addInstance(ContentObjectRenderer::class, $this->contentObjectRenderer->reveal());
228  GeneralUtility::setSingletonInstance(ObjectManager::class, $objectManager->reveal());
229 
230  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
231  $expectedResult = 'Hello World';
232  self::assertSame($expectedResult, $actualResult);
233  }
234 
238  protected function ‪stubBaseDependencies()
239  {
240  $this->configurationManager->getConfiguration(Argument::any())->willReturn([]);
241  $this->contentObjectRenderer->setCurrentVal(Argument::cetera())->willReturn();
242  $this->contentObjectRenderer->cObjGetSingle(Argument::cetera())->willReturn('');
243  $objectManager = $this->prophesize(ObjectManager::class);
244  $objectManager->get(ConfigurationManagerInterface::class)->willReturn($this->configurationManager->reveal());
245  GeneralUtility::setSingletonInstance(ObjectManager::class, $objectManager->reveal());
246  ‪$GLOBALS['TSFE'] = $this->getAccessibleMock(TypoScriptFrontendController::class, ['initCaches'], [], '', false);
247  }
248 }
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\CObjectViewHelperTest\stubBaseDependencies
‪stubBaseDependencies()
Definition: CObjectViewHelperTest.php:234
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\CObjectViewHelperTest\renderThrowsExceptionIfTypoScriptObjectPathDoesNotExistDataProvider
‪renderThrowsExceptionIfTypoScriptObjectPathDoesNotExistDataProvider()
Definition: CObjectViewHelperTest.php:116
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\CObjectViewHelperTest\viewHelperAcceptsChildrenClosureAsInput
‪viewHelperAcceptsChildrenClosureAsInput()
Definition: CObjectViewHelperTest.php:91
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
Definition: ConfigurationManagerInterface.php:28
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\CObjectViewHelperTest
Definition: CObjectViewHelperTest.php:34
‪TYPO3\CMS\Fluid\ViewHelpers\CObjectViewHelper
Definition: CObjectViewHelper.php:85
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\CObjectViewHelperTest\$contentObjectRenderer
‪ContentObjectRenderer $contentObjectRenderer
Definition: CObjectViewHelperTest.php:49
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\CObjectViewHelperTest\renderThrowsExceptionIfTypoScriptObjectPathDoesNotExist
‪renderThrowsExceptionIfTypoScriptObjectPathDoesNotExist(string $objectPath, int $exceptionCode)
Definition: CObjectViewHelperTest.php:134
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\CObjectViewHelperTest\setUp
‪setUp()
Definition: CObjectViewHelperTest.php:54
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\CObjectViewHelperTest\$configurationManager
‪ConfigurationManagerInterface $configurationManager
Definition: CObjectViewHelperTest.php:45
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\CObjectViewHelperTest\renderReturnsSimpleTypoScriptValue
‪renderReturnsSimpleTypoScriptValue(string $objectPath, array $configArray, array $subConfigArray)
Definition: CObjectViewHelperTest.php:203
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\CObjectViewHelperTest\renderReturnsSimpleTypoScriptValueDataProvider
‪renderReturnsSimpleTypoScriptValueDataProvider()
Definition: CObjectViewHelperTest.php:152
‪TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
Definition: TypoScriptFrontendController.php:98
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\CObjectViewHelperTest\viewHelperAcceptsDataParameterAsInput
‪viewHelperAcceptsDataParameterAsInput()
Definition: CObjectViewHelperTest.php:67
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
Definition: ContentObjectRenderer.php:97
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\CObjectViewHelperTest\$viewHelper
‪CObjectViewHelper $viewHelper
Definition: CObjectViewHelperTest.php:41
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers
‪TYPO3\CMS\Extbase\Object\ObjectManager
Definition: ObjectManager.php:28
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\CObjectViewHelperTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: CObjectViewHelperTest.php:37