TYPO3 CMS  TYPO3_7-6
AbstractRecycleTestCase.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 
18 
23 {
27  protected $coreExtensionsToLoad = ['recycler'];
28 
34  protected $backendUserFixture = 'typo3/sysext/recycler/Tests/Functional/Fixtures/Database/be_users.xml';
35 
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 
56  protected function getDeletedPages($pageUid, $depth = 0)
57  {
59  $deletedRecords = GeneralUtility::makeInstance(\TYPO3\CMS\Recycler\Domain\Model\DeletedRecords::class);
60  $deletedRecords->loadData($pageUid, 'pages', $depth);
61  return $deletedRecords->getDeletedRows();
62  }
63 
70  protected function getDeletedContent($contentUid)
71  {
73  $deletedRecords = GeneralUtility::makeInstance(\TYPO3\CMS\Recycler\Domain\Model\DeletedRecords::class);
74  $deletedRecords->loadData($contentUid, 'tt_content', 0);
75  return $deletedRecords->getDeletedRows();
76  }
77 
85  protected function loadDataSet($path)
86  {
87  if (!is_file($path)) {
88  throw new \Exception(
89  'Fixture file ' . $path . ' not found',
90  1376746261
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 
102  foreach ($xml->children() as $table) {
103  $record = [];
104 
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 }