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