[!!!][TASK] Extract testing framework for TYPO3
[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 * 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
17 /**
18 * Test case
19 */
20 class PageRepositoryTest extends \TYPO3\CMS\Components\TestingFramework\Core\UnitTestCase
21 {
22 /**
23 * @var \TYPO3\CMS\Frontend\Page\PageRepository|\TYPO3\CMS\Components\TestingFramework\Core\AccessibleObjectInterface
24 */
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
46 /**
47 * Sets up this testcase
48 */
49 protected function setUp()
50 {
51 $this->pageSelectObject = $this->getAccessibleMock(\TYPO3\CMS\Frontend\Page\PageRepository::class, ['getMultipleGroupsWhereClause']);
52 $this->pageSelectObject->expects($this->any())->method('getMultipleGroupsWhereClause')->will($this->returnValue(' AND 1=1'));
53 }
54
55 /////////////////////////////////////////
56 // Tests concerning getPathFromRootline
57 /////////////////////////////////////////
58 /**
59 * @test
60 */
61 public function getPathFromRootLineForEmptyRootLineReturnsEmptyString()
62 {
63 $this->assertEquals('', $this->pageSelectObject->getPathFromRootline([]));
64 }
65
66 ///////////////////////////////
67 // Tests concerning getExtURL
68 ///////////////////////////////
69 /**
70 * @test
71 */
72 public function getExtUrlForDokType3AndUrlType1AddsHttpSchemeToUrl()
73 {
74 $this->assertEquals('http://www.example.com', $this->pageSelectObject->getExtURL([
75 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_LINK,
76 'urltype' => 1,
77 'url' => 'www.example.com'
78 ]));
79 }
80
81 /**
82 * @test
83 */
84 public function getExtUrlForDokType3AndUrlType0PrependsSiteUrl()
85 {
86 $this->assertEquals(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . 'hello/world/', $this->pageSelectObject->getExtURL([
87 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_LINK,
88 'urltype' => 0,
89 'url' => 'hello/world/'
90 ]));
91 }
92
93 /////////////////////////////////////////
94 // Tests concerning shouldFieldBeOverlaid
95 /////////////////////////////////////////
96 /**
97 * @test
98 * @dataProvider getShouldFieldBeOverlaidData
99 */
100 public function shouldFieldBeOverlaid($field, $table, $value, $expected, $comment = '')
101 {
102 $GLOBALS['TCA']['fake_table']['columns'] = [
103 'exclude' => [
104 'l10n_mode' => 'exclude',
105 'config' => ['type' => 'input'],
106 ],
107 'mergeIfNotBlank' => [
108 'l10n_mode' => 'mergeIfNotBlank',
109 'config' => ['type' => 'input'],
110 ],
111 'mergeIfNotBlank_group' => [
112 'l10n_mode' => 'mergeIfNotBlank',
113 'config' => ['type' => 'group'],
114 ],
115 'default' => [
116 // no l10n_mode set
117 'config' => ['type' => 'input'],
118 ],
119 'noCopy' => [
120 'l10n_mode' => 'noCopy',
121 'config' => ['type' => 'input'],
122 ],
123 'prefixLangTitle' => [
124 'l10n_mode' => 'prefixLangTitle',
125 'config' => ['type' => 'input'],
126 ],
127 ];
128
129 $result = $this->pageSelectObject->_call('shouldFieldBeOverlaid', $table, $field, $value);
130 unset($GLOBALS['TCA']['fake_table']);
131
132 $this->assertSame($expected, $result, $comment);
133 }
134
135 /**
136 * Data provider for shouldFieldBeOverlaid
137 */
138 public function getShouldFieldBeOverlaidData()
139 {
140 return [
141 ['default', 'fake_table', 'foobar', true, 'default is to merge non-empty string'],
142 ['default', 'fake_table', '', true, 'default is to merge empty string'],
143
144 ['exclude', 'fake_table', '', false, 'exclude field with empty string'],
145 ['exclude', 'fake_table', 'foobar', false, 'exclude field with non-empty string'],
146
147 ['mergeIfNotBlank', 'fake_table', '', false, 'mergeIfNotBlank is not merged with empty string'],
148 ['mergeIfNotBlank', 'fake_table', 0, true, 'mergeIfNotBlank is merged with 0'],
149 ['mergeIfNotBlank', 'fake_table', '0', true, 'mergeIfNotBlank is merged with "0"'],
150 ['mergeIfNotBlank', 'fake_table', 'foobar', true, 'mergeIfNotBlank is merged with non-empty string'],
151
152 ['mergeIfNotBlank_group', 'fake_table', '', false, 'mergeIfNotBlank on group is not merged empty string'],
153 ['mergeIfNotBlank_group', 'fake_table', 0, false, 'mergeIfNotBlank on group is not merged with 0'],
154 ['mergeIfNotBlank_group', 'fake_table', '0', false, 'mergeIfNotBlank on group is not merged with "0"'],
155 ['mergeIfNotBlank_group', 'fake_table', 'foobar', true, 'mergeIfNotBlank on group is merged with non-empty string'],
156
157 ['noCopy', 'fake_table', 'foobar', true, 'noCopy is merged with non-empty string'],
158 ['noCopy', 'fake_table', '', true, 'noCopy is merged with empty string'],
159
160 ['prefixLangTitle', 'fake_table', 'foobar', true, 'prefixLangTitle is merged with non-empty string'],
161 ['prefixLangTitle', 'fake_table', '', true, 'prefixLangTitle is merged with empty string'],
162 ];
163 }
164 }