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!
19 * @author Christian Kuhn <lolli@schwarzbu.ch>
20 * @author Oliver Klee <typo3-coding@oliverklee.de>
22 class PageRepositoryTest
extends \TYPO3\CMS\Core\Tests\UnitTestCase
{
25 * @var \TYPO3\CMS\Frontend\Page\PageRepository|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface
27 protected $pageSelectObject;
30 * Sets up this testcase
32 public function setUp() {
33 $GLOBALS['TYPO3_DB'] = $this->getMock(\TYPO3\CMS\Core\Database\DatabaseConnection
::class, array('exec_SELECTquery', 'sql_fetch_assoc', 'sql_free_result'));
34 $this->pageSelectObject
= $this->getAccessibleMock(\TYPO3\CMS\Frontend\Page\PageRepository
::class, array('getMultipleGroupsWhereClause'));
35 $this->pageSelectObject
->expects($this->any())->method('getMultipleGroupsWhereClause')->will($this->returnValue(' AND 1=1'));
39 * Tests whether the getPage Hook is called correctly.
43 public function isGetPageHookCalled() {
44 // Create a hook mock object
45 $className = uniqid('tx_coretest');
46 $getPageHookMock = $this->getMock(\TYPO3\CMS\Frontend\Page\PageRepositoryGetPageHookInterface
::class, array('getPage_preProcess'), array(), $className);
47 // Register hook mock object
48 $GLOBALS['T3_VAR']['getUserObj'][$className] = $getPageHookMock;
49 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_page.php']['getPage'][] = $className;
50 // Test if hook is called and register a callback method to check given arguments
51 $getPageHookMock->expects($this->once())->method('getPage_preProcess')->will($this->returnCallback(array($this, 'isGetPagePreProcessCalledCallback')));
52 $this->pageSelectObject
->getPage(42, FALSE);
56 * Handles the arguments that have been sent to the getPage_preProcess hook
58 public function isGetPagePreProcessCalledCallback() {
59 list($uid, $disableGroupAccessCheck, $parent) = func_get_args();
60 $this->assertEquals(42, $uid);
61 $this->assertFalse($disableGroupAccessCheck);
62 $this->assertTrue($parent instanceof \TYPO3\CMS\Frontend\Page\PageRepository
);
65 /////////////////////////////////////////
66 // Tests concerning getPathFromRootline
67 /////////////////////////////////////////
71 public function getPathFromRootLineForEmptyRootLineReturnsEmptyString() {
72 $this->assertEquals('', $this->pageSelectObject
->getPathFromRootline(array()));
75 ///////////////////////////////
76 // Tests concerning getExtURL
77 ///////////////////////////////
81 public function getExtUrlForDokType3AndUrlType1AddsHttpSchemeToUrl() {
82 $this->assertEquals('http://www.example.com', $this->pageSelectObject
->getExtURL(array(
83 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository
::DOKTYPE_LINK
,
85 'url' => 'www.example.com'
92 public function getExtUrlForDokType3AndUrlType0PrependsSiteUrl() {
93 $this->assertEquals(\TYPO3\CMS\Core\Utility\GeneralUtility
::getIndpEnv('TYPO3_SITE_URL') . 'hello/world/', $this->pageSelectObject
->getExtURL(array(
94 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository
::DOKTYPE_LINK
,
96 'url' => 'hello/world/'
100 /////////////////////////////////////////
101 // Tests concerning shouldFieldBeOverlaid
102 /////////////////////////////////////////
105 * @dataProvider getShouldFieldBeOverlaidData
107 public function shouldFieldBeOverlaid($field, $table, $value, $expected, $comment = '') {
108 $GLOBALS['TCA']['fake_table']['columns'] = array(
110 'l10n_mode' => 'exclude',
111 'config' => array('type' => 'input'),
113 'mergeIfNotBlank' => array(
114 'l10n_mode' => 'mergeIfNotBlank',
115 'config' => array('type' => 'input'),
117 'mergeIfNotBlank_group' => array(
118 'l10n_mode' => 'mergeIfNotBlank',
119 'config' => array('type' => 'group'),
123 'config' => array('type' => 'input'),
126 'l10n_mode' => 'noCopy',
127 'config' => array('type' => 'input'),
129 'prefixLangTitle' => array(
130 'l10n_mode' => 'prefixLangTitle',
131 'config' => array('type' => 'input'),
135 $result = $this->pageSelectObject
->_call('shouldFieldBeOverlaid', $table, $field, $value);
136 unset($GLOBALS['TCA']['fake_table']);
138 $this->assertSame($expected, $result, $comment);
142 * Data provider for shouldFieldBeOverlaid
144 public function getShouldFieldBeOverlaidData() {
146 array('default', 'fake_table', 'foobar', TRUE, 'default is to merge non-empty string'),
147 array('default', 'fake_table', '', TRUE, 'default is to merge empty string'),
149 array('exclude', 'fake_table', '', FALSE, 'exclude field with empty string'),
150 array('exclude', 'fake_table', 'foobar', FALSE, 'exclude field with non-empty string'),
152 array('mergeIfNotBlank', 'fake_table', '', FALSE, 'mergeIfNotBlank is not merged with empty string'),
153 array('mergeIfNotBlank', 'fake_table', 0, TRUE, 'mergeIfNotBlank is merged with 0'),
154 array('mergeIfNotBlank', 'fake_table', '0', TRUE, 'mergeIfNotBlank is merged with "0"'),
155 array('mergeIfNotBlank', 'fake_table', 'foobar', TRUE, 'mergeIfNotBlank is merged with non-empty string'),
157 array('mergeIfNotBlank_group', 'fake_table', '', FALSE, 'mergeIfNotBlank on group is not merged empty string'),
158 array('mergeIfNotBlank_group', 'fake_table', 0, FALSE, 'mergeIfNotBlank on group is not merged with 0'),
159 array('mergeIfNotBlank_group', 'fake_table', '0', FALSE, 'mergeIfNotBlank on group is not merged with "0"'),
160 array('mergeIfNotBlank_group', 'fake_table', 'foobar', TRUE, 'mergeIfNotBlank on group is merged with non-empty string'),
162 array('noCopy', 'fake_table', 'foobar', TRUE, 'noCopy is merged with non-empty string'),
163 array('noCopy', 'fake_table', '', TRUE, 'noCopy is merged with empty string'),
165 array('prefixLangTitle', 'fake_table', 'foobar', TRUE, 'prefixLangTitle is merged with non-empty string'),
166 array('prefixLangTitle', 'fake_table', '', TRUE, 'prefixLangTitle is merged with empty string'),
170 ////////////////////////////////
171 // Tests concerning workspaces
172 ////////////////////////////////
177 public function noPagesFromWorkspaceAreShownLive() {
181 // simulate calls from \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController->fetch_the_id()
182 $this->pageSelectObject
->versioningPreview
= FALSE;
183 $this->pageSelectObject
->versioningWorkspaceId
= $wsid;
184 $this->pageSelectObject
->init(FALSE);
186 // check SQL created by \TYPO3\CMS\Frontend\Page\PageRepository->getPage()
187 $GLOBALS['TYPO3_DB']->expects($this->once())
188 ->method('exec_SELECTquery')
194 $this->stringContains('(pages.t3ver_wsid=0 or pages.t3ver_wsid=' . $wsid . ')')
196 $this->stringContains('AND NOT pages.t3ver_state>0')
200 $this->pageSelectObject
->getPage(1);
207 public function previewShowsPagesFromLiveAndCurrentWorkspace() {
211 // simulate calls from \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController->fetch_the_id()
212 $this->pageSelectObject
->versioningPreview
= TRUE;
213 $this->pageSelectObject
->versioningWorkspaceId
= $wsid;
214 $this->pageSelectObject
->init(FALSE);
216 // check SQL created by \TYPO3\CMS\Frontend\Page\PageRepository->getPage()
217 $GLOBALS['TYPO3_DB']->expects($this->once())
218 ->method('exec_SELECTquery')
222 $this->stringContains('(pages.t3ver_wsid=0 or pages.t3ver_wsid=' . $wsid . ')')
225 $this->pageSelectObject
->getPage(1);
229 ////////////////////////////////
230 // Tests concerning versioning
231 ////////////////////////////////
236 public function enableFieldsHidesVersionedRecordsAndPlaceholders() {
237 $table = uniqid('aTable');
238 $GLOBALS['TCA'] = array(
246 $this->pageSelectObject
->versioningPreview
= FALSE;
247 $this->pageSelectObject
->init(FALSE);
249 $conditions = $this->pageSelectObject
->enableFields($table);
251 $this->assertThat($conditions, $this->stringContains(' AND ' . $table . '.t3ver_state<=0'), 'Versioning placeholders');
252 $this->assertThat($conditions, $this->stringContains(' AND ' . $table . '.pid<>-1'), 'Records from page -1');
258 public function enableFieldsDoesNotHidePlaceholdersInPreview() {
259 $table = uniqid('aTable');
260 $GLOBALS['TCA'] = array(
268 $this->pageSelectObject
->versioningPreview
= TRUE;
269 $this->pageSelectObject
->init(FALSE);
271 $conditions = $this->pageSelectObject
->enableFields($table);
273 $this->assertThat($conditions, $this->logicalNot($this->stringContains(' AND ' . $table . '.t3ver_state<=0')), 'No versioning placeholders');
274 $this->assertThat($conditions, $this->stringContains(' AND ' . $table . '.pid<>-1'), 'Records from page -1');
280 public function enableFieldsDoesFilterToCurrentAndLiveWorkspaceForRecordsInPreview() {
281 $table = uniqid('aTable');
282 $GLOBALS['TCA'] = array(
290 $this->pageSelectObject
->versioningPreview
= TRUE;
291 $this->pageSelectObject
->versioningWorkspaceId
= 2;
292 $this->pageSelectObject
->init(FALSE);
294 $conditions = $this->pageSelectObject
->enableFields($table);
296 $this->assertThat($conditions, $this->stringContains(' AND (' . $table . '.t3ver_wsid=0 OR ' . $table . '.t3ver_wsid=2)'), 'No versioning placeholders');
302 public function enableFieldsDoesNotHideVersionedRecordsWhenCheckingVersionOverlays() {
303 $table = uniqid('aTable');
304 $GLOBALS['TCA'] = array(
312 $this->pageSelectObject
->versioningPreview
= TRUE;
313 $this->pageSelectObject
->init(FALSE);
315 $conditions = $this->pageSelectObject
->enableFields($table, -1, array(), TRUE );
317 $this->assertThat($conditions, $this->logicalNot($this->stringContains(' AND ' . $table . '.t3ver_state<=0')), 'No versioning placeholders');
318 $this->assertThat($conditions, $this->logicalNot($this->stringContains(' AND ' . $table . '.pid<>-1')), 'No ecords from page -1');