[TASK] Doctrine: Migrate \TYPO3\CMS\Frontend\Page\PageRepository
[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\Core\Tests\UnitTestCase
21 {
22 /**
23 * @var \TYPO3\CMS\Frontend\Page\PageRepository|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface
24 */
25 protected $pageSelectObject;
26
27 protected $defaultTcaForPages = array(
28 'ctrl' => array(
29 'label' => 'title',
30 'tstamp' => 'tstamp',
31 'sortby' => 'sorting',
32 'type' => 'doktype',
33 'versioningWS' => true,
34 'origUid' => 't3_origuid',
35 'delete' => 'deleted',
36 'enablecolumns' => array(
37 'disabled' => 'hidden',
38 'starttime' => 'starttime',
39 'endtime' => 'endtime',
40 'fe_group' => 'fe_group'
41 ),
42 ),
43 'columns' => array()
44 );
45
46 /**
47 * Sets up this testcase
48 */
49 protected function setUp()
50 {
51 $GLOBALS['TYPO3_DB'] = $this->getMockBuilder(\TYPO3\CMS\Core\Database\DatabaseConnection::class)
52 ->setMethods(array('exec_SELECTquery', 'sql_fetch_assoc', 'sql_free_result', 'exec_SELECTgetSingleRow'))
53 ->getMock();
54 $this->pageSelectObject = $this->getAccessibleMock(\TYPO3\CMS\Frontend\Page\PageRepository::class, array('getMultipleGroupsWhereClause'));
55 $this->pageSelectObject->expects($this->any())->method('getMultipleGroupsWhereClause')->will($this->returnValue(' AND 1=1'));
56 }
57
58 /////////////////////////////////////////
59 // Tests concerning getPathFromRootline
60 /////////////////////////////////////////
61 /**
62 * @test
63 */
64 public function getPathFromRootLineForEmptyRootLineReturnsEmptyString()
65 {
66 $this->assertEquals('', $this->pageSelectObject->getPathFromRootline(array()));
67 }
68
69 ///////////////////////////////
70 // Tests concerning getExtURL
71 ///////////////////////////////
72 /**
73 * @test
74 */
75 public function getExtUrlForDokType3AndUrlType1AddsHttpSchemeToUrl()
76 {
77 $this->assertEquals('http://www.example.com', $this->pageSelectObject->getExtURL(array(
78 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_LINK,
79 'urltype' => 1,
80 'url' => 'www.example.com'
81 )));
82 }
83
84 /**
85 * @test
86 */
87 public function getExtUrlForDokType3AndUrlType0PrependsSiteUrl()
88 {
89 $this->assertEquals(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . 'hello/world/', $this->pageSelectObject->getExtURL(array(
90 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_LINK,
91 'urltype' => 0,
92 'url' => 'hello/world/'
93 )));
94 }
95
96 /////////////////////////////////////////
97 // Tests concerning shouldFieldBeOverlaid
98 /////////////////////////////////////////
99 /**
100 * @test
101 * @dataProvider getShouldFieldBeOverlaidData
102 */
103 public function shouldFieldBeOverlaid($field, $table, $value, $expected, $comment = '')
104 {
105 $GLOBALS['TCA']['fake_table']['columns'] = array(
106 'exclude' => array(
107 'l10n_mode' => 'exclude',
108 'config' => array('type' => 'input'),
109 ),
110 'mergeIfNotBlank' => array(
111 'l10n_mode' => 'mergeIfNotBlank',
112 'config' => array('type' => 'input'),
113 ),
114 'mergeIfNotBlank_group' => array(
115 'l10n_mode' => 'mergeIfNotBlank',
116 'config' => array('type' => 'group'),
117 ),
118 'default' => array(
119 // no l10n_mode set
120 'config' => array('type' => 'input'),
121 ),
122 'noCopy' => array(
123 'l10n_mode' => 'noCopy',
124 'config' => array('type' => 'input'),
125 ),
126 'prefixLangTitle' => array(
127 'l10n_mode' => 'prefixLangTitle',
128 'config' => array('type' => 'input'),
129 ),
130 );
131
132 $result = $this->pageSelectObject->_call('shouldFieldBeOverlaid', $table, $field, $value);
133 unset($GLOBALS['TCA']['fake_table']);
134
135 $this->assertSame($expected, $result, $comment);
136 }
137
138 /**
139 * Data provider for shouldFieldBeOverlaid
140 */
141 public function getShouldFieldBeOverlaidData()
142 {
143 return array(
144 array('default', 'fake_table', 'foobar', true, 'default is to merge non-empty string'),
145 array('default', 'fake_table', '', true, 'default is to merge empty string'),
146
147 array('exclude', 'fake_table', '', false, 'exclude field with empty string'),
148 array('exclude', 'fake_table', 'foobar', false, 'exclude field with non-empty string'),
149
150 array('mergeIfNotBlank', 'fake_table', '', false, 'mergeIfNotBlank is not merged with empty string'),
151 array('mergeIfNotBlank', 'fake_table', 0, true, 'mergeIfNotBlank is merged with 0'),
152 array('mergeIfNotBlank', 'fake_table', '0', true, 'mergeIfNotBlank is merged with "0"'),
153 array('mergeIfNotBlank', 'fake_table', 'foobar', true, 'mergeIfNotBlank is merged with non-empty string'),
154
155 array('mergeIfNotBlank_group', 'fake_table', '', false, 'mergeIfNotBlank on group is not merged empty string'),
156 array('mergeIfNotBlank_group', 'fake_table', 0, false, 'mergeIfNotBlank on group is not merged with 0'),
157 array('mergeIfNotBlank_group', 'fake_table', '0', false, 'mergeIfNotBlank on group is not merged with "0"'),
158 array('mergeIfNotBlank_group', 'fake_table', 'foobar', true, 'mergeIfNotBlank on group is merged with non-empty string'),
159
160 array('noCopy', 'fake_table', 'foobar', true, 'noCopy is merged with non-empty string'),
161 array('noCopy', 'fake_table', '', true, 'noCopy is merged with empty string'),
162
163 array('prefixLangTitle', 'fake_table', 'foobar', true, 'prefixLangTitle is merged with non-empty string'),
164 array('prefixLangTitle', 'fake_table', '', true, 'prefixLangTitle is merged with empty string'),
165 );
166 }
167 }