[TASK] Move CSV fixtures handling to FunctionalTestCase
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Functional / DataHandling / AbstractDataHandlerActionTestCase.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Functional\DataHandling;
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 DataHandler
21 */
22 abstract class AbstractDataHandlerActionTestCase extends \TYPO3\CMS\Core\Tests\FunctionalTestCase
23 {
24 const VALUE_BackendUserId = 1;
25
26 /**
27 * @var string
28 */
29 protected $scenarioDataSetDirectory;
30
31 /**
32 * @var string
33 */
34 protected $assertionDataSetDirectory;
35
36 /**
37 * If this value is NULL, log entries are not considered.
38 * If it's an integer value, the number of log entries is asserted.
39 *
40 * @var NULL|int
41 */
42 protected $expectedErrorLogEntries = 0;
43
44 /**
45 * @var array
46 */
47 protected $testExtensionsToLoad = [
48 'typo3/sysext/core/Tests/Functional/Fixtures/Extensions/irre_tutorial',
49 ];
50
51 /**
52 * @var array
53 */
54 protected $pathsToLinkInTestInstance = [
55 'typo3/sysext/core/Tests/Functional/Fixtures/Frontend/AdditionalConfiguration.php' => 'typo3conf/AdditionalConfiguration.php',
56 ];
57
58 /**
59 * @var array
60 */
61 protected $recordIds = [];
62
63 /**
64 * @var \TYPO3\CMS\Core\Tests\Functional\DataHandling\Framework\ActionService
65 */
66 protected $actionService;
67
68 /**
69 * @var \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
70 */
71 protected $backendUser;
72
73 protected function setUp()
74 {
75 parent::setUp();
76
77 $this->backendUser = $this->setUpBackendUserFromFixture(self::VALUE_BackendUserId);
78 // By default make tests on live workspace
79 $this->backendUser->workspace = 0;
80
81 $this->actionService = $this->getActionService();
82 \TYPO3\CMS\Core\Core\Bootstrap::getInstance()->initializeLanguageObject();
83 }
84
85 protected function tearDown()
86 {
87 $this->assertErrorLogEntries();
88 unset($this->actionService);
89 unset($this->recordIds);
90 parent::tearDown();
91 }
92
93 /**
94 * @return \TYPO3\CMS\Core\Tests\Functional\DataHandling\Framework\ActionService
95 */
96 protected function getActionService()
97 {
98 return GeneralUtility::makeInstance(
99 \TYPO3\CMS\Core\Tests\Functional\DataHandling\Framework\ActionService::class
100 );
101 }
102
103 /**
104 * @param string $dataSetName
105 */
106 protected function importScenarioDataSet($dataSetName)
107 {
108 $fileName = rtrim($this->scenarioDataSetDirectory, '/') . '/' . $dataSetName . '.csv';
109 $fileName = GeneralUtility::getFileAbsFileName($fileName);
110 $this->importCSVDataSet($fileName);
111 }
112
113 protected function assertAssertionDataSet($dataSetName)
114 {
115 $fileName = rtrim($this->assertionDataSetDirectory, '/') . '/' . $dataSetName . '.csv';
116 $fileName = GeneralUtility::getFileAbsFileName($fileName);
117 $this->assertCSVDataSet($fileName);
118 }
119
120 /**
121 * Asserts correct number of warning and error log entries.
122 *
123 * @return void
124 */
125 protected function assertErrorLogEntries()
126 {
127 if ($this->expectedErrorLogEntries === null) {
128 return;
129 }
130 $errorLogEntries = $this->getDatabaseConnection()->exec_SELECTgetRows('*', 'sys_log', 'error IN (1,2)');
131 $actualErrorLogEntries = count($errorLogEntries);
132 if ($actualErrorLogEntries === $this->expectedErrorLogEntries) {
133 $this->assertSame($this->expectedErrorLogEntries, $actualErrorLogEntries);
134 } else {
135 $failureMessage = 'Expected ' . $this->expectedErrorLogEntries . ' entries in sys_log, but got ' . $actualErrorLogEntries . LF;
136 foreach ($errorLogEntries as $entry) {
137 $entryData = unserialize($entry['log_data']);
138 $entryMessage = vsprintf($entry['details'], $entryData);
139 $failureMessage .= '* ' . $entryMessage . LF;
140 }
141 $this->fail($failureMessage);
142 }
143 }
144
145 /**
146 * @return \TYPO3\CMS\Core\Tests\Functional\Framework\Constraint\RequestSection\HasRecordConstraint
147 */
148 protected function getRequestSectionHasRecordConstraint()
149 {
150 return new \TYPO3\CMS\Core\Tests\Functional\Framework\Constraint\RequestSection\HasRecordConstraint();
151 }
152
153 /**
154 * @return \TYPO3\CMS\Core\Tests\Functional\Framework\Constraint\RequestSection\DoesNotHaveRecordConstraint
155 */
156 protected function getRequestSectionDoesNotHaveRecordConstraint()
157 {
158 return new \TYPO3\CMS\Core\Tests\Functional\Framework\Constraint\RequestSection\DoesNotHaveRecordConstraint();
159 }
160
161 /**
162 * @return \TYPO3\CMS\Core\Tests\Functional\Framework\Constraint\RequestSection\StructureHasRecordConstraint
163 */
164 protected function getRequestSectionStructureHasRecordConstraint()
165 {
166 return new \TYPO3\CMS\Core\Tests\Functional\Framework\Constraint\RequestSection\StructureHasRecordConstraint();
167 }
168
169 /**
170 * @return \TYPO3\CMS\Core\Tests\Functional\Framework\Constraint\RequestSection\StructureDoesNotHaveRecordConstraint
171 */
172 protected function getRequestSectionStructureDoesNotHaveRecordConstraint()
173 {
174 return new \TYPO3\CMS\Core\Tests\Functional\Framework\Constraint\RequestSection\StructureDoesNotHaveRecordConstraint();
175 }
176 }