Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Merge requests
!5616
2575945-43
Code
Review changes
Check out branch
Open in Workspace
Download
Patches
Plain diff
Expand sidebar
Closed
2575945-43
issue/drupal-2575945:2575945-a-new-module
into
11.x
Overview
0
Commits
1
Pipelines
1
Changes
5
Closed
2575945-43
Michael Strelan
requested to merge
issue/drupal-2575945:2575945-a-new-module
into
11.x
Nov 30, 2023
Overview
0
Commits
1
Pipelines
1
Changes
5
Closes
#2575945
0
0
Merge request reports
Compare
11.x
11.x (base)
and
latest version
latest version
f6623ea8
1 commit,
Nov 30, 2023
5 files
+
136
−
4
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
5
core/modules/locale/tests/src/Functional/LocaleTranslationChangeProjectVersionTest.php
0 → 100644
+
86
−
0
View file @ f6623ea8
Edit in single-file editor
Open in Web IDE
<?php
namespace
Drupal\Tests\locale\Functional
;
use
Drupal\Core\StreamWrapper\PublicStream
;
use
Drupal\language\Entity\ConfigurableLanguage
;
/**
* Tests how translations are handled when a project gets updated.
*
* @group locale
*/
class
LocaleTranslationChangeProjectVersionTest
extends
LocaleUpdateBase
{
/**
* {@inheritdoc}
*/
protected
$defaultTheme
=
'stark'
;
/**
* {@inheritdoc}
*/
protected
function
setUp
():
void
{
parent
::
setUp
();
\Drupal
::
moduleHandler
()
->
loadInclude
(
'locale'
,
'inc'
,
'locale.batch'
);
ConfigurableLanguage
::
createFromLangcode
(
'de'
)
->
save
();
\Drupal
::
state
()
->
set
(
'locale.test_projects_alter'
,
TRUE
);
\Drupal
::
state
()
->
set
(
'locale.remove_core_project'
,
TRUE
);
// Setup the environment.
$config
=
$this
->
config
(
'locale.settings'
);
$public_path
=
PublicStream
::
basePath
();
$this
->
setTranslationsDirectory
(
$public_path
.
'/local'
);
$config
->
set
(
'translation.default_filename'
,
'%project-%version.%language._po'
)
->
set
(
'translation.use_source'
,
LOCALE_TRANSLATION_USE_SOURCE_LOCAL
)
->
save
();
// This test uses .po files for the old translation file instead of the ._po
// files because locale_translate_get_interface_translation_files() (used to
// delete old translation files) only works with .po files.
// The new translation file uses _po.
// Old version: 8.x-1.0; New version: 8.x-1.1.
$this
->
makePoFile
(
'remote/all/contrib_module_one'
,
'contrib_module_one-8.x-1.0.de.po'
,
$this
->
timestampOld
,
[]);
$this
->
makePoFile
(
'remote/all/contrib_module_one'
,
'contrib_module_one-8.x-1.1.de._po'
,
$this
->
timestampNew
,
[]);
$this
->
makePoFile
(
'local'
,
'contrib_module_one-8.x-1.0.de.po'
,
$this
->
timestampOld
,
[]);
// Initialize the projects status and change the project version to the old
// version. This makes the code update the module translation to the new
// version when the (batch) update script is triggered.
$status
=
locale_translation_get_status
();
$status
[
'contrib_module_one'
][
'de'
]
->
version
=
'8.x-1.0'
;
\Drupal
::
keyValue
(
'locale.translation_status'
)
->
setMultiple
(
$status
);
}
/**
* Tests update translations when project version changes.
*/
public
function
testUpdateImportSourceRemote
()
{
// Verify that the project status has the old version.
$status
=
locale_translation_get_status
([
'contrib_module_one'
]);
$this
->
assertEquals
(
'8.x-1.0'
,
$status
[
'contrib_module_one'
][
'de'
]
->
version
);
// Verify that the old translation file exists and the new does not exist.
$this
->
assertFileExists
(
'translations://contrib_module_one-8.x-1.0.de.po'
);
$this
->
assertFileDoesNotExist
(
'translations://contrib_module_one-8.x-1.1.de._po'
);
// Run batch tasks.
$context
=
[];
locale_translation_batch_version_check
(
'contrib_module_one'
,
'de'
,
$context
);
locale_translation_batch_status_check
(
'contrib_module_one'
,
'de'
,
[],
$context
);
locale_translation_batch_fetch_download
(
'contrib_module_one'
,
'de'
,
$context
);
// Verify that the project status has the new version.
$status
=
locale_translation_get_status
([
'contrib_module_one'
]);
$this
->
assertEquals
(
'8.x-1.1'
,
$status
[
'contrib_module_one'
][
'de'
]
->
version
);
// Verify that the old translation file was removed and the new was
// downloaded.
$this
->
assertFileDoesNotExist
(
'translations://contrib_module_one-8.x-1.0.de.po'
);
$this
->
assertFileExists
(
'translations://contrib_module_one-8.x-1.1.de._po'
);
}
}
Loading