1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kitodo\Dlf\Tests\Functional; |
4
|
|
|
|
5
|
|
|
use GuzzleHttp\Client as HttpClient; |
6
|
|
|
use Kitodo\Dlf\Common\Solr; |
7
|
|
|
use Symfony\Component\Yaml\Yaml; |
8
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
9
|
|
|
use TYPO3\CMS\Extbase\Object\ObjectManager; |
10
|
|
|
use TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Base class for functional test cases. This provides some common configuration |
14
|
|
|
* and collects utility methods for functional tests. |
15
|
|
|
*/ |
16
|
|
|
class FunctionalTestCase extends \TYPO3\TestingFramework\Core\Functional\FunctionalTestCase |
17
|
|
|
{ |
18
|
|
|
protected $testExtensionsToLoad = [ |
19
|
|
|
'typo3conf/ext/dlf', |
20
|
|
|
]; |
21
|
|
|
|
22
|
|
|
protected $configurationToUseInTestInstance = [ |
23
|
|
|
'SYS' => [ |
24
|
|
|
'caching' => [ |
25
|
|
|
'cacheConfigurations' => [ |
26
|
|
|
'tx_dlf_doc' => [ |
27
|
|
|
'backend' => \TYPO3\CMS\Core\Cache\Backend\NullBackend::class, |
28
|
|
|
], |
29
|
|
|
], |
30
|
|
|
], |
31
|
|
|
], |
32
|
|
|
'EXTENSIONS' => [ |
33
|
|
|
'dlf' => [], // = $this->getDlfConfiguration(), set in constructor |
34
|
|
|
], |
35
|
|
|
'DB' => [ |
36
|
|
|
'Connections' => [ |
37
|
|
|
'Default' => [ |
38
|
|
|
// TODO: This is taken from the base class, minus "ONLY_FULL_GROUP_BY"; should probably rather be changed in DocumentRepository::getOaiDocumentList |
39
|
|
|
'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\';', |
40
|
|
|
], |
41
|
|
|
], |
42
|
|
|
], |
43
|
|
|
]; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* By default, the testing framework wraps responses into a JSON object |
47
|
|
|
* that contains status code etc. as fields. Set this field to true to avoid |
48
|
|
|
* this behavior by not loading the json_response extension. |
49
|
|
|
* |
50
|
|
|
* @var bool |
51
|
|
|
*/ |
52
|
|
|
protected $disableJsonWrappedResponse = false; |
53
|
|
|
|
54
|
|
|
/** @var ObjectManager */ |
55
|
|
|
protected $objectManager; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @var string |
59
|
|
|
*/ |
60
|
|
|
protected $baseUrl; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @var HttpClient |
64
|
|
|
*/ |
65
|
|
|
protected $httpClient; |
66
|
|
|
|
67
|
|
|
public function __construct() |
68
|
|
|
{ |
69
|
|
|
parent::__construct(); |
70
|
|
|
|
71
|
|
|
$this->configurationToUseInTestInstance['EXTENSIONS']['dlf'] = $this->getDlfConfiguration(); |
72
|
|
|
|
73
|
|
|
if ($this->disableJsonWrappedResponse) { |
74
|
|
|
$this->frameworkExtensionsToLoad = array_filter($this->frameworkExtensionsToLoad, function ($ext) { |
|
|
|
|
75
|
|
|
return $ext !== 'Resources/Core/Functional/Extensions/json_response'; |
76
|
|
|
}); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function setUp(): void |
81
|
|
|
{ |
82
|
|
|
parent::setUp(); |
83
|
|
|
|
84
|
|
|
$this->objectManager = GeneralUtility::makeInstance(ObjectManager::class); |
85
|
|
|
|
86
|
|
|
$this->baseUrl = 'http://web:8000/public/typo3temp/var/tests/functional-' . $this->identifier . '/'; |
87
|
|
|
$this->httpClient = new HttpClient([ |
88
|
|
|
'base_uri' => $this->baseUrl, |
89
|
|
|
'http_errors' => false, |
90
|
|
|
]); |
91
|
|
|
|
92
|
|
|
$this->addSiteConfig('dlf-testing', $this->baseUrl); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
protected function getDlfConfiguration() |
96
|
|
|
{ |
97
|
|
|
return [ |
98
|
|
|
'solrFieldAutocomplete' => 'autocomplete', |
99
|
|
|
'solrFieldCollection' => 'collection', |
100
|
|
|
'solrFieldDefault' => 'default', |
101
|
|
|
'solrFieldFulltext' => 'fulltext', |
102
|
|
|
'solrFieldGeom' => 'geom', |
103
|
|
|
'solrFieldId' => 'id', |
104
|
|
|
'solrFieldLicense' => 'license', |
105
|
|
|
'solrFieldLocation' => 'location', |
106
|
|
|
'solrFieldPage' => 'page', |
107
|
|
|
'solrFieldPartof' => 'partof', |
108
|
|
|
'solrFieldPid' => 'pid', |
109
|
|
|
'solrFieldPurl' => 'purl', |
110
|
|
|
'solrFieldRecordId' => 'record_id', |
111
|
|
|
'solrFieldRestrictions' => 'restrictions', |
112
|
|
|
'solrFieldRoot' => 'root', |
113
|
|
|
'solrFieldSid' => 'sid', |
114
|
|
|
'solrFieldTerms' => 'terms', |
115
|
|
|
'solrFieldThumbnail' => 'thumbnail', |
116
|
|
|
'solrFieldTimestamp' => 'timestamp', |
117
|
|
|
'solrFieldTitle' => 'title', |
118
|
|
|
'solrFieldToplevel' => 'toplevel', |
119
|
|
|
'solrFieldType' => 'type', |
120
|
|
|
'solrFieldUid' => 'uid', |
121
|
|
|
'solrFieldUrn' => 'urn', |
122
|
|
|
'solrFieldVolume' => 'volume', |
123
|
|
|
|
124
|
|
|
'solrHost' => getenv('dlfTestingSolrHost'), |
125
|
|
|
]; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
protected function addSiteConfig($identifier, $baseUrl) |
129
|
|
|
{ |
130
|
|
|
$siteConfig = Yaml::parseFile(__DIR__ . '/../Fixtures/siteconfig.yaml'); |
131
|
|
|
$siteConfig['base'] = $baseUrl; |
132
|
|
|
$siteConfig['languages'][0]['base'] = $baseUrl; |
133
|
|
|
|
134
|
|
|
$siteConfigPath = $this->instancePath . '/typo3conf/sites/' . $identifier; |
135
|
|
|
@mkdir($siteConfigPath, 0775, true); |
|
|
|
|
136
|
|
|
file_put_contents($siteConfigPath . '/config.yaml', Yaml::dump($siteConfig)); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
protected function initializeRepository(string $className, int $storagePid) |
140
|
|
|
{ |
141
|
|
|
$repository = $this->objectManager->get($className); |
|
|
|
|
142
|
|
|
|
143
|
|
|
$querySettings = $this->objectManager->get(Typo3QuerySettings::class); |
|
|
|
|
144
|
|
|
$querySettings->setStoragePageIds([$storagePid]); |
145
|
|
|
$repository->setDefaultQuerySettings($querySettings); |
146
|
|
|
|
147
|
|
|
return $repository; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
protected function importSolrDocuments(Solr $solr, string $path) |
151
|
|
|
{ |
152
|
|
|
$jsonDocuments = json_decode(file_get_contents($path), true); |
153
|
|
|
|
154
|
|
|
$updateQuery = $solr->service->createUpdate(); |
155
|
|
|
$documents = array_map(function ($jsonDoc) use ($updateQuery) { |
156
|
|
|
$document = $updateQuery->createDocument(); |
157
|
|
|
foreach ($jsonDoc as $key => $value) { |
158
|
|
|
$document->setField($key, $value); |
|
|
|
|
159
|
|
|
} |
160
|
|
|
if (isset($jsonDoc['collection'])) { |
161
|
|
|
$document->setField('collection_faceting', $jsonDoc['collection']); |
162
|
|
|
} |
163
|
|
|
return $document; |
164
|
|
|
}, $jsonDocuments); |
165
|
|
|
$updateQuery->addDocuments($documents); |
166
|
|
|
$updateQuery->addCommit(); |
167
|
|
|
$solr->service->update($updateQuery); |
168
|
|
|
} |
169
|
|
|
} |
170
|
|
|
|