[TASK] Add functional tests for impexp irre records
[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 * Copyright notice
6 *
7 * (c) 2014 Marc Bastian Heinrichs <typo3@mbh-software.de>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 use TYPO3\CMS\Core\Utility\GeneralUtility;
28 use TYPO3\CMS\Backend\Utility\BackendUtility;
29
30 /**
31 * Functional test for the ImportExport
32 */
33 abstract class AbstractExportTestCase extends \TYPO3\CMS\Core\Tests\FunctionalTestCase {
34
35 /**
36 * @var array
37 */
38 protected $coreExtensionsToLoad = array('impexp');
39
40 /**
41 * @var \TYPO3\CMS\Impexp\ImportExport
42 */
43 protected $export;
44
45 /**
46 * Set up for set up the backend user, initialize the language object
47 * and creating the ImportExport instance
48 *
49 * @return void
50 */
51 public function setUp() {
52 parent::setUp();
53
54 $this->setUpBackendUserFromFixture(1);
55 // Needed to avoid PHP Warnings
56 $GLOBALS['TBE_STYLES']['spriteIconApi']['iconsAvailable'] = array();
57
58 \TYPO3\CMS\Core\Core\Bootstrap::getInstance()->initializeLanguageObject();
59
60 $this->export = GeneralUtility::makeInstance('TYPO3\\CMS\\Impexp\\ImportExport');
61 $this->export->init(0, 'export');
62 }
63
64 /**
65 * Builds a flat array containing the page tree with the PageTreeView
66 * based on given start pid and depth and set it in the ImportExport object.
67 *
68 * @param int $pidToStart
69 * @param int $depth
70 * @return void
71 */
72 protected function setPageTree($pidToStart, $depth = 1) {
73
74 $permsClause = $GLOBALS['BE_USER']->getPagePermsClause(1);
75
76 /** @var $tree \TYPO3\CMS\Backend\Tree\View\PageTreeView */
77 $tree = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Tree\\View\\PageTreeView');
78 $tree->init('AND ' . $permsClause);
79 $tree->tree[] = array('row' => $pidToStart);
80 $tree->buffer_idH = array();
81 $tree->getTree($pidToStart, $depth, '');
82
83 $idH[$pidToStart]['uid'] = $pidToStart;
84 if (count($tree->buffer_idH)) {
85 $idH[$pidToStart]['subrow'] = $tree->buffer_idH;
86 }
87
88 $this->export->setPageTree($idH);
89 }
90
91 /**
92 * Adds records to the export object for a specific page id.
93 *
94 * @param int $pid Page id for which to select records to add
95 * @param array $tables Array of table names to select from
96 * @return void
97 */
98 protected function addRecordsForPid($pid, array $tables) {
99 foreach ($GLOBALS['TCA'] as $table => $value) {
100 if ($table != 'pages' && (in_array($table, $tables) || in_array('_ALL', $tables))) {
101 if ($GLOBALS['BE_USER']->check('tables_select', $table) && !$GLOBALS['TCA'][$table]['ctrl']['is_static']) {
102 $orderBy = $GLOBALS['TCA'][$table]['ctrl']['sortby'] ? 'ORDER BY ' . $GLOBALS['TCA'][$table]['ctrl']['sortby'] : $GLOBALS['TCA'][$table]['ctrl']['default_sortby'];
103 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
104 '*',
105 $table,
106 'pid = ' . (int)$pid . BackendUtility::deleteClause($table),
107 '',
108 $GLOBALS['TYPO3_DB']->stripOrderBy($orderBy)
109 );
110 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
111 $this->export->export_addRecord($table, $row);
112 }
113 }
114 }
115 }
116 }
117
118 }