1
|
|
|
<?php |
2
|
|
|
declare(strict_types = 1); |
3
|
|
|
namespace TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers; |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the TYPO3 CMS project. |
7
|
|
|
* |
8
|
|
|
* It is free software; you can redistribute it and/or modify it under |
9
|
|
|
* the terms of the GNU General Public License, either version 2 |
10
|
|
|
* of the License, or any later version. |
11
|
|
|
* |
12
|
|
|
* For the full copyright and license information, please read the |
13
|
|
|
* LICENSE.txt file that was distributed with this source code. |
14
|
|
|
* |
15
|
|
|
* The TYPO3 project - inspiring people to share! |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
use TYPO3\CMS\Fluid\View\StandaloneView; |
19
|
|
|
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; |
20
|
|
|
|
21
|
|
|
class FetchViewHelperTest extends FunctionalTestCase |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var array |
25
|
|
|
*/ |
26
|
|
|
protected $testExtensionsToLoad = ['typo3conf/ext/qbtools']; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var array |
30
|
|
|
*/ |
31
|
|
|
protected $coreExtensionsToLoad = ['fluid']; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @dataProvider renderFetchesDataProvider |
35
|
|
|
*/ |
36
|
|
|
public function testFetchesData( |
37
|
|
|
string $from, |
38
|
|
|
string $field, |
39
|
|
|
string $sortby, |
40
|
|
|
array $match, |
41
|
|
|
string $limit, |
42
|
|
|
bool $ignoreEnableFields, |
43
|
|
|
string $expected, |
44
|
|
|
string $template |
45
|
|
|
) { |
46
|
|
|
$this->importDataSet(ORIGINAL_ROOT . 'typo3conf/ext/qbtools/Tests/Functional/ViewHelpers/Fixtures/pages.xml'); |
47
|
|
|
$this->importDataSet(ORIGINAL_ROOT . 'typo3conf/ext/qbtools/Tests/Functional/ViewHelpers/Fixtures/fe_groups.xml'); |
48
|
|
|
$this->importDataSet(ORIGINAL_ROOT . 'typo3conf/ext/qbtools/Tests/Functional/ViewHelpers/Fixtures/fe_users.xml'); |
49
|
|
|
|
50
|
|
|
$view = new StandaloneView(); |
51
|
|
|
$view->setTemplatePathAndFilename('typo3conf/ext/qbtools/Tests/Functional/ViewHelpers/Fixtures/' . $template . '.html'); |
52
|
|
|
$view->assignMultiple([ |
53
|
|
|
'from' => $from, |
54
|
|
|
'field' => $field, |
55
|
|
|
'sortby' => $sortby, |
56
|
|
|
'match' => $match, |
57
|
|
|
'limit' => $limit, |
58
|
|
|
'ignoreEnableFields' => $ignoreEnableFields, |
59
|
|
|
]); |
60
|
|
|
|
61
|
|
|
if (version_compare(TYPO3_branch, '9', '<')) { |
62
|
|
|
$uid = 1; |
63
|
|
|
$typoScriptFrontendController = new \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController(null, $uid, 0); |
64
|
|
|
$typoScriptFrontendController->gr_list = ''; |
65
|
|
|
$GLOBALS['TSFE'] = $typoScriptFrontendController; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
$this->assertEquals($expected, trim(preg_replace('/\s+/', ' ', $view->render()))); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return array |
73
|
|
|
*/ |
74
|
|
|
public function renderFetchesDataProvider(): array |
75
|
|
|
{ |
76
|
|
|
return [ |
77
|
|
|
'fetch: table pages' => [ |
78
|
|
|
'from' => 'pages', |
79
|
|
|
'field' => 'title', |
80
|
|
|
'sortby' => 'sorting', |
81
|
|
|
'match' => [], |
82
|
|
|
'limit' => '', |
83
|
|
|
'ignoreEnableFields' => false, |
84
|
|
|
'expected' => 'Main page, Sub page,', |
85
|
|
|
'template' => 'fetch_table_viewhelper', |
86
|
|
|
], |
87
|
|
|
'fetch: table fe_users' => [ |
88
|
|
|
'from' => 'fe_users', |
89
|
|
|
'field' => 'username', |
90
|
|
|
'sortby' => 'uid', |
91
|
|
|
'match' => [], |
92
|
|
|
'limit' => '', |
93
|
|
|
'ignoreEnableFields' => false, |
94
|
|
|
'expected' => 'testuser, testuser2,', |
95
|
|
|
'template' => 'fetch_table_viewhelper', |
96
|
|
|
], |
97
|
|
|
'fetch: model FrontendUser' => [ |
98
|
|
|
'from' => \TYPO3\CMS\Extbase\Domain\Model\FrontendUser::class, |
99
|
|
|
'field' => 'username', |
100
|
|
|
'sortby' => 'uid', |
101
|
|
|
'match' => [], |
102
|
|
|
'limit' => '', |
103
|
|
|
'ignoreEnableFields' => false, |
104
|
|
|
'expected' => 'testuser, testuser2,', |
105
|
|
|
'template' => 'fetch_model_viewhelper', |
106
|
|
|
], |
107
|
|
|
'fetch: table pages in pid 1' => [ |
108
|
|
|
'from' => 'pages', |
109
|
|
|
'field' => 'title', |
110
|
|
|
'sortby' => 'sorting', |
111
|
|
|
'match' => ['pid' => '1'], |
112
|
|
|
'limit' => '', |
113
|
|
|
'ignoreEnableFields' => false, |
114
|
|
|
'expected' => 'Sub page,', |
115
|
|
|
'template' => 'fetch_table_viewhelper', |
116
|
|
|
], |
117
|
|
|
'fetch: model FrontendUser with uid 2' => [ |
118
|
|
|
'from' => \TYPO3\CMS\Extbase\Domain\Model\FrontendUser::class, |
119
|
|
|
'field' => 'username', |
120
|
|
|
'sortby' => 'uid', |
121
|
|
|
'match' => ['uid' => 2], |
122
|
|
|
'limit' => '', |
123
|
|
|
'ignoreEnableFields' => false, |
124
|
|
|
'expected' => 'testuser2,', |
125
|
|
|
'template' => 'fetch_model_viewhelper', |
126
|
|
|
], |
127
|
|
|
'fetch: table pages including hidden ones' => [ |
128
|
|
|
'from' => 'pages', |
129
|
|
|
'field' => 'title', |
130
|
|
|
'sortby' => 'sorting', |
131
|
|
|
'match' => [], |
132
|
|
|
'limit' => '', |
133
|
|
|
'ignoreEnableFields' => true, |
134
|
|
|
'expected' => 'Main page, Sub page,', |
135
|
|
|
'template' => 'fetch_table_viewhelper', |
136
|
|
|
], |
137
|
|
|
'fetch: model FrontendUser including hidden ones' => [ |
138
|
|
|
'from' => \TYPO3\CMS\Extbase\Domain\Model\FrontendUser::class, |
139
|
|
|
'field' => 'username', |
140
|
|
|
'sortby' => 'uid', |
141
|
|
|
'match' => [], |
142
|
|
|
'limit' => '', |
143
|
|
|
'ignoreEnableFields' => true, |
144
|
|
|
'expected' => 'testuser, testuser2, testuser3,', |
145
|
|
|
'template' => 'fetch_model_viewhelper', |
146
|
|
|
], |
147
|
|
|
'fetch: table pages with limit' => [ |
148
|
|
|
'from' => 'pages', |
149
|
|
|
'field' => 'title', |
150
|
|
|
'sortby' => 'sorting', |
151
|
|
|
'match' => [], |
152
|
|
|
'limit' => '1', |
153
|
|
|
'ignoreEnableFields' => false, |
154
|
|
|
'expected' => 'Main page,', |
155
|
|
|
'template' => 'fetch_table_viewhelper', |
156
|
|
|
], |
157
|
|
|
'fetch: model FrontendUser with limit' => [ |
158
|
|
|
'from' => \TYPO3\CMS\Extbase\Domain\Model\FrontendUser::class, |
159
|
|
|
'field' => 'username', |
160
|
|
|
'sortby' => 'uid', |
161
|
|
|
'match' => [], |
162
|
|
|
'limit' => '1', |
163
|
|
|
'ignoreEnableFields' => false, |
164
|
|
|
'expected' => 'testuser,', |
165
|
|
|
'template' => 'fetch_model_viewhelper', |
166
|
|
|
], |
167
|
|
|
]; |
168
|
|
|
} |
169
|
|
|
} |
170
|
|
|
|