TYPO3 CMS  TYPO3_8-7
AbstractPluginTest.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  */
21 
25 class AbstractPluginTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
26 {
30  protected $abstractPlugin;
31 
35  protected $defaultPiVars;
36 
40  protected function setUp()
41  {
42  parent::setUp();
43 
44  // Allow objects until 100 levels deep when executing the stdWrap
45  $GLOBALS['TSFE'] = new \stdClass();
46  $GLOBALS['TSFE']->cObjectDepthCounter = 100;
47 
48  $this->abstractPlugin = new AbstractPlugin();
49  $contentObjectRenderer = new ContentObjectRenderer();
50  $contentObjectRenderer->setContentObjectClassMap([
51  'TEXT' => TextContentObject::class,
52  ]);
53  $this->abstractPlugin->cObj = $contentObjectRenderer;
54  $this->defaultPiVars = $this->abstractPlugin->piVars;
55  }
56 
63  {
64  return [
65  'stdWrap on conf, non-recursive, stdWrap 1 level deep' => [
66  [
67  'abc' => 'DEF',
68  'abc.' => [
69  'stdWrap.' => [
70  'wrap' => 'test | test'
71  ],
72  ],
73  ],
74  [
75  'abc' => 'testDEFtest',
76  'pointer' => '',
77  'mode' => '',
78  'sword' => '',
79  'sort' => '',
80  ],
81  ],
82  'stdWrap on conf, non-recursive, stdWrap 2 levels deep' => [
83  [
84  'xyz.' => [
85  'stdWrap.' => [
86  'cObject' => 'TEXT',
87  'cObject.' => [
88  'data' => 'date:U',
89  'strftime' => '%Y',
90  ],
91  ],
92  ],
93  ],
94  [
95  'xyz' => date('Y'),
96  'pointer' => '',
97  'mode' => '',
98  'sword' => '',
99  'sort' => '',
100  ],
101  ],
102  'stdWrap on conf, recursive' => [
103  [
104  'abc.' => [
105  'def' => 'DEF',
106  'def.' => [
107  'ghi' => '123',
108  'stdWrap.' => [
109  'wrap' => 'test | test'
110  ],
111  ],
112  ],
113  ],
114  [
115  'abc.' => [
116  'def' => 'testDEFtest',
117  'def.' => [
118  'ghi' => '123',
119  ],
120  ],
121  'pointer' => '',
122  'mode' => '',
123  'sword' => '',
124  'sort' => '',
125  ],
126  ],
127  ];
128  }
129 
134  public function piSetPiVarDefaultsStdWrap($input, $expected)
135  {
136  $this->abstractPlugin->piVars = $this->defaultPiVars;
137 
138  $this->abstractPlugin->conf['_DEFAULT_PI_VARS.'] = $input;
139  $this->abstractPlugin->pi_setPiVarDefaults();
140  $this->assertEquals($expected, $this->abstractPlugin->piVars);
141  }
142 
149  {
150  return [
151  'Result browser returning false' => [
152  'className' => $this->getUniqueId('tx_coretest'),
153  'returnValue' => false,
154  'expected' => ''
155  ],
156  'Result browser returning null' => [
157  'className' => $this->getUniqueId('tx_coretest'),
158  'returnValue' => null,
159  'expected' => ''
160  ],
161  'Result browser returning whitespace string' => [
162  'className' => $this->getUniqueId('tx_coretest'),
163  'returnValue' => ' ',
164  'expected' => ''
165  ],
166  'Result browser returning HTML' => [
167  'className' => $this->getUniqueId('tx_coretest'),
168  '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>',
169  '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>'
170  ],
171  'Result browser returning a truthy integer as string' => [
172  'className' => $this->getUniqueId('tx_coretest'),
173  'returnValue' => '1',
174  'expected' => '1'
175  ],
176  'Result browser returning a falsy integer' => [
177  'className' => $this->getUniqueId('tx_coretest'),
178  'returnValue' => 0,
179  'expected' => ''
180  ],
181  'Result browser returning a truthy integer' => [
182  'className' => $this->getUniqueId('tx_coretest'),
183  'returnValue' => 1,
184  'expected' => ''
185  ],
186  'Result browser returning a positive integer' => [
187  'className' => $this->getUniqueId('tx_coretest'),
188  'returnValue' => 42,
189  'expected' => ''
190  ]
191  ];
192  }
193 
202  public function registeredResultBrowsersAreUsed($className, $returnValue, $expected)
203  {
204  $resultBrowserHook = $this->getMockBuilder(ResultBrowserPluginHook::class)
205  ->setMockClassName($className)
206  ->setMethods(['pi_list_browseresults'])
207  ->disableOriginalConstructor()
208  ->getMock();
209 
210  // Register hook mock object
211  GeneralUtility::addInstance($className, $resultBrowserHook);
212  $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][AbstractPlugin::class]['pi_list_browseresults'] = [$className];
213 
214  $resultBrowserHook->expects($this->atLeastOnce())
215  ->method('pi_list_browseresults')
216  ->with(1, '', [], 'pointer', true, false, $this->abstractPlugin)
217  ->will($this->returnValue($returnValue));
218 
219  $actualReturnValue = $this->abstractPlugin->pi_list_browseresults();
220 
221  $this->assertSame($expected, $actualReturnValue);
222 
223  unset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][AbstractPlugin::class]['pi_list_browseresults']);
224  }
225 }
static addInstance($className, $instance)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
registeredResultBrowsersAreUsed($className, $returnValue, $expected)