‪TYPO3CMS  10.4
AbstractPluginTest.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;
29 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
30 
34 class ‪AbstractPluginTest extends UnitTestCase
35 {
39  protected ‪$abstractPlugin;
40 
44  protected ‪$resetSingletonInstances = true;
45 
49  protected function ‪setUp(): void
50  {
51  parent::setUp();
52 
53  $tsfe = $this->prophesize(TypoScriptFrontendController::class);
54  $tsfe->cObjectDepthCounter = 100;
55  $tsfe->getLanguage(Argument::cetera())->willReturn(
56  $this->‪createSiteWithDefaultLanguage()->getLanguageById(0)
57  );
58 
59  $this->abstractPlugin = new ‪AbstractPlugin(null, $tsfe->reveal());
60  $contentObjectRenderer = new ‪ContentObjectRenderer($tsfe->reveal());
61  $contentObjectRenderer->setContentObjectClassMap([
62  'TEXT' => TextContentObject::class,
63  ]);
64  $this->abstractPlugin->cObj = $contentObjectRenderer;
65  }
66 
72  public function ‪piSetPiVarDefaultsStdWrapProvider()
73  {
74  return [
75  'stdWrap on conf, non-recursive, stdWrap 1 level deep' => [
76  [
77  'abc' => 'DEF',
78  'abc.' => [
79  'stdWrap.' => [
80  'wrap' => 'test | test'
81  ],
82  ],
83  'simplevalue' => 'lipsum'
84  ],
85  [
86  'abc' => 'testDEFtest',
87  'simplevalue' => 'lipsum',
88  'pointer' => '',
89  'mode' => '',
90  'sword' => '',
91  'sort' => '',
92  'a' => [
93  'bit' => 'nested'
94  ]
95  ],
96  ],
97  'stdWrap on conf, non-recursive, stdWrap 2 levels deep' => [
98  [
99  'xyz.' => [
100  'stdWrap.' => [
101  'cObject' => 'TEXT',
102  'cObject.' => [
103  'data' => 'date:U',
104  'strftime' => '%Y',
105  ],
106  ],
107  ],
108  ],
109  [
110  'xyz' => date('Y'),
111  'pointer' => '',
112  'mode' => '',
113  'sword' => '',
114  'sort' => '',
115  'a' => [
116  'bit' => 'nested'
117  ]
118  ],
119  ],
120  'stdWrap on conf, recursive' => [
121  [
122  'abc.' => [
123  'def' => 'DEF',
124  'def.' => [
125  'ghi' => '123',
126  'stdWrap.' => [
127  'wrap' => 'test | test'
128  ],
129  ],
130  ],
131  'simple_value' => '45'
132  ],
133  [
134  'abc' => [
135  'def' => [
136  'ghi' => '123',
137  ],
138  ],
139  'simple_value' => '45',
140  'pointer' => '',
141  'mode' => '',
142  'sword' => '',
143  'sort' => '',
144  'a' => [
145  'bit' => 'nested'
146  ]
147  ],
148  ],
149  'stdWrap on conf, recursive, default pivars get overridden recursive nested set' => [
150  [
151  'abc.' => [
152  'def' => 'DEF',
153  'def.' => [
154  'ghi' => '123',
155  'stdWrap.' => [
156  'wrap' => 'test | test'
157  ],
158  ],
159  ],
160  'a' => [
161  'default-is' => 'uncool'
162  ],
163  'simple_value' => '45'
164  ],
165  [
166  'abc' => [
167  'def' => [
168  'ghi' => '123',
169  ],
170  ],
171  'simple_value' => '45',
172  'pointer' => '',
173  'mode' => '',
174  'sword' => '',
175  'sort' => '',
176  'a' => [
177  'default-is' => 'uncool',
178  'bit' => 'nested'
179  ]
180  ],
181  ],
182  ];
183  }
184 
189  public function ‪piSetPiVarDefaultsStdWrap($input, $expected)
190  {
191  $this->resetSingletonInstances = true;
192  $this->abstractPlugin->piVars['a']['bit'] = 'nested';
193 
194  $this->abstractPlugin->conf['_DEFAULT_PI_VARS.'] = $input;
195  $this->abstractPlugin->pi_setPiVarDefaults();
196  self::assertEquals($expected, $this->abstractPlugin->piVars);
197  }
198 
204  public function ‪registeredResultBrowserProvider()
205  {
206  return [
207  'Result browser returning false' => [
208  'className' => ‪StringUtility::getUniqueId('tx_coretest'),
209  'returnValue' => false,
210  'expected' => ''
211  ],
212  'Result browser returning null' => [
213  'className' => ‪StringUtility::getUniqueId('tx_coretest'),
214  'returnValue' => null,
215  'expected' => ''
216  ],
217  'Result browser returning whitespace string' => [
218  'className' => ‪StringUtility::getUniqueId('tx_coretest'),
219  'returnValue' => ' ',
220  'expected' => ''
221  ],
222  'Result browser returning HTML' => [
223  'className' => ‪StringUtility::getUniqueId('tx_coretest'),
224  'returnValue' => '<div><a href="index.php?id=1&pointer=1">1</a><a href="index.php?id=1&pointer=2">2</a><a href="index.php?id=1&pointer=3">3</a><a href="index.php?id=1&pointer=4">4</a></div>',
225  'expected' => '<div><a href="index.php?id=1&pointer=1">1</a><a href="index.php?id=1&pointer=2">2</a><a href="index.php?id=1&pointer=3">3</a><a href="index.php?id=1&pointer=4">4</a></div>'
226  ],
227  'Result browser returning a truthy integer as string' => [
228  'className' => ‪StringUtility::getUniqueId('tx_coretest'),
229  'returnValue' => '1',
230  'expected' => '1'
231  ],
232  'Result browser returning a falsy integer' => [
233  'className' => ‪StringUtility::getUniqueId('tx_coretest'),
234  'returnValue' => 0,
235  'expected' => ''
236  ],
237  'Result browser returning a truthy integer' => [
238  'className' => ‪StringUtility::getUniqueId('tx_coretest'),
239  'returnValue' => 1,
240  'expected' => ''
241  ],
242  'Result browser returning a positive integer' => [
243  'className' => ‪StringUtility::getUniqueId('tx_coretest'),
244  'returnValue' => 42,
245  'expected' => ''
246  ]
247  ];
248  }
249 
258  public function ‪registeredResultBrowsersAreUsed($className, $returnValue, $expected)
259  {
260  $resultBrowserHook = $this->getMockBuilder(ResultBrowserPluginHook::class)
261  ->setMockClassName($className)
262  ->setMethods(['pi_list_browseresults'])
263  ->disableOriginalConstructor()
264  ->getMock();
265 
266  // Register hook mock object
267  GeneralUtility::addInstance($className, $resultBrowserHook);
268  ‪$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][AbstractPlugin::class]['pi_list_browseresults'] = [$className];
269 
270  $resultBrowserHook->expects(self::atLeastOnce())
271  ->method('pi_list_browseresults')
272  ->with(1, '', [], 'pointer', true, false, $this->abstractPlugin)
273  ->willReturn($returnValue);
274 
275  $actualReturnValue = $this->abstractPlugin->pi_list_browseresults();
276 
277  self::assertSame($expected, $actualReturnValue);
278 
279  unset(‪$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][AbstractPlugin::class]['pi_list_browseresults']);
280  }
281 
282  private function ‪createSiteWithDefaultLanguage(): ‪Site
283  {
284  return new ‪Site('test', 1, [
285  'identifier' => 'test',
286  'rootPageId' => 1,
287  'base' => '/',
288  'languages' => [
289  [
290  'base' => '/',
291  'languageId' => 0,
292  'locale' => 'en_US',
293  'typo3Language' => 'en'
294  ],
295  ]
296  ]);
297  }
298 }
‪TYPO3\CMS\Frontend\Tests\Unit\Fixtures\ResultBrowserPluginHook
Definition: ResultBrowserPluginHook.php:24
‪TYPO3\CMS\Frontend\Tests\Unit\Plugin\AbstractPluginTest\piSetPiVarDefaultsStdWrap
‪piSetPiVarDefaultsStdWrap($input, $expected)
Definition: AbstractPluginTest.php:187
‪TYPO3\CMS\Frontend\Plugin\AbstractPlugin
Definition: AbstractPlugin.php:42
‪TYPO3\CMS\Core\Site\Entity\Site
Definition: Site.php:40
‪TYPO3\CMS\Frontend\Tests\Unit\Plugin\AbstractPluginTest\$abstractPlugin
‪AbstractPlugin $abstractPlugin
Definition: AbstractPluginTest.php:38
‪TYPO3\CMS\Frontend\Tests\Unit\Plugin\AbstractPluginTest\setUp
‪setUp()
Definition: AbstractPluginTest.php:47
‪TYPO3\CMS\Frontend\Tests\Unit\Plugin\AbstractPluginTest\registeredResultBrowsersAreUsed
‪registeredResultBrowsersAreUsed($className, $returnValue, $expected)
Definition: AbstractPluginTest.php:256
‪TYPO3\CMS\Frontend\Tests\Unit\Plugin\AbstractPluginTest\piSetPiVarDefaultsStdWrapProvider
‪array piSetPiVarDefaultsStdWrapProvider()
Definition: AbstractPluginTest.php:70
‪TYPO3\CMS\Core\Utility\StringUtility\getUniqueId
‪static string getUniqueId($prefix='')
Definition: StringUtility.php:92
‪TYPO3\CMS\Frontend\Tests\Unit\Plugin\AbstractPluginTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: AbstractPluginTest.php:42
‪TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
Definition: TypoScriptFrontendController.php:98
‪TYPO3\CMS\Frontend\Tests\Unit\Plugin\AbstractPluginTest\createSiteWithDefaultLanguage
‪createSiteWithDefaultLanguage()
Definition: AbstractPluginTest.php:280
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
Definition: ContentObjectRenderer.php:97
‪TYPO3\CMS\Frontend\Tests\Unit\Plugin
Definition: AbstractPluginTest.php:18
‪TYPO3\CMS\Frontend\Tests\Unit\Plugin\AbstractPluginTest
Definition: AbstractPluginTest.php:35
‪TYPO3\CMS\Frontend\ContentObject\TextContentObject
Definition: TextContentObject.php:22
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Utility\StringUtility
Definition: StringUtility.php:22
‪TYPO3\CMS\Frontend\Tests\Unit\Plugin\AbstractPluginTest\registeredResultBrowserProvider
‪array registeredResultBrowserProvider()
Definition: AbstractPluginTest.php:202