TYPO3 CMS  TYPO3_7-6
PageRepositoryTest.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  */
16 
21 {
25  protected $pageSelectObject;
26 
27  protected $defaultTcaForPages = [
28  'ctrl' => [
29  'label' => 'title',
30  'tstamp' => 'tstamp',
31  'sortby' => 'sorting',
32  'type' => 'doktype',
33  'versioningWS' => true,
34  'origUid' => 't3_origuid',
35  'delete' => 'deleted',
36  'enablecolumns' => [
37  'disabled' => 'hidden',
38  'starttime' => 'starttime',
39  'endtime' => 'endtime',
40  'fe_group' => 'fe_group'
41  ],
42  ],
43  'columns' => []
44  ];
45 
49  protected function setUp()
50  {
51  $GLOBALS['TYPO3_DB'] = $this->getMock(\TYPO3\CMS\Core\Database\DatabaseConnection::class, ['exec_SELECTquery', 'sql_fetch_assoc', 'sql_free_result', 'exec_SELECTgetSingleRow']);
52  $this->pageSelectObject = $this->getAccessibleMock(\TYPO3\CMS\Frontend\Page\PageRepository::class, ['getMultipleGroupsWhereClause']);
53  $this->pageSelectObject->expects($this->any())->method('getMultipleGroupsWhereClause')->will($this->returnValue(' AND 1=1'));
54  }
55 
61  public function isGetPageHookCalled()
62  {
63  // Create a hook mock object
64  $className = $this->getUniqueId('tx_coretest');
65  $getPageHookMock = $this->getMock(\TYPO3\CMS\Frontend\Page\PageRepositoryGetPageHookInterface::class, ['getPage_preProcess'], [], $className);
66  // Register hook mock object
67  $GLOBALS['T3_VAR']['getUserObj'][$className] = $getPageHookMock;
68  $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_page.php']['getPage'][] = $className;
69  // Test if hook is called and register a callback method to check given arguments
70  $getPageHookMock->expects($this->once())->method('getPage_preProcess')->will($this->returnCallback([$this, 'isGetPagePreProcessCalledCallback']));
71  $this->pageSelectObject->getPage(42, false);
72  }
73 
78  {
79  list($uid, $disableGroupAccessCheck, $parent) = func_get_args();
80  $this->assertEquals(42, $uid);
81  $this->assertFalse($disableGroupAccessCheck);
82  $this->assertTrue($parent instanceof \TYPO3\CMS\Frontend\Page\PageRepository);
83  }
84 
86  // Tests concerning getPathFromRootline
88 
92  {
93  $this->assertEquals('', $this->pageSelectObject->getPathFromRootline([]));
94  }
95 
97  // Tests concerning getExtURL
99 
103  {
104  $this->assertEquals('http://www.example.com', $this->pageSelectObject->getExtURL([
105  'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_LINK,
106  'urltype' => 1,
107  'url' => 'www.example.com'
108  ]));
109  }
110 
115  {
116  $this->assertEquals(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . 'hello/world/', $this->pageSelectObject->getExtURL([
117  'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_LINK,
118  'urltype' => 0,
119  'url' => 'hello/world/'
120  ]));
121  }
122 
124  // Tests concerning shouldFieldBeOverlaid
126 
130  public function shouldFieldBeOverlaid($field, $table, $value, $expected, $comment = '')
131  {
132  $GLOBALS['TCA']['fake_table']['columns'] = [
133  'exclude' => [
134  'l10n_mode' => 'exclude',
135  'config' => ['type' => 'input'],
136  ],
137  'mergeIfNotBlank' => [
138  'l10n_mode' => 'mergeIfNotBlank',
139  'config' => ['type' => 'input'],
140  ],
141  'mergeIfNotBlank_group' => [
142  'l10n_mode' => 'mergeIfNotBlank',
143  'config' => ['type' => 'group'],
144  ],
145  'default' => [
146  // no l10n_mode set
147  'config' => ['type' => 'input'],
148  ],
149  'noCopy' => [
150  'l10n_mode' => 'noCopy',
151  'config' => ['type' => 'input'],
152  ],
153  'prefixLangTitle' => [
154  'l10n_mode' => 'prefixLangTitle',
155  'config' => ['type' => 'input'],
156  ],
157  ];
158 
159  $result = $this->pageSelectObject->_call('shouldFieldBeOverlaid', $table, $field, $value);
160  unset($GLOBALS['TCA']['fake_table']);
161 
162  $this->assertSame($expected, $result, $comment);
163  }
164 
169  {
170  return [
171  ['default', 'fake_table', 'foobar', true, 'default is to merge non-empty string'],
172  ['default', 'fake_table', '', true, 'default is to merge empty string'],
173 
174  ['exclude', 'fake_table', '', false, 'exclude field with empty string'],
175  ['exclude', 'fake_table', 'foobar', false, 'exclude field with non-empty string'],
176 
177  ['mergeIfNotBlank', 'fake_table', '', false, 'mergeIfNotBlank is not merged with empty string'],
178  ['mergeIfNotBlank', 'fake_table', 0, true, 'mergeIfNotBlank is merged with 0'],
179  ['mergeIfNotBlank', 'fake_table', '0', true, 'mergeIfNotBlank is merged with "0"'],
180  ['mergeIfNotBlank', 'fake_table', 'foobar', true, 'mergeIfNotBlank is merged with non-empty string'],
181 
182  ['mergeIfNotBlank_group', 'fake_table', '', false, 'mergeIfNotBlank on group is not merged empty string'],
183  ['mergeIfNotBlank_group', 'fake_table', 0, false, 'mergeIfNotBlank on group is not merged with 0'],
184  ['mergeIfNotBlank_group', 'fake_table', '0', false, 'mergeIfNotBlank on group is not merged with "0"'],
185  ['mergeIfNotBlank_group', 'fake_table', 'foobar', true, 'mergeIfNotBlank on group is merged with non-empty string'],
186 
187  ['noCopy', 'fake_table', 'foobar', true, 'noCopy is merged with non-empty string'],
188  ['noCopy', 'fake_table', '', true, 'noCopy is merged with empty string'],
189 
190  ['prefixLangTitle', 'fake_table', 'foobar', true, 'prefixLangTitle is merged with non-empty string'],
191  ['prefixLangTitle', 'fake_table', '', true, 'prefixLangTitle is merged with empty string'],
192  ];
193  }
194 
196  // Tests concerning workspaces
198 
203  {
204  // initialization
205  $wsid = 987654321;
206  $GLOBALS['TCA'] = [
207  'pages' => $this->defaultTcaForPages
208  ];
209 
210  // simulate calls from \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController->fetch_the_id()
211  $this->pageSelectObject->versioningPreview = false;
212  $this->pageSelectObject->versioningWorkspaceId = $wsid;
213  $this->pageSelectObject->init(false);
214 
215  // check SQL created by \TYPO3\CMS\Frontend\Page\PageRepository->getPage()
216  $GLOBALS['TYPO3_DB']->expects($this->once())
217  ->method('exec_SELECTgetSingleRow')
218  ->with(
219  '*',
220  'pages',
221  $this->logicalAnd(
222  $this->logicalNot(
223  $this->stringContains('(pages.t3ver_wsid=0 or pages.t3ver_wsid=' . $wsid . ')')
224  ),
225  $this->stringContains('AND pages.t3ver_state<=0')
226  )
227  );
228 
229  $this->pageSelectObject->getPage(1);
230  }
231 
236  {
237  // initialization
238  $wsid = 987654321;
239  $GLOBALS['TCA'] = [
240  'pages' => $this->defaultTcaForPages
241  ];
242 
243  // simulate calls from \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController->fetch_the_id()
244  $this->pageSelectObject->versioningPreview = true;
245  $this->pageSelectObject->versioningWorkspaceId = $wsid;
246  $this->pageSelectObject->init(false);
247 
248  // check SQL created by \TYPO3\CMS\Frontend\Page\PageRepository->getPage()
249  $GLOBALS['TYPO3_DB']->expects($this->once())
250  ->method('exec_SELECTgetSingleRow')
251  ->with(
252  '*',
253  'pages',
254  $this->stringContains('(pages.t3ver_wsid=0 or pages.t3ver_wsid=' . $wsid . ')')
255  );
256 
257  $this->pageSelectObject->getPage(1);
258  }
259 
261  // Tests concerning versioning
263 
268  {
269  $table = $this->getUniqueId('aTable');
270  $GLOBALS['TCA'] = [
271  'pages' => $this->defaultTcaForPages,
272  $table => [
273  'ctrl' => [
274  'versioningWS' => true
275  ]
276  ]
277  ];
278 
279  $this->pageSelectObject->versioningPreview = false;
280  $this->pageSelectObject->init(false);
281 
282  $conditions = $this->pageSelectObject->enableFields($table);
283 
284  $this->assertThat($conditions, $this->stringContains(' AND ' . $table . '.t3ver_state<=0'), 'Versioning placeholders');
285  $this->assertThat($conditions, $this->stringContains(' AND ' . $table . '.pid<>-1'), 'Records from page -1');
286  }
287 
292  {
293  $table = $this->getUniqueId('aTable');
294  $GLOBALS['TCA'] = [
295  'pages' => $this->defaultTcaForPages,
296  $table => [
297  'ctrl' => [
298  'versioningWS' => true
299  ]
300  ]
301  ];
302 
303  $this->pageSelectObject->versioningPreview = true;
304  $this->pageSelectObject->init(false);
305 
306  $conditions = $this->pageSelectObject->enableFields($table);
307 
308  $this->assertThat($conditions, $this->logicalNot($this->stringContains(' AND ' . $table . '.t3ver_state<=0')), 'No versioning placeholders');
309  $this->assertThat($conditions, $this->stringContains(' AND ' . $table . '.pid<>-1'), 'Records from page -1');
310  }
311 
316  {
317  $table = $this->getUniqueId('aTable');
318  $GLOBALS['TCA'] = [
319  'pages' => $this->defaultTcaForPages,
320  $table => [
321  'ctrl' => [
322  'versioningWS' => true
323  ]
324  ]
325  ];
326 
327  $this->pageSelectObject->versioningPreview = true;
328  $this->pageSelectObject->versioningWorkspaceId = 2;
329  $this->pageSelectObject->init(false);
330 
331  $conditions = $this->pageSelectObject->enableFields($table);
332 
333  $this->assertThat($conditions, $this->stringContains(' AND (' . $table . '.t3ver_wsid=0 OR ' . $table . '.t3ver_wsid=2)'), 'No versioning placeholders');
334  }
335 
340  {
341  $table = $this->getUniqueId('aTable');
342  $GLOBALS['TCA'] = [
343  'pages' => $this->defaultTcaForPages,
344  $table => [
345  'ctrl' => [
346  'versioningWS' => true
347  ]
348  ]
349  ];
350 
351  $this->pageSelectObject->versioningPreview = true;
352  $this->pageSelectObject->init(false);
353 
354  $conditions = $this->pageSelectObject->enableFields($table, -1, [], true);
355 
356  $this->assertThat($conditions, $this->logicalNot($this->stringContains(' AND ' . $table . '.t3ver_state<=0')), 'No versioning placeholders');
357  $this->assertThat($conditions, $this->logicalNot($this->stringContains(' AND ' . $table . '.pid<>-1')), 'No ecords from page -1');
358  }
359 }
shouldFieldBeOverlaid($field, $table, $value, $expected, $comment='')
getAccessibleMock( $originalClassName, $methods=[], array $arguments=[], $mockClassName='', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)
$uid
Definition: server.php:38
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']