LocaleTranslatedSchemaDefinitionTest.php in Drupal 8
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;
public static $modules = [
'language',
'locale',
'node',
];
protected $defaultTheme = 'classy';
protected function setUp() {
parent::setUp();
ConfigurableLanguage::createFromLangcode('fr')
->save();
$this
->config('system.site')
->set('default_langcode', 'fr')
->save();
drupal_flush_all_caches();
}
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
->assertEqual('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
->assertRaw('messages--status', 'No pending updates.');
$this
->assertNoLinkByHref('fr/update.php/run', 'No link to run updates.');
}
}