Skip to content

Commit

Permalink
test(SLB-269): test case for translation strings from drupal
Browse files Browse the repository at this point in the history
  • Loading branch information
pmelab committed Feb 16, 2024
1 parent 50b6fac commit 0f830dd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
26 changes: 26 additions & 0 deletions packages/drupal/test_content/import.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
use AmazeeLabs\DefaultContent\Import;
use Drupal\Component\Serialization\Yaml;
use Drupal\locale\StringStorageInterface;
use Drupal\webform\Entity\Webform;

if (PHP_SAPI !== 'cli') {
Expand All @@ -13,3 +14,28 @@
foreach (glob(__DIR__ . '/webforms/*.yml') as $file) {
Webform::create(Yaml::decode(file_get_contents($file)))->save();
}

// Create an example string translation for test cases.
$stringStorage = \Drupal::service('locale.storage');
if ($stringStorage instanceof StringStorageInterface) {
/** @var \Drupal\locale\StringInterface $strings */
$strings = $stringStorage->getStrings([
'source' => 'Company Name',
'context' => 'gatsby',
]);
$lid = 0;
if (empty($strings)) {
$lid = $stringStorage->createString([
'source' => 'Company name',
'context' => 'gatsby',
])->save()->lid;
}
else {
$lid = $strings[0]->lid;
}
$stringStorage->createTranslation([
'lid' => $lid,
'language' => 'de',
'translation' => 'Drupal Company',
])->save();
}
5 changes: 4 additions & 1 deletion tests/e2e/specs/translatables.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ test('translatable strings', async ({ page }) => {
footer.getByText('© 2024 Random Company. All rights reserved.'),
).toBeVisible();
await page.getByRole('link', { name: 'de' }).click();
// Drupal provides the "Drupal Company" translation for the "Company Name" string.
// Decap provides the "Random Company" translation for the "Company Name" string,
// but Drupal translations have higher precedence.
await expect(
footer.getByText('© 2024 Random Company. Alle Rechte vorbehalten.'),
footer.getByText('© 2024 Drupal Company. Alle Rechte vorbehalten.'),
).toBeVisible();
});

0 comments on commit 0f830dd

Please sign in to comment.