‪TYPO3CMS  9.5
AbstractImportExportTestCase.php
Go to the documentation of this file.
1 <?php
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 
24 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
25 
29 abstract class ‪AbstractImportExportTestCase extends FunctionalTestCase
30 {
34  protected ‪$coreExtensionsToLoad = [
35  'impexp',
36  ];
37 
44  protected ‪$testFilesToDelete = [];
45 
50  protected function ‪setUp()
51  {
52  parent::setUp();
53 
54  $backendUser = $this->setUpBackendUserFromFixture(1);
55  $backendUser->workspace = 0;
57  }
58 
62  protected function ‪tearDown()
63  {
64  foreach ($this->testFilesToDelete as $absoluteFileName) {
65  if (@is_file($absoluteFileName)) {
66  unlink($absoluteFileName);
67  }
68  }
69  parent::tearDown();
70  }
71 
82  protected function ‪setPageTree(‪Export $export, $pidToStart, $depth = 1)
83  {
84  $permsClause = ‪$GLOBALS['BE_USER']->getPagePermsClause(1);
85 
86  $tree = GeneralUtility::makeInstance(PageTreeView::class);
87  $tree->init('AND ' . $permsClause);
88  $tree->tree[] = ['row' => $pidToStart];
89  $tree->buffer_idH = [];
90  if ($depth > 0) {
91  $tree->getTree($pidToStart, $depth, '');
92  }
93 
94  $idH[$pidToStart]['uid'] = $pidToStart;
95  if (!empty($tree->buffer_idH)) {
96  $idH[$pidToStart]['subrow'] = $tree->buffer_idH;
97  }
98 
99  $export->‪setPageTree($idH);
100  }
101 
111  protected function ‪addRecordsForPid(‪Export $export, $pid, array $tables)
112  {
113  foreach (‪$GLOBALS['TCA'] as $table => $value) {
114  if ($table !== 'pages' && (in_array($table, $tables) || in_array('_ALL', $tables))) {
115  if (‪$GLOBALS['BE_USER']->check('tables_select', $table) && !‪$GLOBALS['TCA'][$table]['ctrl']['is_static']) {
116  $orderBy = ‪$GLOBALS['TCA'][$table]['ctrl']['sortby'] ?: ‪$GLOBALS['TCA'][$table]['ctrl']['default_sortby'];
117 
118  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
119  ->getQueryBuilderForTable($table);
120 
121  $queryBuilder->getRestrictions()
122  ->removeAll()
123  ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
124 
125  $queryBuilder
126  ->select('*')
127  ->from($table)
128  ->where(
129  $queryBuilder->expr()->eq(
130  'pid',
131  $queryBuilder->createNamedParameter($pid, \PDO::PARAM_INT)
132  )
133  );
134 
135  foreach (‪QueryHelper::parseOrderBy((string)$orderBy) as $orderPair) {
136  list($fieldName, $order) = $orderPair;
137  $queryBuilder->addOrderBy($fieldName, $order);
138  }
139  $queryBuilder->addOrderBy('uid', 'ASC');
140 
141  $result = $queryBuilder->execute();
142  while ($row = $result->fetch()) {
143  $export->‪export_addRecord($table, $this->‪forceStringsOnRowValues($row));
144  }
145  }
146  }
147  }
148  }
149 
157  protected function ‪forceStringsOnRowValues(array $row): array
158  {
159  foreach ($row as $fieldName => $value) {
160  // Keep null but force everything else to string
161  $row[$fieldName] = $value === null ? $value : (string)$value;
162  }
163  return $row;
164  }
165 
172  protected function ‪isCaseSensitiveFilesystem()
173  {
174  $caseSensitive = true;
175  $path = GeneralUtility::tempnam('aAbB');
176 
177  // do the actual sensitivity check
178  if (@file_exists(strtoupper($path)) && @file_exists(strtolower($path))) {
179  $caseSensitive = false;
180  }
181 
182  // clean filesystem
183  unlink($path);
184  return $caseSensitive;
185  }
186 }
‪TYPO3\CMS\Core\Database\Query\QueryHelper\parseOrderBy
‪static array array[] parseOrderBy(string $input)
Definition: QueryHelper.php:42
‪TYPO3\CMS\Impexp\Export\setPageTree
‪array setPageTree($idH)
Definition: Export.php:222
‪TYPO3\CMS\Impexp\Tests\Functional\AbstractImportExportTestCase\isCaseSensitiveFilesystem
‪bool isCaseSensitiveFilesystem()
Definition: AbstractImportExportTestCase.php:170
‪TYPO3\CMS\Impexp\Tests\Functional\AbstractImportExportTestCase\$testFilesToDelete
‪array $testFilesToDelete
Definition: AbstractImportExportTestCase.php:42
‪TYPO3\CMS\Impexp\Tests\Functional
Definition: AbstractImportExportTestCase.php:2
‪TYPO3\CMS\Impexp\Tests\Functional\AbstractImportExportTestCase\$coreExtensionsToLoad
‪array $coreExtensionsToLoad
Definition: AbstractImportExportTestCase.php:33
‪TYPO3\CMS\Backend\Tree\View\PageTreeView
Definition: PageTreeView.php:23
‪TYPO3\CMS\Impexp\Tests\Functional\AbstractImportExportTestCase\setPageTree
‪setPageTree(Export $export, $pidToStart, $depth=1)
Definition: AbstractImportExportTestCase.php:80
‪TYPO3\CMS\Core\Database\Query\QueryHelper
Definition: QueryHelper.php:30
‪TYPO3\CMS\Impexp\Export\export_addRecord
‪export_addRecord($table, $row, $relationLevel=0)
Definition: Export.php:289
‪TYPO3\CMS\Impexp\Tests\Functional\AbstractImportExportTestCase
Definition: AbstractImportExportTestCase.php:30
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction
Definition: DeletedRestriction.php:26
‪TYPO3\CMS\Core\Core\Bootstrap
Definition: Bootstrap.php:50
‪TYPO3\CMS\Impexp\Tests\Functional\AbstractImportExportTestCase\forceStringsOnRowValues
‪array forceStringsOnRowValues(array $row)
Definition: AbstractImportExportTestCase.php:155
‪TYPO3\CMS\Impexp\Export
Definition: Export.php:62
‪TYPO3\CMS\Impexp\Tests\Functional\AbstractImportExportTestCase\tearDown
‪tearDown()
Definition: AbstractImportExportTestCase.php:60
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Impexp\Tests\Functional\AbstractImportExportTestCase\addRecordsForPid
‪addRecordsForPid(Export $export, $pid, array $tables)
Definition: AbstractImportExportTestCase.php:109
‪TYPO3\CMS\Impexp\Tests\Functional\AbstractImportExportTestCase\setUp
‪setUp()
Definition: AbstractImportExportTestCase.php:48
‪TYPO3\CMS\Core\Core\Bootstrap\initializeLanguageObject
‪static Bootstrap null initializeLanguageObject()
Definition: Bootstrap.php:986