LocaleTranslatedSchemaDefinitionTest.php in Drupal 9
File
core/modules/locale/tests/src/Functional/LocaleTranslatedSchemaDefinitionTest.php
View source
<?php
namespace Drupal\Tests\locale\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\RequirementsPageTrait;
class LocaleTranslatedSchemaDefinitionTest extends BrowserTestBase {
use RequirementsPageTrait;
protected static $modules = [
'language',
'locale',
'node',
];
protected $defaultTheme = 'classy';
protected function setUp() : void {
parent::setUp();
ConfigurableLanguage::createFromLangcode('fr')
->save();
$this
->config('system.site')
->set('default_langcode', 'fr')
->save();
$this
->resetAll();
}
public function testTranslatedSchemaDefinition() {
$stringStorage = \Drupal::service('locale.storage');
$source = $stringStorage
->createString([
'source' => 'Revision ID',
])
->save();
$stringStorage
->createTranslation([
'lid' => $source->lid,
'language' => 'fr',
'translation' => 'Translated Revision ID',
])
->save();
$this
->assertEquals('Translated Revision ID', \Drupal::service('entity_field.manager')
->getBaseFieldDefinitions('node')['vid']
->getLabel());
$this
->assertFalse(\Drupal::service('entity.definition_update_manager')
->needsUpdates());
}
public function testTranslatedUpdate() {
$user = $this
->drupalCreateUser([
'administer software updates',
]);
$this
->drupalLogin($user);
$update_url = $GLOBALS['base_url'] . '/update.php';
$this
->drupalGet($update_url, [
'external' => TRUE,
]);
$stringStorage = \Drupal::service('locale.storage');
$sources = $stringStorage
->getStrings();
foreach ($sources as $source) {
$stringStorage
->createTranslation([
'lid' => $source->lid,
'language' => 'fr',
'translation' => $this
->randomMachineName(100),
])
->save();
}
$this
->drupalGet($update_url . '/selection', [
'external' => TRUE,
]);
$this
->updateRequirementsProblem();
$this
->drupalGet($update_url . '/selection', [
'external' => TRUE,
]);
$this
->assertSession()
->responseContains('messages--status');
$this
->assertSession()
->linkByHrefNotExists('fr/update.php/run', 'No link to run updates.');
}
}