‪TYPO3CMS  ‪main
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 
20 use PHPUnit\Framework\Attributes\Test;
27 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
28 
29 final class ‪DownloadRecordListTest extends FunctionalTestCase
30 {
32 
33  protected function ‪setUp(): void
34  {
35  parent::setUp();
36  $this->importCSVDataSet(__DIR__ . '/../Fixtures/be_users.csv');
37  $this->user = $this->setUpBackendUser(1);
38  ‪$GLOBALS['LANG'] = $this->get(LanguageServiceFactory::class)->createFromUserPreferences($this->user);
39  }
40 
41  #[Test]
43  {
44  $recordList = $this->get(DatabaseRecordList::class);
45  $recordList->setRequest(new ‪ServerRequest());
46  $recordList->start(0, 'be_users', 0);
47  $recordList->setFields['be_users'] = [
48  'username',
49  'realName',
50  'email',
51  'admin',
52  'crdate',
53  ];
54  $subject = new ‪DownloadRecordList($recordList, new ‪TranslationConfigurationProvider());
55  $headerRow = $subject->getHeaderRow($recordList->setFields['be_users']);
56  $contentRows = $subject->getRecords('be_users', $recordList->setFields['be_users'], $this->user);
57  $result = array_merge([$headerRow], $contentRows);
58  self::assertEquals([
59  [
60  'username' => 'username',
61  'email' => 'email',
62  'realName' => 'realName',
63  'admin' => 'admin',
64  'crdate' => 'crdate',
65  ],
66  [
67  'username' => 'admin',
68  'email' => '',
69  'realName' => '',
70  'admin' => 'Yes',
71  'crdate' => '22-04-13 14:55',
72  ],
73  ], $this->‪prepareRecordsForDbCompatAssertions($result));
74  }
75 
76  #[Test]
77  public function ‪downloadReturnsAListOfSubpages(): void
78  {
79  $this->importCSVDataSet(__DIR__ . '/../Fixtures/pages_download_record_list.csv');
80  $recordList = $this->get(DatabaseRecordList::class);
81  $recordList->setRequest(new ‪ServerRequest());
82  $recordList->start(1, 'pages', 0);
83  $recordList->setFields['pages'] = [
84  'uid',
85  'pid',
86  'title',
87  'sys_language_uid',
88  ];
89  $subject = new ‪DownloadRecordList($recordList, new ‪TranslationConfigurationProvider());
90  $headerRow = $subject->getHeaderRow($recordList->setFields['pages']);
91  // Get records with raw values
92  $contentRows = $subject->getRecords('pages', $recordList->setFields['pages'], $this->user, false, true);
93  $result = array_merge([$headerRow], $contentRows);
94  self::assertEquals([
95  [
96  'uid' => 'uid',
97  'pid' => 'pid',
98  'title' => 'title',
99  'sys_language_uid' => 'sys_language_uid',
100  ],
101  [
102  'uid' => '2',
103  'pid' => '1',
104  'title' => 'Dummy 1-2',
105  'sys_language_uid' => '0',
106  ],
107  [
108  'uid' => '902',
109  'pid' => '1',
110  'title' => 'Attrappe 1-2',
111  'sys_language_uid' => '1',
112  ],
113  [
114  'uid' => '3',
115  'pid' => '1',
116  'title' => 'Dummy 1-3',
117  'sys_language_uid' => '0',
118  ],
119  [
120  'uid' => '903',
121  'pid' => '1',
122  'title' => 'Attrappe 1-3',
123  'sys_language_uid' => '1',
124  ],
125  [
126  'uid' => '4',
127  'pid' => '1',
128  'title' => 'Dummy 1-4',
129  'sys_language_uid' => '0',
130  ],
131  ], $this->‪prepareRecordsForDbCompatAssertions($result));
132 
133  // Fetch the records again but now ensure translations are omitted
134  $headerRow = $subject->getHeaderRow($recordList->setFields['pages']);
135  $contentRows = $subject->getRecords('pages', $recordList->setFields['pages'], $this->user, true);
136  $result = array_merge([$headerRow], $contentRows);
137  self::assertEquals([
138  [
139  'uid' => 'uid',
140  'pid' => 'pid',
141  'title' => 'title',
142  'sys_language_uid' => 'sys_language_uid',
143  ],
144  [
145  'uid' => '2',
146  'pid' => '1',
147  'title' => 'Dummy 1-2',
148  'sys_language_uid' => 'Default',
149  ],
150  [
151  'uid' => '3',
152  'pid' => '1',
153  'title' => 'Dummy 1-3',
154  'sys_language_uid' => 'Default',
155  ],
156  [
157  'uid' => '4',
158  'pid' => '1',
159  'title' => 'Dummy 1-4',
160  'sys_language_uid' => 'Default',
161  ],
162  ], $this->‪prepareRecordsForDbCompatAssertions($result));
163  }
164 
165  #[Test]
166  public function ‪downloadReturnsRawValues(): void
167  {
168  $recordList = $this->get(DatabaseRecordList::class);
169  $recordList->setRequest(new ‪ServerRequest());
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', $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 
204  protected function ‪prepareRecordsForDbCompatAssertions(array $records): array
205  {
206  foreach ($records as &‪$record) {
207  ‪$record = array_map(strval(...), ‪$record);
208  }
209  return $records;
210  }
211 }
‪TYPO3\CMS\Core\Localization\LanguageServiceFactory
Definition: LanguageServiceFactory.php:25
‪TYPO3\CMS\Backend\Tests\Functional\RecordList\DownloadRecordListTest
Definition: DownloadRecordListTest.php:30
‪TYPO3\CMS\Backend\RecordList\DownloadRecordList
Definition: DownloadRecordList.php:35
‪TYPO3\CMS\Backend\RecordList\DatabaseRecordList
Definition: DatabaseRecordList.php:68
‪TYPO3\CMS\Backend\Tests\Functional\RecordList\DownloadRecordListTest\downloadReturnsAListOfSubpages
‪downloadReturnsAListOfSubpages()
Definition: DownloadRecordListTest.php:77
‪TYPO3\CMS\Backend\Tests\Functional\RecordList\DownloadRecordListTest\downloadReturnsAListOfAllBackendUsers
‪downloadReturnsAListOfAllBackendUsers()
Definition: DownloadRecordListTest.php:42
‪TYPO3\CMS\Backend\Tests\Functional\RecordList\DownloadRecordListTest\downloadReturnsRawValues
‪downloadReturnsRawValues()
Definition: DownloadRecordListTest.php:166
‪TYPO3\CMS\Webhooks\Message\$record
‪identifier readonly int readonly array $record
Definition: PageModificationMessage.php:36
‪TYPO3\CMS\Backend\Tests\Functional\RecordList\DownloadRecordListTest\$user
‪BackendUserAuthentication $user
Definition: DownloadRecordListTest.php:31
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:39
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:61
‪TYPO3\CMS\Backend\Tests\Functional\RecordList
Definition: DownloadRecordListTest.php:18
‪TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider
Definition: TranslationConfigurationProvider.php:39
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Backend\Tests\Functional\RecordList\DownloadRecordListTest\setUp
‪setUp()
Definition: DownloadRecordListTest.php:33
‪TYPO3\CMS\Backend\Tests\Functional\RecordList\DownloadRecordListTest\prepareRecordsForDbCompatAssertions
‪prepareRecordsForDbCompatAssertions(array $records)
Definition: DownloadRecordListTest.php:204