TYPO3 CMS  TYPO3_8-7
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 
25 
29 abstract class AbstractImportExportTestCase extends FunctionalTestCase
30 {
34  protected $coreExtensionsToLoad = [
35  'impexp',
36  ];
37 
44  protected $testFilesToDelete = [];
45 
52  protected $databasePlatform;
53 
58  protected function setUp()
59  {
60  parent::setUp();
61 
62  $this->databasePlatform = $this->getConnectionPool()
63  ->getConnectionByName(ConnectionPool::DEFAULT_CONNECTION_NAME)
64  ->getDatabasePlatform()
65  ->getName();
66 
67  $backendUser = $this->setUpBackendUserFromFixture(1);
68  $backendUser->workspace = 0;
69  Bootstrap::getInstance()->initializeLanguageObject();
70  }
71 
75  protected function tearDown()
76  {
77  foreach ($this->testFilesToDelete as $absoluteFileName) {
78  if (@is_file($absoluteFileName)) {
79  unlink($absoluteFileName);
80  }
81  }
82  parent::tearDown();
83  }
84 
95  protected function setPageTree(Export $export, $pidToStart, $depth = 1)
96  {
97  $permsClause = $GLOBALS['BE_USER']->getPagePermsClause(1);
98 
99  $tree = GeneralUtility::makeInstance(PageTreeView::class);
100  $tree->init('AND ' . $permsClause);
101  $tree->tree[] = ['row' => $pidToStart];
102  $tree->buffer_idH = [];
103  if ($depth > 0) {
104  $tree->getTree($pidToStart, $depth, '');
105  }
106 
107  $idH[$pidToStart]['uid'] = $pidToStart;
108  if (!empty($tree->buffer_idH)) {
109  $idH[$pidToStart]['subrow'] = $tree->buffer_idH;
110  }
111 
112  $export->setPageTree($idH);
113  }
114 
124  protected function addRecordsForPid(Export $export, $pid, array $tables)
125  {
126  foreach ($GLOBALS['TCA'] as $table => $value) {
127  if ($table !== 'pages' && (in_array($table, $tables) || in_array('_ALL', $tables))) {
128  if ($GLOBALS['BE_USER']->check('tables_select', $table) && !$GLOBALS['TCA'][$table]['ctrl']['is_static']) {
129  $orderBy = $GLOBALS['TCA'][$table]['ctrl']['sortby'] ?: $GLOBALS['TCA'][$table]['ctrl']['default_sortby'];
130 
131  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
132  ->getQueryBuilderForTable($table);
133 
134  $queryBuilder->getRestrictions()
135  ->removeAll()
136  ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
137 
138  $queryBuilder
139  ->select('*')
140  ->from($table)
141  ->where(
142  $queryBuilder->expr()->eq(
143  'pid',
144  $queryBuilder->createNamedParameter($pid, \PDO::PARAM_INT)
145  )
146  );
147 
148  foreach (QueryHelper::parseOrderBy((string)$orderBy) as $orderPair) {
149  list($fieldName, $order) = $orderPair;
150  $queryBuilder->addOrderBy($fieldName, $order);
151  }
152 
153  $result = $queryBuilder->execute();
154  while ($row = $result->fetch()) {
155  $export->export_addRecord($table, $row);
156  }
157  }
158  }
159  }
160  }
161 
168  protected function isCaseSensitiveFilesystem()
169  {
170  $caseSensitive = true;
171  $path = GeneralUtility::tempnam('aAbB');
172 
173  // do the actual sensitivity check
174  if (@file_exists(strtoupper($path)) && @file_exists(strtolower($path))) {
175  $caseSensitive = false;
176  }
177 
178  // clean filesystem
179  unlink($path);
180  return $caseSensitive;
181  }
182 }
static makeInstance($className,... $constructorArguments)
export_addRecord($table, $row, $relationLevel=0)
Definition: Export.php:300
static tempnam($filePrefix, $fileSuffix='')
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']