1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kitodo\Dlf\Tests\Functional\Common; |
4
|
|
|
|
5
|
|
|
use Kitodo\Dlf\Common\Helper; |
6
|
|
|
use Kitodo\Dlf\Tests\Functional\FunctionalTestCase; |
7
|
|
|
use TYPO3\CMS\Core\Localization\LanguageService; |
8
|
|
|
|
9
|
|
|
class HelperTest extends FunctionalTestCase |
10
|
|
|
{ |
11
|
|
|
public function setUp(): void |
12
|
|
|
{ |
13
|
|
|
parent::setUp(); |
14
|
|
|
|
15
|
|
|
$this->importDataSet(__DIR__ . '/../../Fixtures/Common/libraries.xml'); |
|
|
|
|
16
|
|
|
$this->importDataSet(__DIR__ . '/../../Fixtures/Common/metadata.xml'); |
|
|
|
|
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @test |
21
|
|
|
*/ |
22
|
|
|
public function canGetIndexNameFromUid() |
23
|
|
|
{ |
24
|
|
|
// Repeat to make sure caching isn't broken |
25
|
|
|
for ($n = 0; $n < 2; $n++) { |
26
|
|
|
// Good UID, no PID |
27
|
|
|
$this->assertEquals( |
28
|
|
|
'default', |
29
|
|
|
Helper::getIndexNameFromUid(10001, 'tx_dlf_libraries') |
30
|
|
|
); |
31
|
|
|
$this->assertEquals( |
32
|
|
|
'title', |
33
|
|
|
Helper::getIndexNameFromUid(5001, 'tx_dlf_metadata') |
34
|
|
|
); |
35
|
|
|
$this->assertEquals( |
36
|
|
|
'collection', |
37
|
|
|
Helper::getIndexNameFromUid(5002, 'tx_dlf_metadata') |
38
|
|
|
); |
39
|
|
|
|
40
|
|
|
// Good UID, good PID |
41
|
|
|
$this->assertEquals( |
42
|
|
|
'default', |
43
|
|
|
Helper::getIndexNameFromUid(10001, 'tx_dlf_libraries', 20000) |
44
|
|
|
); |
45
|
|
|
$this->assertEquals( |
46
|
|
|
'title', |
47
|
|
|
Helper::getIndexNameFromUid(5001, 'tx_dlf_metadata', 20000) |
48
|
|
|
); |
49
|
|
|
$this->assertEquals( |
50
|
|
|
'collection', |
51
|
|
|
Helper::getIndexNameFromUid(5002, 'tx_dlf_metadata', 20000) |
52
|
|
|
); |
53
|
|
|
|
54
|
|
|
// Good UID, bad PID |
55
|
|
|
$this->assertEquals( |
56
|
|
|
'', |
57
|
|
|
Helper::getIndexNameFromUid(10001, 'tx_dlf_libraries', 123456) |
58
|
|
|
); |
59
|
|
|
|
60
|
|
|
// Bad UID, no PID |
61
|
|
|
$this->assertEquals( |
62
|
|
|
'', |
63
|
|
|
Helper::getIndexNameFromUid(123456, 'tx_dlf_libraries') |
64
|
|
|
); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @test |
70
|
|
|
* @group getLanguageName |
71
|
|
|
*/ |
72
|
|
|
public function canTranslateLanguageNameToEnglish() |
73
|
|
|
{ |
74
|
|
|
// NOTE: This only tests in BE mode |
75
|
|
|
|
76
|
|
|
$GLOBALS['LANG'] = LanguageService::create('default'); |
77
|
|
|
$this->assertEquals('German', Helper::getLanguageName('de')); // ISO 639-1 |
78
|
|
|
$this->assertEquals('German', Helper::getLanguageName('ger')); // ISO 639-2 |
79
|
|
|
$this->assertEquals('abcde', Helper::getLanguageName('abcde')); // doesn't match ISO code regex |
80
|
|
|
$this->assertEquals('abc', Helper::getLanguageName('abc')); // matches ISO code regex, but not an ISO code |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @test |
85
|
|
|
* @group getLanguageName |
86
|
|
|
*/ |
87
|
|
|
public function canTranslateLanguageNameToGerman() |
88
|
|
|
{ |
89
|
|
|
// NOTE: This only tests in BE mode |
90
|
|
|
|
91
|
|
|
$GLOBALS['LANG'] = LanguageService::create('de'); |
92
|
|
|
$this->assertEquals('Deutsch', Helper::getLanguageName('de')); // ISO 639-1 |
93
|
|
|
$this->assertEquals('Deutsch', Helper::getLanguageName('ger')); // ISO 639-2 |
94
|
|
|
$this->assertEquals('abcde', Helper::getLanguageName('abcde')); // doesn't match ISO code regex |
95
|
|
|
$this->assertEquals('abc', Helper::getLanguageName('abc')); // matches ISO code regex, but not an ISO code |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.