‪TYPO3CMS  9.5
AbstractPluginTest.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  */
22 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
23 
27 class ‪AbstractPluginTest extends UnitTestCase
28 {
32  protected ‪$abstractPlugin;
33 
37  protected ‪$defaultPiVars;
38 
42  protected ‪$resetSingletonInstances = true;
43 
47  protected function ‪setUp()
48  {
49  parent::setUp();
50 
51  // Allow objects until 100 levels deep when executing the stdWrap
52  ‪$GLOBALS['TSFE'] = new \stdClass();
53  ‪$GLOBALS['TSFE']->cObjectDepthCounter = 100;
54 
55  $this->abstractPlugin = new ‪AbstractPlugin();
56  $contentObjectRenderer = new ‪ContentObjectRenderer();
57  $contentObjectRenderer->setContentObjectClassMap([
58  'TEXT' => TextContentObject::class,
59  ]);
60  $this->abstractPlugin->cObj = $contentObjectRenderer;
61  $this->defaultPiVars = $this->abstractPlugin->piVars;
62  }
63 
69  public function ‪piSetPiVarDefaultsStdWrapProvider()
70  {
71  return [
72  'stdWrap on conf, non-recursive, stdWrap 1 level deep' => [
73  [
74  'abc' => 'DEF',
75  'abc.' => [
76  'stdWrap.' => [
77  'wrap' => 'test | test'
78  ],
79  ],
80  ],
81  [
82  'abc' => 'testDEFtest',
83  'pointer' => '',
84  'mode' => '',
85  'sword' => '',
86  'sort' => '',
87  ],
88  ],
89  'stdWrap on conf, non-recursive, stdWrap 2 levels deep' => [
90  [
91  'xyz.' => [
92  'stdWrap.' => [
93  'cObject' => 'TEXT',
94  'cObject.' => [
95  'data' => 'date:U',
96  'strftime' => '%Y',
97  ],
98  ],
99  ],
100  ],
101  [
102  'xyz' => date('Y'),
103  'pointer' => '',
104  'mode' => '',
105  'sword' => '',
106  'sort' => '',
107  ],
108  ],
109  'stdWrap on conf, recursive' => [
110  [
111  'abc.' => [
112  'def' => 'DEF',
113  'def.' => [
114  'ghi' => '123',
115  'stdWrap.' => [
116  'wrap' => 'test | test'
117  ],
118  ],
119  ],
120  ],
121  [
122  'abc.' => [
123  'def' => 'testDEFtest',
124  'def.' => [
125  'ghi' => '123',
126  ],
127  ],
128  'pointer' => '',
129  'mode' => '',
130  'sword' => '',
131  'sort' => '',
132  ],
133  ],
134  ];
135  }
136 
141  public function ‪piSetPiVarDefaultsStdWrap($input, $expected)
142  {
143  $this->resetSingletonInstances = true;
144  $this->abstractPlugin->piVars = ‪$this->defaultPiVars;
145 
146  $this->abstractPlugin->conf['_DEFAULT_PI_VARS.'] = $input;
147  $this->abstractPlugin->pi_setPiVarDefaults();
148  $this->assertEquals($expected, $this->abstractPlugin->piVars);
149  }
150 
156  public function ‪registeredResultBrowserProvider()
157  {
158  return [
159  'Result browser returning false' => [
160  'className' => $this->getUniqueId('tx_coretest'),
161  'returnValue' => false,
162  'expected' => ''
163  ],
164  'Result browser returning null' => [
165  'className' => $this->getUniqueId('tx_coretest'),
166  'returnValue' => null,
167  'expected' => ''
168  ],
169  'Result browser returning whitespace string' => [
170  'className' => $this->getUniqueId('tx_coretest'),
171  'returnValue' => ' ',
172  'expected' => ''
173  ],
174  'Result browser returning HTML' => [
175  'className' => $this->getUniqueId('tx_coretest'),
176  '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>',
177  '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>'
178  ],
179  'Result browser returning a truthy integer as string' => [
180  'className' => $this->getUniqueId('tx_coretest'),
181  'returnValue' => '1',
182  'expected' => '1'
183  ],
184  'Result browser returning a falsy integer' => [
185  'className' => $this->getUniqueId('tx_coretest'),
186  'returnValue' => 0,
187  'expected' => ''
188  ],
189  'Result browser returning a truthy integer' => [
190  'className' => $this->getUniqueId('tx_coretest'),
191  'returnValue' => 1,
192  'expected' => ''
193  ],
194  'Result browser returning a positive integer' => [
195  'className' => $this->getUniqueId('tx_coretest'),
196  'returnValue' => 42,
197  'expected' => ''
198  ]
199  ];
200  }
201 
210  public function ‪registeredResultBrowsersAreUsed($className, $returnValue, $expected)
211  {
212  $resultBrowserHook = $this->getMockBuilder(ResultBrowserPluginHook::class)
213  ->setMockClassName($className)
214  ->setMethods(['pi_list_browseresults'])
215  ->disableOriginalConstructor()
216  ->getMock();
217 
218  // Register hook mock object
219  GeneralUtility::addInstance($className, $resultBrowserHook);
220  ‪$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][AbstractPlugin::class]['pi_list_browseresults'] = [$className];
221 
222  $resultBrowserHook->expects($this->atLeastOnce())
223  ->method('pi_list_browseresults')
224  ->with(1, '', [], 'pointer', true, false, $this->abstractPlugin)
225  ->will($this->returnValue($returnValue));
226 
227  $actualReturnValue = $this->abstractPlugin->pi_list_browseresults();
228 
229  $this->assertSame($expected, $actualReturnValue);
230 
231  unset(‪$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][AbstractPlugin::class]['pi_list_browseresults']);
232  }
233 }
‪TYPO3\CMS\Frontend\Tests\Unit\Fixtures\ResultBrowserPluginHook
Definition: ResultBrowserPluginHook.php:22
‪TYPO3\CMS\Frontend\Tests\Unit\Plugin\AbstractPluginTest\piSetPiVarDefaultsStdWrap
‪piSetPiVarDefaultsStdWrap($input, $expected)
Definition: AbstractPluginTest.php:138
‪TYPO3\CMS\Frontend\Plugin\AbstractPlugin
Definition: AbstractPlugin.php:42
‪TYPO3\CMS\Frontend\Tests\Unit\Plugin\AbstractPluginTest\$abstractPlugin
‪AbstractPlugin $abstractPlugin
Definition: AbstractPluginTest.php:31
‪TYPO3\CMS\Frontend\Tests\Unit\Plugin\AbstractPluginTest\setUp
‪setUp()
Definition: AbstractPluginTest.php:44
‪TYPO3\CMS\Frontend\Tests\Unit\Plugin\AbstractPluginTest\registeredResultBrowsersAreUsed
‪registeredResultBrowsersAreUsed($className, $returnValue, $expected)
Definition: AbstractPluginTest.php:207
‪TYPO3\CMS\Frontend\Tests\Unit\Plugin\AbstractPluginTest\piSetPiVarDefaultsStdWrapProvider
‪array piSetPiVarDefaultsStdWrapProvider()
Definition: AbstractPluginTest.php:66
‪TYPO3\CMS\Frontend\Tests\Unit\Plugin\AbstractPluginTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: AbstractPluginTest.php:39
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
Definition: ContentObjectRenderer.php:91
‪TYPO3\CMS\Frontend\Tests\Unit\Plugin
Definition: AbstractPluginTest.php:3
‪TYPO3\CMS\Frontend\Tests\Unit\Plugin\AbstractPluginTest
Definition: AbstractPluginTest.php:28
‪TYPO3\CMS\Frontend\ContentObject\TextContentObject
Definition: TextContentObject.php:21
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Frontend\Tests\Unit\Plugin\AbstractPluginTest\registeredResultBrowserProvider
‪array registeredResultBrowserProvider()
Definition: AbstractPluginTest.php:153
‪TYPO3\CMS\Frontend\Tests\Unit\Plugin\AbstractPluginTest\$defaultPiVars
‪array $defaultPiVars
Definition: AbstractPluginTest.php:35