[BUGFIX] LogLevelTest dataProvider not used
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Utility / RootlineUtilityTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\Utility;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2012 Steffen Ritter <steffen.ritter@typo3.org>
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 require_once __DIR__ . '/Fixtures/RootlineUtilityTestAccessibleFixture.php';
28
29 /**
30 * Testcase for class \TYPO3\CMS\Core\Utility\RootlineUtility
31 *
32 * @author Steffen Ritter <steffen.ritter@typo3.org>
33 * @package TYPO3
34 * @subpackage t3lib
35 */
36 class RootlineUtilityTest extends \tx_phpunit_testcase {
37
38 /***
39 *
40 * UTILITY FUNCTIONS
41 *
42 */
43 /**
44 * Tests that $subsetCandidate is completely part of $superset
45 * and keys match.
46 *
47 * @see (A ^ B) = A <=> A c B
48 * @param array $subsetCandidate
49 * @param array $superset
50 */
51 protected function assertIsSubset(array $subsetCandidate, array $superset) {
52 $this->assertSame($subsetCandidate, array_intersect_assoc($subsetCandidate, $superset));
53 }
54
55 /***
56 *
57 * >TEST CASES
58 *
59 */
60 /**
61 * @test
62 */
63 public function isMountedPageWithoutMountPointsReturnsFalse() {
64 $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1);
65 $this->assertFalse($fixture->isMountedPage());
66 }
67
68 /**
69 * @test
70 */
71 public function isMountedPageWithMatchingMountPointParameterReturnsTrue() {
72 $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1, '1-99');
73 $this->assertTrue($fixture->isMountedPage());
74 }
75
76 /**
77 * @test
78 */
79 public function isMountedPageWithNonMatchingMountPointParameterReturnsFalse() {
80 $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1, '99-99');
81 $this->assertFalse($fixture->isMountedPage());
82 }
83
84 /**
85 * @test
86 * @expectedException RuntimeException
87 */
88 public function processMountedPageWithNonMountedPageThrowsException() {
89 $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1, '1-99');
90 $fixture->processMountedPage(array('uid' => 1), array('uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_DEFAULT));
91 }
92
93 /**
94 * @test
95 */
96 public function processMountedPageWithMountedPageNotThrowsException() {
97 $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1, '1-99');
98 $fixture->processMountedPage(array('uid' => 1), array('uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1));
99 }
100
101 /**
102 * @test
103 */
104 public function processMountedPageWithMountedPageAddsMountedFromParameter() {
105 $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1, '1-99');
106 $result = $fixture->processMountedPage(array('uid' => 1), array('uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1));
107 $this->assertTrue(isset($result['_MOUNTED_FROM']));
108 $this->assertSame(1, $result['_MOUNTED_FROM']);
109 }
110
111 /**
112 * @test
113 */
114 public function processMountedPageWithMountedPageAddsMountPointParameterToReturnValue() {
115 $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1, '1-99');
116 $result = $fixture->processMountedPage(array('uid' => 1), array('uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1));
117 $this->assertTrue(isset($result['_MP_PARAM']));
118 $this->assertSame('1-99', $result['_MP_PARAM']);
119 }
120
121 /**
122 * @test
123 */
124 public function processMountedPageForMountPageIsOverlayAddsMountOLParameter() {
125 $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1, '1-99');
126 $result = $fixture->processMountedPage(array('uid' => 1), array('uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1, 'mount_pid_ol' => 1));
127 $this->assertTrue(isset($result['_MOUNT_OL']));
128 $this->assertSame(TRUE, $result['_MOUNT_OL']);
129 }
130
131 /**
132 * @test
133 */
134 public function processMountedPageForMountPageIsOverlayAddsDataInformationAboutMountPage() {
135 $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1, '1-99');
136 $result = $fixture->processMountedPage(array('uid' => 1), array('uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1, 'mount_pid_ol' => 1, 'pid' => 5, 'title' => 'TestCase'));
137 $this->assertTrue(isset($result['_MOUNT_PAGE']));
138 $this->assertSame(array('uid' => 99, 'pid' => 5, 'title' => 'TestCase'), $result['_MOUNT_PAGE']);
139 }
140
141 /**
142 * @test
143 */
144 public function processMountedPageForMountPageWithoutOverlayReplacesMountedPageWithMountPage() {
145 $a = array('uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1, 'mount_pid_ol' => 0);
146 $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1, '1-99');
147 $result = $fixture->processMountedPage(array('uid' => 1), $a);
148 $this->assertIsSubset($a, $result);
149 }
150
151 /**
152 * @test
153 */
154 public function columnHasRelationToResolveDetectsGroupFieldAsLocal() {
155 $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1);
156 $this->assertFalse($fixture->columnHasRelationToResolve(array(
157 'type' => 'group'
158 )));
159 }
160
161 /**
162 * @test
163 */
164 public function columnHasRelationToResolveDetectsGroupFieldWithMMAsRemote() {
165 $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1);
166 $this->assertTrue($fixture->columnHasRelationToResolve(array(
167 'config' => array(
168 'type' => 'group',
169 'MM' => 'tx_xyz'
170 )
171 )));
172 }
173
174 /**
175 * @test
176 */
177 public function columnHasRelationToResolveDetectsInlineFieldAsLocal() {
178 $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1);
179 $this->assertFalse($fixture->columnHasRelationToResolve(array(
180 'config' => array(
181 'type' => 'inline'
182 )
183 )));
184 }
185
186 /**
187 * @test
188 */
189 public function columnHasRelationToResolveDetectsInlineFieldWithForeignKeyAsRemote() {
190 $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1);
191 $this->assertTrue($fixture->columnHasRelationToResolve(array(
192 'config' => array(
193 'type' => 'inline',
194 'foreign_field' => 'xyz'
195 )
196 )));
197 }
198
199 /**
200 * @test
201 */
202 public function columnHasRelationToResolveDetectsInlineFieldWithFMMAsRemote() {
203 $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1);
204 $this->assertTrue($fixture->columnHasRelationToResolve(array(
205 'config' => array(
206 'type' => 'inline',
207 'MM' => 'xyz'
208 )
209 )));
210 }
211
212 /**
213 * @test
214 */
215 public function columnHasRelationToResolveDetectsSelectFieldAsLocal() {
216 $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1);
217 $this->assertFalse($fixture->columnHasRelationToResolve(array(
218 'config' => array(
219 'type' => 'select'
220 )
221 )));
222 }
223
224 /**
225 * @test
226 */
227 public function columnHasRelationToResolveDetectsSelectFieldWithMMAsRemote() {
228 $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1);
229 $this->assertTrue($fixture->columnHasRelationToResolve(array(
230 'config' => array(
231 'type' => 'select',
232 'MM' => 'xyz'
233 )
234 )));
235 }
236
237 /**
238 * @test
239 */
240 public function getCacheIdentifierContainsAllContextParameters() {
241 $pageContext = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
242 $pageContext->sys_language_uid = 8;
243 $pageContext->versioningWorkspaceId = 15;
244 $pageContext->versioningPreview = TRUE;
245 $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(42, '47-11', $pageContext);
246 $this->assertSame('42_47-11_8_15_1', $fixture->getCacheIdentifier());
247 $pageContext->versioningPreview = FALSE;
248 $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(42, '47-11', $pageContext);
249 $this->assertSame('42_47-11_8_15_0', $fixture->getCacheIdentifier());
250 $pageContext->versioningWorkspaceId = 0;
251 $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(42, '47-11', $pageContext);
252 $this->assertSame('42_47-11_8_0_0', $fixture->getCacheIdentifier());
253 }
254
255 }
256
257 ?>