‪TYPO3CMS  9.5
CObjectViewHelperTest.php
Go to the documentation of this file.
1 <?php
2 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 
18 use Prophecy\Argument;
25 use TYPO3\TestingFramework\Fluid\Unit\ViewHelpers\ViewHelperBaseTestcase;
26 
30 class ‪CObjectViewHelperTest extends ViewHelperBaseTestcase
31 {
35  protected ‪$resetSingletonInstances = true;
36 
40  protected ‪$viewHelper;
41 
45  protected ‪$configurationManager;
46 
50  protected ‪$contentObjectRenderer;
51 
55  protected function ‪setUp()
56  {
57  parent::setUp();
58  $this->viewHelper = new ‪CObjectViewHelper();
59  $this->injectDependenciesIntoViewHelper($this->viewHelper);
60 
61  $this->configurationManager = $this->prophesize(ConfigurationManagerInterface::class);
62  $this->contentObjectRenderer = $this->prophesize(ContentObjectRenderer::class);
63  }
64 
69  {
70  $this->‪stubBaseDependencies();
71 
72  $this->setArgumentsUnderTest(
73  $this->viewHelper,
74  [
75  'typoscriptObjectPath' => 'test',
76  'data' => 'foo',
77  ]
78  );
79  $configArray = [
80  'test' => 'TEXT',
81  'test.' => [],
82  ];
83  $this->configurationManager->getConfiguration(Argument::any())->willReturn($configArray);
84 
85  $this->contentObjectRenderer->start(['foo'], '')->willReturn();
86  $this->viewHelper->initializeArgumentsAndRender();
87  }
88 
93  {
94  $this->‪stubBaseDependencies();
95 
96  $this->viewHelper->setRenderChildrenClosure(
97  function () {
98  return 'foo';
99  }
100  );
101  $this->setArgumentsUnderTest(
102  $this->viewHelper,
103  [
104  'typoscriptObjectPath' => 'test',
105  ]
106  );
107  $configArray = [
108  'test' => 'TEXT',
109  'test.' => [],
110  ];
111  $this->configurationManager->getConfiguration(Argument::any())->willReturn($configArray);
112 
113  $this->contentObjectRenderer->start(['foo'], '')->willReturn();
114  $this->viewHelper->initializeArgumentsAndRender();
115  }
116 
118  {
119  return [
120  'Single path' => [
121  'test',
122  1540246570
123  ],
124  'Multi path' => [
125  'test.path',
126  1253191023
127  ],
128  ];
129  }
130 
135  public function ‪renderThrowsExceptionIfTypoScriptObjectPathDoesNotExist(string $objectPath, int $exceptionCode)
136  {
137  $this->‪stubBaseDependencies();
138  $this->contentObjectRenderer->start(Argument::cetera())->willReturn();
139 
140  $this->setArgumentsUnderTest(
141  $this->viewHelper,
142  [
143  'data' => 'foo',
144  'typoscriptObjectPath' => $objectPath,
145  ]
146  );
147 
148  $this->expectException(\‪TYPO3Fluid\Fluid\Core\ViewHelper\Exception::class);
149  $this->expectExceptionCode($exceptionCode);
150  $this->viewHelper->initializeArgumentsAndRender();
151  }
152 
154  {
155  $subConfigArray = [
156  'value' => 'Hello World',
157  'wrap' => 'ab | cd',
158  ];
159  return [
160  'Single path' => [
161  'test',
162  [
163  'test' => 'TEXT',
164  'test.' => $subConfigArray,
165  ],
166  $subConfigArray
167  ],
168  'Single path no config' => [
169  'test',
170  [
171  'test' => 'TEXT',
172  ],
173  []
174  ],
175  'Multi path' => [
176  'plugin.test',
177  [
178  'plugin.' => [
179  'test' => 'TEXT',
180  'test.' => $subConfigArray,
181  ]
182  ],
183  $subConfigArray
184  ],
185  'Multi path no config' => [
186  'plugin.test',
187  [
188  'plugin.' => [
189  'test' => 'TEXT',
190  ]
191  ],
192  []
193  ],
194  ];
195  }
196 
204  public function ‪renderReturnsSimpleTypoScriptValue(string $objectPath, array $configArray, array $subConfigArray)
205  {
206  $this->‪stubBaseDependencies();
207  $this->setArgumentsUnderTest(
208  $this->viewHelper,
209  [
210  'typoscriptObjectPath' => $objectPath,
211  'data' => 'foo',
212  'table' => 'table',
213  ]
214  );
215 
216  $this->configurationManager->getConfiguration(Argument::any())->willReturn($configArray);
217 
218  $this->contentObjectRenderer->start(['foo'], 'table')->willReturn();
219  $this->contentObjectRenderer->setCurrentVal('foo')->willReturn();
220  $this->contentObjectRenderer->cObjGetSingle('TEXT', $subConfigArray, Argument::any())->willReturn('Hello World');
221 
222  $objectManager = $this->prophesize(ObjectManager::class);
223  $objectManager->get(ConfigurationManagerInterface::class)->willReturn($this->configurationManager->reveal());
224  GeneralUtility::addInstance(ContentObjectRenderer::class, $this->contentObjectRenderer->reveal());
225  GeneralUtility::setSingletonInstance(ObjectManager::class, $objectManager->reveal());
226 
227  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
228  $expectedResult = 'Hello World';
229  $this->assertSame($expectedResult, $actualResult);
230  }
231 
235  protected function ‪stubBaseDependencies()
236  {
237  $this->configurationManager->getConfiguration(Argument::any())->willReturn([]);
238  $this->contentObjectRenderer->setCurrentVal(Argument::cetera())->willReturn();
239  $this->contentObjectRenderer->cObjGetSingle(Argument::cetera())->willReturn('');
240  $objectManager = $this->prophesize(ObjectManager::class);
241  $objectManager->get(ConfigurationManagerInterface::class)->willReturn($this->configurationManager->reveal());
242  GeneralUtility::setSingletonInstance(ObjectManager::class, $objectManager->reveal());
243  ‪$GLOBALS['TSFE'] = $this->getAccessibleMock(TypoScriptFrontendController::class, ['initCaches'], [], '', false);
244  }
245 }
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\CObjectViewHelperTest\stubBaseDependencies
‪stubBaseDependencies()
Definition: CObjectViewHelperTest.php:231
‪TYPO3Fluid
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\CObjectViewHelperTest\renderThrowsExceptionIfTypoScriptObjectPathDoesNotExistDataProvider
‪renderThrowsExceptionIfTypoScriptObjectPathDoesNotExistDataProvider()
Definition: CObjectViewHelperTest.php:113
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\CObjectViewHelperTest\viewHelperAcceptsChildrenClosureAsInput
‪viewHelperAcceptsChildrenClosureAsInput()
Definition: CObjectViewHelperTest.php:88
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
Definition: ConfigurationManagerInterface.php:22
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\CObjectViewHelperTest
Definition: CObjectViewHelperTest.php:31
‪TYPO3\CMS\Fluid\ViewHelpers\CObjectViewHelper
Definition: CObjectViewHelper.php:81
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\CObjectViewHelperTest\$contentObjectRenderer
‪ContentObjectRenderer $contentObjectRenderer
Definition: CObjectViewHelperTest.php:46
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\CObjectViewHelperTest\renderThrowsExceptionIfTypoScriptObjectPathDoesNotExist
‪renderThrowsExceptionIfTypoScriptObjectPathDoesNotExist(string $objectPath, int $exceptionCode)
Definition: CObjectViewHelperTest.php:131
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\CObjectViewHelperTest\setUp
‪setUp()
Definition: CObjectViewHelperTest.php:51
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\CObjectViewHelperTest\$configurationManager
‪ConfigurationManagerInterface $configurationManager
Definition: CObjectViewHelperTest.php:42
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\CObjectViewHelperTest\renderReturnsSimpleTypoScriptValue
‪renderReturnsSimpleTypoScriptValue(string $objectPath, array $configArray, array $subConfigArray)
Definition: CObjectViewHelperTest.php:200
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\CObjectViewHelperTest\renderReturnsSimpleTypoScriptValueDataProvider
‪renderReturnsSimpleTypoScriptValueDataProvider()
Definition: CObjectViewHelperTest.php:149
‪TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
Definition: TypoScriptFrontendController.php:97
‪$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:64
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
Definition: ContentObjectRenderer.php:91
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\CObjectViewHelperTest\$viewHelper
‪CObjectViewHelper $viewHelper
Definition: CObjectViewHelperTest.php:38
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers
Definition: BaseViewHelperTest.php:2
‪TYPO3\CMS\Extbase\Object\ObjectManager
Definition: ObjectManager.php:25
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\CObjectViewHelperTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: CObjectViewHelperTest.php:34