By marvil07 on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
10.2.x
Introduced in version:
10.2.3
Issue links:
Description:
Two new traits have been added for changing the language configuration in tests. These should be used whenever the language configuration form itself is not under test.
LanguageTestTrait, providing methods general tolanguagemodule.ContentTranslationTestTrait, extending the previous trait to makecontent_translationmodule related configuration changes.
Sample usage of LanguageTestTrait
use Drupal\Tests\language\Traits\LanguageTestTrait;
class ExampleTest extends BrowserTestBase {
use LanguageTestTrait;
protected static $modules = [
...
'node',
'language',
...
];
public function testExample() {
...
self::createLanguageFromLangcode('es');
self::enableBundleTranslation('node', 'article');
self::setFieldTranslatable('node', 'article', 'body', TRUE);
...
self::disableBundleTranslation('node', 'article');
...
}
}
Sample usage of ContentTranslationTestTrait
Notice that LanguageTestTrait methods are available on this trait too.
use Drupal\Tests\content_translation\Traits\ContentTranslationTestTrait;
class ExampleTest extends BrowserTestBase {
use ContentTranslationTestTrait;
protected static $modules = [
...
'node',
'content_translation',
...
];
public function testExample() {
...
self::createLanguageFromLangcode('es');
self::enableContentTranslation('node', 'article');
self::setFieldTranslatable('node', 'article', 'body', TRUE);
...
self::disableBundleTranslation('node', 'article');
...
}
}
Impacts:
Module developers