-
Notifications
You must be signed in to change notification settings - Fork 638
/
AbstractDataHandlerActionTestCase.php
196 lines (171 loc) · 5.74 KB
/
AbstractDataHandlerActionTestCase.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<?php
namespace TYPO3\CMS\Core\Tests\Functional\DataHandling;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Core\Core\Bootstrap;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\TestingFramework\Core\Functional\Framework\Constraint\RequestSection\DoesNotHaveRecordConstraint;
use TYPO3\TestingFramework\Core\Functional\Framework\Constraint\RequestSection\HasRecordConstraint;
use TYPO3\TestingFramework\Core\Functional\Framework\Constraint\RequestSection\StructureDoesNotHaveRecordConstraint;
use TYPO3\TestingFramework\Core\Functional\Framework\Constraint\RequestSection\StructureHasRecordConstraint;
use TYPO3\TestingFramework\Core\Functional\Framework\DataHandling\ActionService;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
/**
* Functional test for the DataHandler
*/
abstract class AbstractDataHandlerActionTestCase extends FunctionalTestCase
{
const VALUE_BackendUserId = 1;
/**
* @var string
*/
protected $scenarioDataSetDirectory;
/**
* @var string
*/
protected $assertionDataSetDirectory;
/**
* If this value is NULL, log entries are not considered.
* If it's an integer value, the number of log entries is asserted.
*
* @var int|null
*/
protected $expectedErrorLogEntries = 0;
/**
* @var array
*/
protected $testExtensionsToLoad = [
'typo3/sysext/core/Tests/Functional/Fixtures/Extensions/irre_tutorial',
];
/**
* @var array
*/
protected $pathsToLinkInTestInstance = [
'typo3/sysext/core/Tests/Functional/Fixtures/Frontend/AdditionalConfiguration.php' => 'typo3conf/AdditionalConfiguration.php',
];
/**
* @var array
*/
protected $recordIds = [];
/**
* @var ActionService
*/
protected $actionService;
/**
* @var \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
*/
protected $backendUser;
protected function setUp()
{
parent::setUp();
$this->backendUser = $this->setUpBackendUserFromFixture(self::VALUE_BackendUserId);
// By default make tests on live workspace
$this->backendUser->workspace = 0;
$this->actionService = $this->getActionService();
Bootstrap::initializeLanguageObject();
}
protected function tearDown()
{
$this->assertErrorLogEntries();
unset($this->actionService);
unset($this->recordIds);
parent::tearDown();
}
/**
* @return ActionService
*/
protected function getActionService()
{
return GeneralUtility::makeInstance(
ActionService::class
);
}
/**
* @param string $dataSetName
*/
protected function importScenarioDataSet($dataSetName)
{
$fileName = rtrim($this->scenarioDataSetDirectory, '/') . '/' . $dataSetName . '.csv';
$fileName = GeneralUtility::getFileAbsFileName($fileName);
$this->importCSVDataSet($fileName);
}
protected function assertAssertionDataSet($dataSetName)
{
$fileName = rtrim($this->assertionDataSetDirectory, '/') . '/' . $dataSetName . '.csv';
$fileName = GeneralUtility::getFileAbsFileName($fileName);
$this->assertCSVDataSet($fileName);
}
/**
* Asserts correct number of warning and error log entries.
*/
protected function assertErrorLogEntries()
{
if ($this->expectedErrorLogEntries === null) {
return;
}
$queryBuilder = $this->getConnectionPool()
->getQueryBuilderForTable('sys_log');
$queryBuilder->getRestrictions()->removeAll();
$statement = $queryBuilder
->select('*')
->from('sys_log')
->where(
$queryBuilder->expr()->in(
'error',
$queryBuilder->createNamedParameter([1, 2], Connection::PARAM_INT_ARRAY)
)
)
->execute();
$actualErrorLogEntries = $statement->rowCount();
if ($actualErrorLogEntries === $this->expectedErrorLogEntries) {
$this->assertSame($this->expectedErrorLogEntries, $actualErrorLogEntries);
} else {
$failureMessage = 'Expected ' . $this->expectedErrorLogEntries . ' entries in sys_log, but got ' . $actualErrorLogEntries . LF;
while ($entry = $statement->fetch()) {
$entryData = unserialize($entry['log_data']);
$entryMessage = vsprintf($entry['details'], $entryData);
$failureMessage .= '* ' . $entryMessage . LF;
}
$this->fail($failureMessage);
}
}
/**
* @return HasRecordConstraint
*/
protected function getRequestSectionHasRecordConstraint()
{
return new HasRecordConstraint();
}
/**
* @return DoesNotHaveRecordConstraint
*/
protected function getRequestSectionDoesNotHaveRecordConstraint()
{
return new DoesNotHaveRecordConstraint();
}
/**
* @return StructureHasRecordConstraint
*/
protected function getRequestSectionStructureHasRecordConstraint()
{
return new StructureHasRecordConstraint();
}
/**
* @return StructureDoesNotHaveRecordConstraint
*/
protected function getRequestSectionStructureDoesNotHaveRecordConstraint()
{
return new StructureDoesNotHaveRecordConstraint();
}
}