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