1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* (c) Kitodo. Key to digital objects e.V. <[email protected]> |
5
|
|
|
* |
6
|
|
|
* This file is part of the Kitodo and TYPO3 projects. |
7
|
|
|
* |
8
|
|
|
* @license GNU General Public License version 3 or later. |
9
|
|
|
* For the full copyright and license information, please read the |
10
|
|
|
* LICENSE.txt file that was distributed with this source code. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace Kitodo\Dlf\Tests\Functional; |
14
|
|
|
|
15
|
|
|
use Dotenv\Dotenv; |
16
|
|
|
use GuzzleHttp\Client as HttpClient; |
17
|
|
|
use Kitodo\Dlf\Common\Solr\Solr; |
18
|
|
|
use Symfony\Component\Yaml\Yaml; |
19
|
|
|
use TYPO3\CMS\Core\Localization\LanguageServiceFactory; |
20
|
|
|
use TYPO3\CMS\Core\Utility\ArrayUtility; |
21
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
22
|
|
|
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager; |
23
|
|
|
use TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings; |
24
|
|
|
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Base class for functional test cases. This provides some common configuration |
28
|
|
|
* and collects utility methods for functional tests. |
29
|
|
|
*/ |
30
|
|
|
class FunctionalTestCase extends \TYPO3\TestingFramework\Core\Functional\FunctionalTestCase |
31
|
|
|
{ |
32
|
|
|
protected array $testExtensionsToLoad = [ |
33
|
|
|
'typo3conf/ext/dlf', |
34
|
|
|
]; |
35
|
|
|
|
36
|
|
|
protected array $configurationToUseInTestInstance = [ |
37
|
|
|
'SYS' => [ |
38
|
|
|
'caching' => [ |
39
|
|
|
'cacheConfigurations' => [ |
40
|
|
|
'tx_dlf_doc' => [ |
41
|
|
|
'backend' => \TYPO3\CMS\Core\Cache\Backend\NullBackend::class, |
42
|
|
|
], |
43
|
|
|
], |
44
|
|
|
], |
45
|
|
|
'displayErrors' => '1' |
46
|
|
|
], |
47
|
|
|
'SC_OPTIONS' => [ |
48
|
|
|
'dlf/Classes/Plugin/Toolbox.php' => [] |
49
|
|
|
], |
50
|
|
|
'EXTENSIONS' => [ |
51
|
|
|
'dlf' => [], // = $this->getDlfConfiguration(), set in constructor |
52
|
|
|
], |
53
|
|
|
'FE' => [ |
54
|
|
|
'cacheHash' => [ |
55
|
|
|
'enforceValidation' => false, |
56
|
|
|
], |
57
|
|
|
], |
58
|
|
|
'DB' => [ |
59
|
|
|
'Connections' => [ |
60
|
|
|
'Default' => [ |
61
|
|
|
// TODO: This is taken from the base class, minus "ONLY_FULL_GROUP_BY"; should probably rather be changed in DocumentRepository::getOaiDocumentList |
62
|
|
|
'initCommands' => 'SET SESSION sql_mode = \'STRICT_ALL_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_VALUE_ON_ZERO,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE\';', |
63
|
|
|
], |
64
|
|
|
], |
65
|
|
|
], |
66
|
|
|
]; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* By default, the testing framework wraps responses into a JSON object |
70
|
|
|
* that contains status code etc. as fields. Set this field to true to avoid |
71
|
|
|
* this behavior by not loading the json_response extension. |
72
|
|
|
* |
73
|
|
|
* @var bool |
74
|
|
|
*/ |
75
|
|
|
protected $disableJsonWrappedResponse = false; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @var PersistenceManager |
79
|
|
|
*/ |
80
|
|
|
protected $persistenceManager; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @var string |
84
|
|
|
*/ |
85
|
|
|
protected $baseUrl; |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @var HttpClient |
89
|
|
|
*/ |
90
|
|
|
protected $httpClient; |
91
|
|
|
|
92
|
|
|
public function __construct() |
93
|
|
|
{ |
94
|
|
|
parent::__construct(); |
95
|
|
|
|
96
|
|
|
$this->configurationToUseInTestInstance['EXTENSIONS']['dlf'] = $this->getDlfConfiguration(); |
97
|
|
|
|
98
|
|
|
if ($this->disableJsonWrappedResponse) { |
99
|
|
|
$this->frameworkExtensionsToLoad = array_filter($this->frameworkExtensionsToLoad, function ($ext) { |
|
|
|
|
100
|
|
|
return $ext !== 'Resources/Core/Functional/Extensions/json_response'; |
101
|
|
|
}); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function setUp(): void |
106
|
|
|
{ |
107
|
|
|
parent::setUp(); |
108
|
|
|
|
109
|
|
|
$this->persistenceManager = GeneralUtility::makeInstance(PersistenceManager::class); |
110
|
|
|
|
111
|
|
|
$this->baseUrl = 'http://web:8000/public/typo3temp/var/tests/functional-' . $this->identifier . '/'; |
112
|
|
|
$this->httpClient = new HttpClient([ |
113
|
|
|
'base_uri' => $this->baseUrl . 'index.php', |
114
|
|
|
'http_errors' => false, |
115
|
|
|
]); |
116
|
|
|
|
117
|
|
|
$this->addSiteConfig('dlf-testing'); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
protected function getDlfConfiguration() |
121
|
|
|
{ |
122
|
|
|
$dotenv = Dotenv::createImmutable('/home/runner/work/kitodo-presentation/kitodo-presentation/Build/Test/', 'test.env'); |
123
|
|
|
$dotenv->load(); |
124
|
|
|
|
125
|
|
|
return [ |
126
|
|
|
'general' => [ |
127
|
|
|
'useExternalApisForMetadata' => 0, |
128
|
|
|
'requiredMetadataFields' => 'document_format' |
129
|
|
|
], |
130
|
|
|
'files' => [ |
131
|
|
|
'fileGrpImages' => 'DEFAULT,MAX', |
132
|
|
|
'fileGrpThumbs' => 'THUMBS', |
133
|
|
|
'fileGrpDownload' => 'DOWNLOAD', |
134
|
|
|
'fileGrpFulltext' => 'FULLTEXT', |
135
|
|
|
'fileGrpAudio' => 'AUDIO' |
136
|
|
|
], |
137
|
|
|
'solr' => [ |
138
|
|
|
'host' => getenv('dlfTestingSolrHost'), |
139
|
|
|
'fields' => [ |
140
|
|
|
'autocomplete' => 'autocomplete', |
141
|
|
|
'collection' => 'collection', |
142
|
|
|
'default' => 'default', |
143
|
|
|
'fulltext' => 'fulltext', |
144
|
|
|
'geom' => 'geom', |
145
|
|
|
'id' => 'id', |
146
|
|
|
'license' => 'license', |
147
|
|
|
'location' => 'location', |
148
|
|
|
'page' => 'page', |
149
|
|
|
'partof' => 'partof', |
150
|
|
|
'pid' => 'pid', |
151
|
|
|
'purl' => 'purl', |
152
|
|
|
'recordId' => 'record_id', |
153
|
|
|
'restrictions' => 'restrictions', |
154
|
|
|
'root' => 'root', |
155
|
|
|
'sid' => 'sid', |
156
|
|
|
'terms' => 'terms', |
157
|
|
|
'thumbnail' => 'thumbnail', |
158
|
|
|
'timestamp' => 'timestamp', |
159
|
|
|
'title' => 'title', |
160
|
|
|
'toplevel' => 'toplevel', |
161
|
|
|
'type' => 'type', |
162
|
|
|
'uid' => 'uid', |
163
|
|
|
'urn' => 'urn', |
164
|
|
|
'volume' => 'volume' |
165
|
|
|
] |
166
|
|
|
] |
167
|
|
|
]; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
protected function addSiteConfig($identifier) |
171
|
|
|
{ |
172
|
|
|
$siteConfig = Yaml::parseFile(__DIR__ . '/../Fixtures/siteconfig.yaml'); |
173
|
|
|
$siteConfig['base'] = $this->baseUrl; |
174
|
|
|
$siteConfig['languages'][0]['base'] = $this->baseUrl; |
175
|
|
|
|
176
|
|
|
$siteConfigPath = $this->instancePath . '/typo3conf/sites/' . $identifier; |
177
|
|
|
@mkdir($siteConfigPath, 0775, true); |
|
|
|
|
178
|
|
|
file_put_contents($siteConfigPath . '/config.yaml', Yaml::dump($siteConfig)); |
179
|
|
|
|
180
|
|
|
// refresh site cache (otherwise site config is not found) |
181
|
|
|
$finder = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Site\SiteFinder::class); |
182
|
|
|
$finder->getAllSites(false); // useCache = false |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
protected function initializeRepository(string $className, int $storagePid) |
186
|
|
|
{ |
187
|
|
|
$repository = GeneralUtility::makeInstance($className); |
188
|
|
|
$querySettings = GeneralUtility::makeInstance(Typo3QuerySettings::class); |
189
|
|
|
$querySettings->setStoragePageIds([$storagePid]); |
190
|
|
|
$repository->setDefaultQuerySettings($querySettings); |
191
|
|
|
|
192
|
|
|
return $repository; |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
protected function importSolrDocuments(Solr $solr, string $path) |
196
|
|
|
{ |
197
|
|
|
$jsonDocuments = json_decode(file_get_contents($path), true); |
198
|
|
|
|
199
|
|
|
$updateQuery = $solr->service->createUpdate(); |
200
|
|
|
$documents = array_map(function ($jsonDoc) use ($updateQuery) { |
201
|
|
|
$document = $updateQuery->createDocument(); |
202
|
|
|
foreach ($jsonDoc as $key => $value) { |
203
|
|
|
$document->setField($key, $value); |
|
|
|
|
204
|
|
|
} |
205
|
|
|
if (isset($jsonDoc['collection'])) { |
206
|
|
|
$document->setField('collection_faceting', $jsonDoc['collection']); |
207
|
|
|
} |
208
|
|
|
return $document; |
209
|
|
|
}, $jsonDocuments); |
210
|
|
|
$updateQuery->addDocuments($documents); |
211
|
|
|
$updateQuery->addCommit(); |
212
|
|
|
$solr->service->update($updateQuery); |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
protected function initLanguageService(string $locale) |
216
|
|
|
{ |
217
|
|
|
// create mock backend user and set language |
218
|
|
|
// which is loaded by LanguageServiceFactory as default value in backend mode |
219
|
|
|
$backendUser = GeneralUtility::makeInstance(BackendUserAuthentication::class); |
220
|
|
|
$backendUser->user["lang"] = $locale; |
221
|
|
|
$GLOBALS['BE_USER'] = $backendUser; |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* Assert that $sub is recursively contained within $super. |
226
|
|
|
*/ |
227
|
|
|
protected function assertArrayMatches(array $sub, array $super, string $message = '') |
228
|
|
|
{ |
229
|
|
|
self::assertEquals($sub, ArrayUtility::intersectRecursive($super, $sub), $message); |
230
|
|
|
} |
231
|
|
|
} |
232
|
|
|
|