‪TYPO3CMS  10.4
AbstractImportExportTestCase.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
25 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
26 
30 abstract class ‪AbstractImportExportTestCase extends FunctionalTestCase
31 {
35  protected ‪$coreExtensionsToLoad = [
36  'impexp',
37  ];
38 
45  protected ‪$testFilesToDelete = [];
46 
51  protected function ‪setUp(): void
52  {
53  parent::setUp();
54 
55  $backendUser = $this->setUpBackendUserFromFixture(1);
56  $backendUser->workspace = 0;
58  }
59 
63  protected function ‪tearDown(): void
64  {
65  foreach ($this->testFilesToDelete as $absoluteFileName) {
66  if (@is_file($absoluteFileName)) {
67  unlink($absoluteFileName);
68  }
69  }
70  parent::tearDown();
71  }
72 
83  protected function ‪setPageTree(‪Export $export, $pidToStart, $depth = 1)
84  {
85  $permsClause = ‪$GLOBALS['BE_USER']->getPagePermsClause(1);
86 
87  $tree = GeneralUtility::makeInstance(PageTreeView::class);
88  $tree->init('AND ' . $permsClause);
89  $tree->tree[] = ['row' => $pidToStart];
90  $tree->buffer_idH = [];
91  if ($depth > 0) {
92  $tree->getTree($pidToStart, $depth, '');
93  }
94 
95  $idH = [];
96  $idH[$pidToStart]['uid'] = $pidToStart;
97  if (!empty($tree->buffer_idH)) {
98  $idH[$pidToStart]['subrow'] = $tree->buffer_idH;
99  }
100 
101  $export->‪setPageTree($idH);
102  }
103 
113  protected function ‪addRecordsForPid(‪Export $export, $pid, array $tables)
114  {
115  foreach (‪$GLOBALS['TCA'] as $table => $value) {
116  if ($table !== 'pages' && (in_array($table, $tables) || in_array('_ALL', $tables))) {
117  if (‪$GLOBALS['BE_USER']->check('tables_select', $table) && !‪$GLOBALS['TCA'][$table]['ctrl']['is_static']) {
118  $orderBy = ‪$GLOBALS['TCA'][$table]['ctrl']['sortby'] ?: ‪$GLOBALS['TCA'][$table]['ctrl']['default_sortby'];
119 
120  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
121  ->getQueryBuilderForTable($table);
122 
123  $queryBuilder->getRestrictions()
124  ->removeAll()
125  ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
126 
127  $queryBuilder
128  ->select('*')
129  ->from($table)
130  ->where(
131  $queryBuilder->expr()->eq(
132  'pid',
133  $queryBuilder->createNamedParameter($pid, \PDO::PARAM_INT)
134  )
135  );
136 
137  foreach (‪QueryHelper::parseOrderBy((string)$orderBy) as $orderPair) {
138  [$fieldName, $order] = $orderPair;
139  $queryBuilder->addOrderBy($fieldName, $order);
140  }
141  $queryBuilder->addOrderBy('uid', 'ASC');
142 
143  $result = $queryBuilder->execute();
144  while ($row = $result->fetch()) {
145  $export->‪export_addRecord($table, $this->‪forceStringsOnRowValues($row));
146  }
147  }
148  }
149  }
150  }
151 
159  protected function ‪forceStringsOnRowValues(array $row): array
160  {
161  foreach ($row as $fieldName => $value) {
162  // Keep null but force everything else to string
163  $row[$fieldName] = $value === null ? $value : (string)$value;
164  }
165  return $row;
166  }
167 
174  protected function ‪isCaseSensitiveFilesystem()
175  {
176  $caseSensitive = true;
177  $path = GeneralUtility::tempnam('aAbB');
178 
179  // do the actual sensitivity check
180  if (@file_exists(strtoupper($path)) && @file_exists(strtolower($path))) {
181  $caseSensitive = false;
182  }
183 
184  // clean filesystem
185  unlink($path);
186  return $caseSensitive;
187  }
188 }
‪TYPO3\CMS\Core\Database\Query\QueryHelper\parseOrderBy
‪static array array[] parseOrderBy(string $input)
Definition: QueryHelper.php:44
‪TYPO3\CMS\Impexp\Export\setPageTree
‪array setPageTree($idH)
Definition: Export.php:209
‪TYPO3\CMS\Impexp\Tests\Functional\AbstractImportExportTestCase\isCaseSensitiveFilesystem
‪bool isCaseSensitiveFilesystem()
Definition: AbstractImportExportTestCase.php:172
‪TYPO3\CMS\Impexp\Tests\Functional\AbstractImportExportTestCase\$testFilesToDelete
‪array $testFilesToDelete
Definition: AbstractImportExportTestCase.php:43
‪TYPO3\CMS\Impexp\Tests\Functional
Definition: AbstractImportExportTestCase.php:16
‪TYPO3\CMS\Impexp\Tests\Functional\AbstractImportExportTestCase\$coreExtensionsToLoad
‪array $coreExtensionsToLoad
Definition: AbstractImportExportTestCase.php:34
‪TYPO3\CMS\Backend\Tree\View\PageTreeView
Definition: PageTreeView.php:24
‪TYPO3\CMS\Impexp\Tests\Functional\AbstractImportExportTestCase\setPageTree
‪setPageTree(Export $export, $pidToStart, $depth=1)
Definition: AbstractImportExportTestCase.php:81
‪TYPO3\CMS\Core\Core\Bootstrap\initializeLanguageObject
‪static initializeLanguageObject()
Definition: Bootstrap.php:617
‪TYPO3\CMS\Core\Database\Query\QueryHelper
Definition: QueryHelper.php:32
‪TYPO3\CMS\Impexp\Export\export_addRecord
‪export_addRecord($table, $row, $relationLevel=0)
Definition: Export.php:276
‪TYPO3\CMS\Impexp\Tests\Functional\AbstractImportExportTestCase
Definition: AbstractImportExportTestCase.php:31
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction
Definition: DeletedRestriction.php:28
‪TYPO3\CMS\Core\Core\Bootstrap
Definition: Bootstrap.php:66
‪TYPO3\CMS\Impexp\Tests\Functional\AbstractImportExportTestCase\forceStringsOnRowValues
‪array forceStringsOnRowValues(array $row)
Definition: AbstractImportExportTestCase.php:157
‪TYPO3\CMS\Impexp\Export
Definition: Export.php:64
‪TYPO3\CMS\Impexp\Tests\Functional\AbstractImportExportTestCase\tearDown
‪tearDown()
Definition: AbstractImportExportTestCase.php:61
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Impexp\Tests\Functional\AbstractImportExportTestCase\addRecordsForPid
‪addRecordsForPid(Export $export, $pid, array $tables)
Definition: AbstractImportExportTestCase.php:111
‪TYPO3\CMS\Impexp\Tests\Functional\AbstractImportExportTestCase\setUp
‪setUp()
Definition: AbstractImportExportTestCase.php:49