‪TYPO3CMS  11.5
DownloadRecordListTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
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 
19 
25 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
26 
27 class ‪DownloadRecordListTest extends FunctionalTestCase
28 {
30 
31  protected function ‪setUp(): void
32  {
33  parent::setUp();
34  $this->user = $this->setUpBackendUserFromFixture(1);
35  ‪$GLOBALS['LANG'] = $this->get(LanguageServiceFactory::class)->createFromUserPreferences($this->user);
36  }
37 
42  {
43  $recordList = $this->get(DatabaseRecordList::class);
44  $recordList->start(0, 'be_users', 0);
45  $recordList->setFields['be_users'] = [
46  'username',
47  'realName',
48  'email',
49  'admin',
50  'crdate',
51  ];
52  $subject = new ‪DownloadRecordList($recordList, new ‪TranslationConfigurationProvider());
53  $headerRow = $subject->getHeaderRow($recordList->setFields['be_users']);
54  $contentRows = $subject->getRecords('be_users', 0, $recordList->setFields['be_users'], $this->user);
55  $result = array_merge([$headerRow], $contentRows);
56  self::assertEquals([
57  [
58  'username' => 'username',
59  'email' => 'email',
60  'realName' => 'realName',
61  'admin' => 'admin',
62  'crdate' => 'crdate',
63  ],
64  [
65  'username' => 'admin',
66  'email' => '',
67  'realName' => '',
68  'admin' => 'Yes',
69  'crdate' => '22-04-13 14:55',
70  ],
71  ], $this->‪prepareRecordsForDbCompatAssertions($result));
72  }
73 
77  public function ‪downloadReturnsAListOfSubpages(): void
78  {
79  $this->importCSVDataSet(__DIR__ . '/Fixtures/pages.csv');
80  $recordList = $this->get(DatabaseRecordList::class);
81  $recordList->start(1, 'pages', 0);
82  $recordList->setFields['pages'] = [
83  'uid',
84  'pid',
85  'title',
86  'sys_language_uid',
87  ];
88  $subject = new ‪DownloadRecordList($recordList, new ‪TranslationConfigurationProvider());
89  $headerRow = $subject->getHeaderRow($recordList->setFields['pages']);
90  // Get records with raw values
91  $contentRows = $subject->getRecords('pages', 1, $recordList->setFields['pages'], $this->user, false, true);
92  $result = array_merge([$headerRow], $contentRows);
93  self::assertEquals([
94  [
95  'uid' => 'uid',
96  'pid' => 'pid',
97  'title' => 'title',
98  'sys_language_uid' => 'sys_language_uid',
99  ],
100  [
101  'uid' => '2',
102  'pid' => '1',
103  'title' => 'Dummy 1-2',
104  'sys_language_uid' => '0',
105  ],
106  [
107  'uid' => '902',
108  'pid' => '1',
109  'title' => 'Attrappe 1-2',
110  'sys_language_uid' => '1',
111  ],
112  [
113  'uid' => '3',
114  'pid' => '1',
115  'title' => 'Dummy 1-3',
116  'sys_language_uid' => '0',
117  ],
118  [
119  'uid' => '903',
120  'pid' => '1',
121  'title' => 'Attrappe 1-3',
122  'sys_language_uid' => '1',
123  ],
124  [
125  'uid' => '4',
126  'pid' => '1',
127  'title' => 'Dummy 1-4',
128  'sys_language_uid' => '0',
129  ],
130  ], $this->‪prepareRecordsForDbCompatAssertions($result));
131 
132  // Fetch the records again but now ensure translations are omitted
133  $headerRow = $subject->getHeaderRow($recordList->setFields['pages']);
134  $contentRows = $subject->getRecords('pages', 1, $recordList->setFields['pages'], $this->user, true);
135  $result = array_merge([$headerRow], $contentRows);
136  self::assertEquals([
137  [
138  'uid' => 'uid',
139  'pid' => 'pid',
140  'title' => 'title',
141  'sys_language_uid' => 'sys_language_uid',
142  ],
143  [
144  'uid' => '2',
145  'pid' => '1',
146  'title' => 'Dummy 1-2',
147  'sys_language_uid' => 'Default',
148  ],
149  [
150  'uid' => '3',
151  'pid' => '1',
152  'title' => 'Dummy 1-3',
153  'sys_language_uid' => 'Default',
154  ],
155  [
156  'uid' => '4',
157  'pid' => '1',
158  'title' => 'Dummy 1-4',
159  'sys_language_uid' => 'Default',
160  ],
161  ], $this->‪prepareRecordsForDbCompatAssertions($result));
162  }
163 
167  public function ‪downloadReturnsRawValues(): void
168  {
169  $recordList = $this->get(DatabaseRecordList::class);
170  $recordList->start(0, 'be_users', 0);
171  $recordList->setFields['be_users'] = [
172  'username',
173  'realName',
174  'email',
175  'admin',
176  'crdate',
177  ];
178  $subject = new ‪DownloadRecordList($recordList, new ‪TranslationConfigurationProvider());
179  $headerRow = $subject->getHeaderRow($recordList->setFields['be_users']);
180  $contentRows = $subject->getRecords('be_users', 0, $recordList->setFields['be_users'], $this->user, false, true);
181  $result = array_merge([$headerRow], $contentRows);
182  self::assertEquals([
183  [
184  'username' => 'username',
185  'email' => 'email',
186  'realName' => 'realName',
187  'admin' => 'admin',
188  'crdate' => 'crdate',
189  ],
190  [
191  'username' => 'admin',
192  'email' => '',
193  'realName' => '',
194  'admin' => '1',
195  'crdate' => '1366642540',
196  ],
197  ], $this->‪prepareRecordsForDbCompatAssertions($result));
198  }
199 
207  protected function ‪prepareRecordsForDbCompatAssertions(array $records): array
208  {
209  foreach ($records as &$record) {
210  $record = array_map('strval', $record);
211  }
212  return $records;
213  }
214 }
‪TYPO3\CMS\Core\Localization\LanguageServiceFactory
Definition: LanguageServiceFactory.php:25
‪TYPO3\CMS\Recordlist\Tests\Functional\RecordList\DownloadRecordListTest\downloadReturnsAListOfAllBackendUsers
‪downloadReturnsAListOfAllBackendUsers()
Definition: DownloadRecordListTest.php:41
‪TYPO3\CMS\Recordlist\Tests\Functional\RecordList\DownloadRecordListTest\downloadReturnsAListOfSubpages
‪downloadReturnsAListOfSubpages()
Definition: DownloadRecordListTest.php:77
‪TYPO3\CMS\Recordlist\Tests\Functional\RecordList\DownloadRecordListTest\$user
‪BackendUserAuthentication $user
Definition: DownloadRecordListTest.php:29
‪TYPO3\CMS\Recordlist\Tests\Functional\RecordList\DownloadRecordListTest
Definition: DownloadRecordListTest.php:28
‪TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList
Definition: DatabaseRecordList.php:59
‪TYPO3\CMS\Recordlist\Tests\Functional\RecordList\DownloadRecordListTest\setUp
‪setUp()
Definition: DownloadRecordListTest.php:31
‪TYPO3\CMS\Recordlist\Tests\Functional\RecordList
Definition: DownloadRecordListTest.php:18
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider
Definition: TranslationConfigurationProvider.php:37
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Recordlist\RecordList\DownloadRecordList
Definition: DownloadRecordList.php:35
‪TYPO3\CMS\Recordlist\Tests\Functional\RecordList\DownloadRecordListTest\downloadReturnsRawValues
‪downloadReturnsRawValues()
Definition: DownloadRecordListTest.php:167
‪TYPO3\CMS\Recordlist\Tests\Functional\RecordList\DownloadRecordListTest\prepareRecordsForDbCompatAssertions
‪array prepareRecordsForDbCompatAssertions(array $records)
Definition: DownloadRecordListTest.php:207