Skip to content

Commit a75e5cf

Browse files
committed
[TASK] Add tests for page and b13/container translation
Beside a quite big testing setup, the extension did not test basic page translations and translation tests with b13/container activated. Due to this lack of missing translation tests, issues where encountered, which could be avoided if tests where given. This commit adds tests for three things: 1. Basic page translation 2. Translation of added l10n_mode fields 3. Translation of content elements inside b13/container
1 parent da13ab1 commit a75e5cf

11 files changed

Lines changed: 341 additions & 4 deletions

File tree

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace WebVision\Deepltranslate\Core\Tests\Functional\Container;
6+
7+
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
8+
use PHPUnit\Framework\Attributes\Test;
9+
use TYPO3\CMS\Core\DataHandling\DataHandler;
10+
use TYPO3\CMS\Core\Localization\LanguageServiceFactory;
11+
use TYPO3\CMS\Core\Utility\GeneralUtility;
12+
use WebVision\Deepltranslate\Core\Tests\Functional\AbstractDeepLTestCase;
13+
use WebVision\Deepltranslate\Core\Tests\Functional\Fixtures\Traits\SiteBasedTestTrait;
14+
15+
final class ContentElementsInContainerTest extends AbstractDeepLTestCase
16+
{
17+
use SiteBasedTestTrait;
18+
19+
/**
20+
* @var non-empty-string[]
21+
*/
22+
protected array $testExtensionsToLoad = [
23+
'b13/container',
24+
'web-vision/deepltranslate-core',
25+
__DIR__ . '/../Fixtures/Extensions/test_services_override',
26+
__DIR__ . '/Fixtures/Extensions/test_container',
27+
];
28+
29+
protected const LANGUAGE_PRESETS = [
30+
'EN' => [
31+
'id' => 0,
32+
'title' => 'English',
33+
'locale' => 'en_US.UTF-8',
34+
'iso' => 'en',
35+
'hrefLang' => 'en-US',
36+
'direction' => '',
37+
'custom' => [
38+
'deeplTargetLanguage' => '',
39+
],
40+
],
41+
'DE' => [
42+
'id' => 2,
43+
'title' => 'Deutsch',
44+
'locale' => 'de_DE',
45+
'iso' => 'de',
46+
'hrefLang' => 'de-DE',
47+
'direction' => '',
48+
'custom' => [
49+
'deeplTargetLanguage' => 'DE',
50+
],
51+
],
52+
'EB' => [
53+
'id' => 3,
54+
'title' => 'Britisch',
55+
'locale' => 'en_GB',
56+
'iso' => 'eb',
57+
'hrefLang' => 'en-GB',
58+
'direction' => '',
59+
'custom' => [
60+
'deeplTargetLanguage' => 'EN-GB',
61+
],
62+
],
63+
'BS' => [
64+
'id' => 4,
65+
'title' => 'Bosnian',
66+
'locale' => 'bs_BA.utf8',
67+
'iso' => 'bs',
68+
'hrefLang' => 'bs',
69+
'direction' => '',
70+
'custom' => [
71+
'deeplTargetLanguage' => '',
72+
],
73+
],
74+
];
75+
76+
protected function setUp(): void
77+
{
78+
$this->configurationToUseInTestInstance = array_merge(
79+
$this->configurationToUseInTestInstance,
80+
require __DIR__ . '/../Fixtures/ExtensionConfig.php'
81+
);
82+
83+
parent::setUp();
84+
85+
$this->importCSVDataSet(__DIR__ . '/Fixtures/page_with_container.csv');
86+
$this->writeSiteConfiguration(
87+
'acme',
88+
$this->buildSiteConfiguration(1, '/', 'Home'),
89+
[
90+
$this->buildDefaultLanguageConfiguration('EN', '/'),
91+
$this->buildLanguageConfiguration('EB', '/eb/', ['EN'], 'strict'),
92+
$this->buildLanguageConfiguration('DE', '/de/', ['EN'], 'strict'),
93+
$this->buildLanguageConfiguration('BS', '/bs/', ['EN'], 'strict'),
94+
]
95+
);
96+
$this->setUpFrontendRootPage(1, [], []);
97+
98+
$this->setUpBackendUser(1);
99+
100+
$GLOBALS['LANG'] = GeneralUtility::makeInstance(LanguageServiceFactory::class)->createFromUserPreferences($GLOBALS['BE_USER']);
101+
}
102+
103+
#[Test]
104+
#[IgnoreDeprecations]
105+
public function containerAndInlineElementsAreTranslated(): void
106+
{
107+
$dataHandler = GeneralUtility::makeInstance(DataHandler::class);
108+
$cmdMap = [
109+
'tt_content' => [
110+
2 => [
111+
'deepltranslate' => 2,
112+
],
113+
],
114+
];
115+
116+
$dataHandler->start([], $cmdMap);
117+
$dataHandler->process_cmdmap();
118+
119+
static::assertEmpty($dataHandler->errorLog);
120+
self::assertCSVDataSet(__DIR__ . '/Fixtures/Result/container_translated.csv');
121+
}
122+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
use B13\Container\Tca\ContainerConfiguration;
4+
use B13\Container\Tca\Registry;
5+
use TYPO3\CMS\Core\Utility\GeneralUtility;
6+
7+
(static function (): void {
8+
GeneralUtility::makeInstance(Registry::class)->configureContainer(
9+
(new ContainerConfiguration(
10+
'container-50-50',
11+
'50-50 Container',
12+
'50-50 Container for testing purposes',
13+
[
14+
[
15+
[
16+
'name' => '50',
17+
'colPos' => 100,
18+
],
19+
[
20+
'name' => '50',
21+
'colPos' => 101,
22+
],
23+
],
24+
]
25+
))
26+
->setIcon('content-container-columns-2')
27+
->setSaveAndCloseInNewContentElementWizard(false)
28+
);
29+
})();
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "web-vision/test-container",
3+
"type": "typo3-cms-extension",
4+
"description": "Testing extension for Content elements within containers",
5+
"license": [
6+
"GPL-2.0-or-later"
7+
],
8+
"require": {
9+
"b13/container": "*",
10+
"typo3/cms-core": "*",
11+
"web-vision/deepltranslate-core": "*"
12+
},
13+
"extra":{
14+
"typo3/cms": {
15+
"extension-key": "test_container"
16+
}
17+
}
18+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
tt_content
2+
,uid,pid,header,CType,colPos,tx_container_parent,sys_language_uid,l18n_parent
3+
,2,1,"proton beam","container-50-50",0,0,0,0
4+
,3,1,"proton beam","text",100,2,0,0
5+
,4,1,"Protonenstrahl","container-50-50",0,0,2,2
6+
,5,1,"Protonenstrahl","text",100,2,2,3
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"be_users"
2+
,"uid","pid","tstamp","username","password","admin","disable","starttime","endtime","options","crdate","workspace_perms","deleted","TSconfig","lastlogin","workspace_id"
3+
# The password is "password"
4+
,1,0,1366642540,"admin","$1$tCrlLajZ$C0sikFQQ3SWaFAZ1Me0Z/1",1,0,0,0,0,1366642540,1,0,,1371033743,0
5+
pages
6+
,uid,pid,doktype,is_siteroot,sys_language_uid,l10n_parent,l10n_source,title,slug
7+
,1,0,1,1,0,0,0,"Home","/"
8+
,2,0,1,1,2,1,1,"Startseite","/"
9+
tt_content
10+
,uid,pid,header,CType,colPos,tx_container_parent,sys_language_uid
11+
,2,1,"proton beam","container-50-50",0,0,0
12+
,3,1,"proton beam","text",100,2,0
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pages,,,,,
2-
,"uid","pid","title","sys_language_uid","slug"
3-
,1,0,"Deepl-Functional-Test",0,"/"
4-
1+
pages
2+
,"uid","pid","title","subtitle","sys_language_uid","slug","nav_title","description"
3+
,1,0,"Deepl-Functional-Test","",0,"/","",""
4+
,3,1,"proton beam","proton beam",0,"/proton-beam","proton beam","proton beam"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
3+
(static function (): void {
4+
$GLOBALS['TCA']['pages']['columns']['nav_title']['l10n_mode'] = 'prefixLangTitle';
5+
$GLOBALS['TCA']['pages']['columns']['title']['config']['type'] = 'text';
6+
})();
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "web-vision/test-tca-override",
3+
"type": "typo3-cms-extension",
4+
"description": "Testing extension for TCA overrides in DeepL translate",
5+
"license": [
6+
"GPL-2.0-or-later"
7+
],
8+
"require": {
9+
"typo3/cms-core": "*",
10+
"web-vision/deepltranslate-core": "*"
11+
},
12+
"extra":{
13+
"typo3/cms": {
14+
"extension-key": "test_tca_override"
15+
}
16+
}
17+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
(static function (): void {})();
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pages
2+
,"uid","pid","title","subtitle","sys_language_uid","slug","nav_title","description","l10n_parent"
3+
,1,0,"Deepl-Functional-Test","",0,"/","","",0
4+
,3,1,"proton beam","proton beam",0,"/proton-beam","proton beam","proton beam",0
5+
,4,1,"Protonenstrahl","Protonenstrahl",2,"/protonenstrahl","Protonenstrahl","Protonenstrahl",3

0 commit comments

Comments
 (0)