2 namespace TYPO3\CMS\Frontend\Tests\Unit\Page
;
5 * This file is part of the TYPO3 CMS project.
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.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
16 use TYPO3\CMS\Core\Utility\GeneralUtility
;
21 class PageRepositoryTest
extends \TYPO3\CMS\Core\Tests\UnitTestCase
24 * @var \TYPO3\CMS\Frontend\Page\PageRepository|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface
26 protected $pageSelectObject;
28 protected $defaultTcaForPages = array(
32 'sortby' => 'sorting',
34 'versioningWS' => true,
35 'origUid' => 't3_origuid',
36 'delete' => 'deleted',
37 'enablecolumns' => array(
38 'disabled' => 'hidden',
39 'starttime' => 'starttime',
40 'endtime' => 'endtime',
41 'fe_group' => 'fe_group'
48 * Sets up this testcase
50 protected function setUp()
52 $GLOBALS['TYPO3_DB'] = $this->getMock(\TYPO3\CMS\Core\Database\DatabaseConnection
::class, array('exec_SELECTquery', 'sql_fetch_assoc', 'sql_free_result', 'exec_SELECTgetSingleRow'));
53 $this->pageSelectObject
= $this->getAccessibleMock(\TYPO3\CMS\Frontend\Page\PageRepository
::class, array('getMultipleGroupsWhereClause'));
54 $this->pageSelectObject
->expects($this->any())->method('getMultipleGroupsWhereClause')->will($this->returnValue(' AND 1=1'));
58 * Tests whether the getPage Hook is called correctly.
62 public function isGetPageHookCalled()
64 // Create a hook mock object
65 $className = $this->getUniqueId('tx_coretest');
66 $getPageHookMock = $this->getMock(\TYPO3\CMS\Frontend\Page\PageRepositoryGetPageHookInterface
::class, array('getPage_preProcess'), array(), $className);
67 // Register hook mock object
68 GeneralUtility
::addInstance($className, $getPageHookMock);
69 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_page.php']['getPage'][] = $className;
70 // Test if hook is called and register a callback method to check given arguments
71 $getPageHookMock->expects($this->once())->method('getPage_preProcess')->will($this->returnCallback(array($this, 'isGetPagePreProcessCalledCallback')));
72 $this->pageSelectObject
->getPage(42, false);
76 * Handles the arguments that have been sent to the getPage_preProcess hook
79 * @param $disableGroupAccessCheck
80 * @param \TYPO3\CMS\Frontend\Page\PageRepository $parent
82 public function isGetPagePreProcessCalledCallback($uid, $disableGroupAccessCheck, $parent)
84 $this->assertEquals(42, $uid);
85 $this->assertFalse($disableGroupAccessCheck);
86 $this->assertTrue($parent instanceof \TYPO3\CMS\Frontend\Page\PageRepository
);
89 /////////////////////////////////////////
90 // Tests concerning getPathFromRootline
91 /////////////////////////////////////////
95 public function getPathFromRootLineForEmptyRootLineReturnsEmptyString()
97 $this->assertEquals('', $this->pageSelectObject
->getPathFromRootline(array()));
100 ///////////////////////////////
101 // Tests concerning getExtURL
102 ///////////////////////////////
106 public function getExtUrlForDokType3AndUrlType1AddsHttpSchemeToUrl()
108 $this->assertEquals('http://www.example.com', $this->pageSelectObject
->getExtURL(array(
109 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository
::DOKTYPE_LINK
,
111 'url' => 'www.example.com'
118 public function getExtUrlForDokType3AndUrlType0PrependsSiteUrl()
120 $this->assertEquals(\TYPO3\CMS\Core\Utility\GeneralUtility
::getIndpEnv('TYPO3_SITE_URL') . 'hello/world/', $this->pageSelectObject
->getExtURL(array(
121 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository
::DOKTYPE_LINK
,
123 'url' => 'hello/world/'
127 /////////////////////////////////////////
128 // Tests concerning shouldFieldBeOverlaid
129 /////////////////////////////////////////
132 * @dataProvider getShouldFieldBeOverlaidData
134 public function shouldFieldBeOverlaid($field, $table, $value, $expected, $comment = '')
136 $GLOBALS['TCA']['fake_table']['columns'] = array(
138 'l10n_mode' => 'exclude',
139 'config' => array('type' => 'input'),
141 'mergeIfNotBlank' => array(
142 'l10n_mode' => 'mergeIfNotBlank',
143 'config' => array('type' => 'input'),
145 'mergeIfNotBlank_group' => array(
146 'l10n_mode' => 'mergeIfNotBlank',
147 'config' => array('type' => 'group'),
151 'config' => array('type' => 'input'),
154 'l10n_mode' => 'noCopy',
155 'config' => array('type' => 'input'),
157 'prefixLangTitle' => array(
158 'l10n_mode' => 'prefixLangTitle',
159 'config' => array('type' => 'input'),
163 $result = $this->pageSelectObject
->_call('shouldFieldBeOverlaid', $table, $field, $value);
164 unset($GLOBALS['TCA']['fake_table']);
166 $this->assertSame($expected, $result, $comment);
170 * Data provider for shouldFieldBeOverlaid
172 public function getShouldFieldBeOverlaidData()
175 array('default', 'fake_table', 'foobar', true, 'default is to merge non-empty string'),
176 array('default', 'fake_table', '', true, 'default is to merge empty string'),
178 array('exclude', 'fake_table', '', false, 'exclude field with empty string'),
179 array('exclude', 'fake_table', 'foobar', false, 'exclude field with non-empty string'),
181 array('mergeIfNotBlank', 'fake_table', '', false, 'mergeIfNotBlank is not merged with empty string'),
182 array('mergeIfNotBlank', 'fake_table', 0, true, 'mergeIfNotBlank is merged with 0'),
183 array('mergeIfNotBlank', 'fake_table', '0', true, 'mergeIfNotBlank is merged with "0"'),
184 array('mergeIfNotBlank', 'fake_table', 'foobar', true, 'mergeIfNotBlank is merged with non-empty string'),
186 array('mergeIfNotBlank_group', 'fake_table', '', false, 'mergeIfNotBlank on group is not merged empty string'),
187 array('mergeIfNotBlank_group', 'fake_table', 0, false, 'mergeIfNotBlank on group is not merged with 0'),
188 array('mergeIfNotBlank_group', 'fake_table', '0', false, 'mergeIfNotBlank on group is not merged with "0"'),
189 array('mergeIfNotBlank_group', 'fake_table', 'foobar', true, 'mergeIfNotBlank on group is merged with non-empty string'),
191 array('noCopy', 'fake_table', 'foobar', true, 'noCopy is merged with non-empty string'),
192 array('noCopy', 'fake_table', '', true, 'noCopy is merged with empty string'),
194 array('prefixLangTitle', 'fake_table', 'foobar', true, 'prefixLangTitle is merged with non-empty string'),
195 array('prefixLangTitle', 'fake_table', '', true, 'prefixLangTitle is merged with empty string'),
199 ////////////////////////////////
200 // Tests concerning workspaces
201 ////////////////////////////////
206 public function noPagesFromWorkspaceAreShownLive()
210 $GLOBALS['TCA'] = array(
211 'pages' => $this->defaultTcaForPages
214 // simulate calls from \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController->fetch_the_id()
215 $this->pageSelectObject
->versioningPreview
= false;
216 $this->pageSelectObject
->versioningWorkspaceId
= $wsid;
217 $this->pageSelectObject
->init(false);
219 // check SQL created by \TYPO3\CMS\Frontend\Page\PageRepository->getPage()
220 $GLOBALS['TYPO3_DB']->expects($this->once())
221 ->method('exec_SELECTgetSingleRow')
227 $this->stringContains('(pages.t3ver_wsid=0 or pages.t3ver_wsid=' . $wsid . ')')
229 $this->stringContains('AND pages.t3ver_state<=0')
233 $this->pageSelectObject
->getPage(1);
239 public function previewShowsPagesFromLiveAndCurrentWorkspace()
243 $GLOBALS['TCA'] = array(
244 'pages' => $this->defaultTcaForPages
247 // simulate calls from \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController->fetch_the_id()
248 $this->pageSelectObject
->versioningPreview
= true;
249 $this->pageSelectObject
->versioningWorkspaceId
= $wsid;
250 $this->pageSelectObject
->init(false);
252 // check SQL created by \TYPO3\CMS\Frontend\Page\PageRepository->getPage()
253 $GLOBALS['TYPO3_DB']->expects($this->once())
254 ->method('exec_SELECTgetSingleRow')
258 $this->stringContains('(pages.t3ver_wsid=0 or pages.t3ver_wsid=' . $wsid . ')')
261 $this->pageSelectObject
->getPage(1);
264 ////////////////////////////////
265 // Tests concerning versioning
266 ////////////////////////////////
271 public function enableFieldsHidesVersionedRecordsAndPlaceholders()
273 $table = $this->getUniqueId('aTable');
274 $GLOBALS['TCA'] = array(
275 'pages' => $this->defaultTcaForPages
,
278 'versioningWS' => true
283 $this->pageSelectObject
->versioningPreview
= false;
284 $this->pageSelectObject
->init(false);
286 $conditions = $this->pageSelectObject
->enableFields($table);
288 $this->assertThat($conditions, $this->stringContains(' AND ' . $table . '.t3ver_state<=0'), 'Versioning placeholders');
289 $this->assertThat($conditions, $this->stringContains(' AND ' . $table . '.pid<>-1'), 'Records from page -1');
295 public function enableFieldsDoesNotHidePlaceholdersInPreview()
297 $table = $this->getUniqueId('aTable');
298 $GLOBALS['TCA'] = array(
299 'pages' => $this->defaultTcaForPages
,
302 'versioningWS' => true
307 $this->pageSelectObject
->versioningPreview
= true;
308 $this->pageSelectObject
->init(false);
310 $conditions = $this->pageSelectObject
->enableFields($table);
312 $this->assertThat($conditions, $this->logicalNot($this->stringContains(' AND ' . $table . '.t3ver_state<=0')), 'No versioning placeholders');
313 $this->assertThat($conditions, $this->stringContains(' AND ' . $table . '.pid<>-1'), 'Records from page -1');
319 public function enableFieldsDoesFilterToCurrentAndLiveWorkspaceForRecordsInPreview()
321 $table = $this->getUniqueId('aTable');
322 $GLOBALS['TCA'] = array(
323 'pages' => $this->defaultTcaForPages
,
326 'versioningWS' => true
331 $this->pageSelectObject
->versioningPreview
= true;
332 $this->pageSelectObject
->versioningWorkspaceId
= 2;
333 $this->pageSelectObject
->init(false);
335 $conditions = $this->pageSelectObject
->enableFields($table);
337 $this->assertThat($conditions, $this->stringContains(' AND (' . $table . '.t3ver_wsid=0 OR ' . $table . '.t3ver_wsid=2)'), 'No versioning placeholders');
343 public function enableFieldsDoesNotHideVersionedRecordsWhenCheckingVersionOverlays()
345 $table = $this->getUniqueId('aTable');
346 $GLOBALS['TCA'] = array(
347 'pages' => $this->defaultTcaForPages
,
350 'versioningWS' => true
355 $this->pageSelectObject
->versioningPreview
= true;
356 $this->pageSelectObject
->init(false);
358 $conditions = $this->pageSelectObject
->enableFields($table, -1, array(), true);
360 $this->assertThat($conditions, $this->logicalNot($this->stringContains(' AND ' . $table . '.t3ver_state<=0')), 'No versioning placeholders');
361 $this->assertThat($conditions, $this->logicalNot($this->stringContains(' AND ' . $table . '.pid<>-1')), 'No ecords from page -1');