[!!!][TASK] Extract testing framework for TYPO3
[Packages/TYPO3.CMS.git] / typo3 / sysext / recycler / Tests / Functional / Recycle / AbstractRecycleTestCase.php
1 <?php
2 namespace TYPO3\CMS\Recycler\Tests\Functional\Recycle;
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
19 /**
20 * Functional test for the Export
21 */
22 abstract class AbstractRecycleTestCase extends \TYPO3\CMS\Components\TestingFramework\Core\FunctionalTestCase
23 {
24 /**
25 * @var array
26 */
27 protected $coreExtensionsToLoad = ['recycler'];
28
29 /**
30 * The fixture which is used when initializing a backend user
31 *
32 * @var string
33 */
34 protected $backendUserFixture = 'typo3/sysext/recycler/Tests/Functional/Fixtures/Database/be_users.xml';
35
36 /**
37 * Set up for set up the backend user, initialize the language object
38 * and creating the Export instance
39 *
40 * @return void
41 */
42 protected function setUp()
43 {
44 parent::setUp();
45 $this->importDataSet(__DIR__ . '/../Fixtures/Database/be_groups.xml');
46 \TYPO3\CMS\Core\Core\Bootstrap::getInstance()->initializeLanguageObject();
47 }
48
49 /**
50 * Retrieves deleted pages using the recycler domain model "deletedRecords" class.
51 *
52 * @param int $pageUid
53 * @param int $depth
54 * @return array Retrieved deleted records
55 */
56 protected function getDeletedPages($pageUid, $depth = 0)
57 {
58 /** @var $deletedRecords \TYPO3\CMS\Recycler\Domain\Model\DeletedRecords */
59 $deletedRecords = GeneralUtility::makeInstance(\TYPO3\CMS\Recycler\Domain\Model\DeletedRecords::class);
60 $deletedRecords->loadData($pageUid, 'pages', $depth);
61 return $deletedRecords->getDeletedRows();
62 }
63
64 /**
65 * Retrieves a deleted content elment using the recycler domain model "deletedRecords" class.
66 *
67 * @param int $contentUid
68 * @return array Retrieved deleted records
69 */
70 protected function getDeletedContent($contentUid)
71 {
72 /** @var $deletedRecords \TYPO3\CMS\Recycler\Domain\Model\DeletedRecords */
73 $deletedRecords = GeneralUtility::makeInstance(\TYPO3\CMS\Recycler\Domain\Model\DeletedRecords::class);
74 $deletedRecords->loadData($contentUid, 'tt_content', 0);
75 return $deletedRecords->getDeletedRows();
76 }
77
78 /**
79 * Loads a data set represented as XML and returns it as array.
80 *
81 * @param string $path Absolute path to the XML file containing the data set to load
82 * @return array The records loaded from the data set
83 * @throws \Exception
84 */
85 protected function loadDataSet($path)
86 {
87 if (!is_file($path)) {
88 throw new \Exception(
89 'Fixture file ' . $path . ' not found',
90 1476109709
91 );
92 }
93
94 $data = [];
95 $fileContent = file_get_contents($path);
96 // Disables the functionality to allow external entities to be loaded when parsing the XML, must be kept
97 $previousValueOfEntityLoader = libxml_disable_entity_loader(true);
98 $xml = simplexml_load_string($fileContent);
99 libxml_disable_entity_loader($previousValueOfEntityLoader);
100
101 /** @var $table \SimpleXMLElement */
102 foreach ($xml->children() as $table) {
103 $record = [];
104
105 /** @var $column \SimpleXMLElement */
106 foreach ($table->children() as $column) {
107 $columnName = $column->getName();
108 $columnValue = null;
109
110 if (isset($column['ref'])) {
111 $columnValue = explode('#', $column['ref']);
112 } elseif (isset($column['is-NULL']) && ($column['is-NULL'] === 'yes')) {
113 $columnValue = null;
114 } else {
115 $columnValue = (string)$table->$columnName;
116 }
117
118 $record[$columnName] = $columnValue;
119 }
120
121 $tableName = $table->getName();
122 $data[$tableName][] = $record;
123 }
124 return $data;
125 }
126 }