a681bb4e3fd2efdd96e5b4fd9059853a78930a8b
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Tests / Unit / Page / PageRepositoryTest.php
1 <?php
2 namespace TYPO3\CMS\Frontend\Tests\Unit\Page;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2009-2013 Christian Kuhn <lolli@schwarzbu.ch>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26 /**
27 * Test case
28 *
29 * @author Christian Kuhn <lolli@schwarzbu.ch>
30 * @author Oliver Klee <typo3-coding@oliverklee.de>
31 */
32 class PageRepositoryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
33
34 /**
35 * @var \TYPO3\CMS\Core\Database\DatabaseConnection
36 */
37 protected $typo3DbBackup;
38
39 /**
40 * @var \TYPO3\CMS\Frontend\Page\PageRepository
41 */
42 protected $pageSelectObject;
43
44 /**
45 * Sets up this testcase
46 */
47 public function setUp() {
48 $this->typo3DbBackup = $GLOBALS['TYPO3_DB'];
49 $GLOBALS['TYPO3_DB'] = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection', array('exec_SELECTquery', 'sql_fetch_assoc', 'sql_free_result'));
50 $this->pageSelectObject = $this->getMock('TYPO3\\CMS\\Frontend\\Page\\PageRepository', array('getMultipleGroupsWhereClause'));
51 $this->pageSelectObject->expects($this->any())->method('getMultipleGroupsWhereClause')->will($this->returnValue(' AND 1=1'));
52 }
53
54 /**
55 * Tears down this testcase
56 */
57 public function tearDown() {
58 $GLOBALS['TYPO3_DB'] = $this->typo3DbBackup;
59 }
60
61 /**
62 * Tests whether the getPage Hook is called correctly.
63 *
64 * @test
65 */
66 public function isGetPageHookCalled() {
67 // Create a hook mock object
68 $className = uniqid('tx_coretest');
69 $getPageHookMock = $this->getMock('TYPO3\\CMS\\Frontend\\Page\\PageRepositoryGetPageHookInterface', array('getPage_preProcess'), array(), $className);
70 // Register hook mock object
71 $GLOBALS['T3_VAR']['getUserObj'][$className] = $getPageHookMock;
72 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_page.php']['getPage'][] = $className;
73 // Test if hook is called and register a callback method to check given arguments
74 $getPageHookMock->expects($this->once())->method('getPage_preProcess')->will($this->returnCallback(array($this, 'isGetPagePreProcessCalledCallback')));
75 $this->pageSelectObject->getPage(42, FALSE);
76 }
77
78 /**
79 * Handles the arguments that have been sent to the getPage_preProcess hook
80 */
81 public function isGetPagePreProcessCalledCallback() {
82 list($uid, $disableGroupAccessCheck, $parent) = func_get_args();
83 $this->assertEquals(42, $uid);
84 $this->assertFalse($disableGroupAccessCheck);
85 $this->assertTrue($parent instanceof \TYPO3\CMS\Frontend\Page\PageRepository);
86 }
87
88 /////////////////////////////////////////
89 // Tests concerning getPathFromRootline
90 /////////////////////////////////////////
91 /**
92 * @test
93 */
94 public function getPathFromRootLineForEmptyRootLineReturnsEmptyString() {
95 $this->assertEquals('', $this->pageSelectObject->getPathFromRootline(array()));
96 }
97
98 ///////////////////////////////
99 // Tests concerning getExtURL
100 ///////////////////////////////
101 /**
102 * @test
103 */
104 public function getExtUrlForDokType3AndUrlType1AddsHttpSchemeToUrl() {
105 $this->assertEquals('http://www.example.com', $this->pageSelectObject->getExtURL(array(
106 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_LINK,
107 'urltype' => 1,
108 'url' => 'www.example.com'
109 )));
110 }
111
112 /**
113 * @test
114 */
115 public function getExtUrlForDokType3AndUrlType0PrependsSiteUrl() {
116 $this->assertEquals(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . 'hello/world/', $this->pageSelectObject->getExtURL(array(
117 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_LINK,
118 'urltype' => 0,
119 'url' => 'hello/world/'
120 )));
121 }
122
123
124 ////////////////////////////////
125 // Tests concerning versioning
126 ////////////////////////////////
127
128 /**
129 * @test
130 */
131 public function enableFieldsHidesVersionedRecordsAndPlaceholders() {
132 $this->pageSelectObject->versioningPreview = FALSE;
133 $this->pageSelectObject->init(FALSE);
134
135 $conditions = $this->pageSelectObject->enableFields('tt_content');
136
137 $this->assertThat($conditions, $this->stringContains(' AND tt_content.t3ver_state<=0'), 'Versioning placeholders');
138 $this->assertThat($conditions, $this->stringContains(' AND tt_content.pid<>-1'), 'Records from page -1');
139 }
140
141 /**
142 * @test
143 */
144 public function enableFieldsDoesNotHidePlaceholdersInPreview() {
145 $this->pageSelectObject->versioningPreview = TRUE;
146 $this->pageSelectObject->init(FALSE);
147
148 $conditions = $this->pageSelectObject->enableFields('tt_content');
149
150 $this->assertThat($conditions, $this->logicalNot($this->stringContains(' AND tt_content.t3ver_state<=0')), 'No versioning placeholders');
151 $this->assertThat($conditions, $this->stringContains(' AND tt_content.pid<>-1'), 'Records from page -1');
152 }
153
154 /**
155 * @test
156 */
157 public function enableFieldsDoesFilterToCurrentAndLiveWorkspaceForRecordsInPreview() {
158 $this->pageSelectObject->versioningPreview = TRUE;
159 $this->pageSelectObject->versioningWorkspaceId = 2;
160 $this->pageSelectObject->init(FALSE);
161
162 $conditions = $this->pageSelectObject->enableFields('tt_content');
163
164 $this->assertThat($conditions, $this->stringContains(' AND (tt_content.t3ver_wsid=0 OR tt_content.t3ver_wsid=2)'), 'No versioning placeholders');
165 }
166
167 /**
168 * @test
169 */
170 public function enableFieldsDoesNotHideVersionedRecordsWhenCheckingVersionOverlays() {
171 $this->pageSelectObject->versioningPreview = TRUE;
172 $this->pageSelectObject->init(FALSE);
173
174 $conditions = $this->pageSelectObject->enableFields('tt_content', -1, array(), TRUE );
175
176 $this->assertThat($conditions, $this->logicalNot($this->stringContains(' AND tt_content.t3ver_state<=0')), 'No versioning placeholders');
177 $this->assertThat($conditions, $this->logicalNot($this->stringContains(' AND tt_content.pid<>-1')), 'No ecords from page -1');
178 }
179
180
181 }
182
183 ?>