e1092338be6d38f1381f619e03db73c416fd55dd
[Packages/TYPO3.CMS.git] / typo3 / sysext / impexp / Tests / Functional / Export / AbstractExportTestCase.php
1 <?php
2 namespace TYPO3\CMS\Impexp\Tests\Functional\Export;
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
17 use TYPO3\CMS\Core\Utility\GeneralUtility;
18 use TYPO3\CMS\Backend\Utility\BackendUtility;
19
20 /**
21 * Functional test for the ImportExport
22 */
23 abstract class AbstractExportTestCase extends \TYPO3\CMS\Core\Tests\FunctionalTestCase {
24
25 /**
26 * @var array
27 */
28 protected $coreExtensionsToLoad = array('impexp');
29
30 /**
31 * @var \TYPO3\CMS\Impexp\ImportExport
32 */
33 protected $export;
34
35 /**
36 * Set up for set up the backend user, initialize the language object
37 * and creating the ImportExport instance
38 *
39 * @return void
40 */
41 protected function setUp() {
42 parent::setUp();
43
44 $this->setUpBackendUserFromFixture(1);
45 // Needed to avoid PHP Warnings
46 $GLOBALS['TBE_STYLES']['spriteIconApi']['iconsAvailable'] = array();
47
48 \TYPO3\CMS\Core\Core\Bootstrap::getInstance()->initializeLanguageObject();
49
50 $this->export = GeneralUtility::makeInstance(\TYPO3\CMS\Impexp\ImportExport::class);
51 $this->export->init(0, 'export');
52 }
53
54 /**
55 * Builds a flat array containing the page tree with the PageTreeView
56 * based on given start pid and depth and set it in the ImportExport object.
57 *
58 * @param int $pidToStart
59 * @param int $depth
60 * @return void
61 */
62 protected function setPageTree($pidToStart, $depth = 1) {
63
64 $permsClause = $GLOBALS['BE_USER']->getPagePermsClause(1);
65
66 /** @var $tree \TYPO3\CMS\Backend\Tree\View\PageTreeView */
67 $tree = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Tree\View\PageTreeView::class);
68 $tree->init('AND ' . $permsClause);
69 $tree->tree[] = array('row' => $pidToStart);
70 $tree->buffer_idH = array();
71 if ($depth > 0) {
72 $tree->getTree($pidToStart, $depth, '');
73 }
74
75 $idH[$pidToStart]['uid'] = $pidToStart;
76 if (count($tree->buffer_idH)) {
77 $idH[$pidToStart]['subrow'] = $tree->buffer_idH;
78 }
79
80 $this->export->setPageTree($idH);
81 }
82
83 /**
84 * Adds records to the export object for a specific page id.
85 *
86 * @param int $pid Page id for which to select records to add
87 * @param array $tables Array of table names to select from
88 * @return void
89 */
90 protected function addRecordsForPid($pid, array $tables) {
91 foreach ($GLOBALS['TCA'] as $table => $value) {
92 if ($table != 'pages' && (in_array($table, $tables) || in_array('_ALL', $tables))) {
93 if ($GLOBALS['BE_USER']->check('tables_select', $table) && !$GLOBALS['TCA'][$table]['ctrl']['is_static']) {
94 $orderBy = $GLOBALS['TCA'][$table]['ctrl']['sortby'] ? 'ORDER BY ' . $GLOBALS['TCA'][$table]['ctrl']['sortby'] : $GLOBALS['TCA'][$table]['ctrl']['default_sortby'];
95 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
96 '*',
97 $table,
98 'pid = ' . (int)$pid . BackendUtility::deleteClause($table),
99 '',
100 $GLOBALS['TYPO3_DB']->stripOrderBy($orderBy)
101 );
102 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
103 $this->export->export_addRecord($table, $row);
104 }
105 }
106 }
107 }
108 }
109
110 }