You are here

public function ConfigTranslationUiTest::testDateFormatTranslation in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php \Drupal\config_translation\Tests\ConfigTranslationUiTest::testDateFormatTranslation()

Tests date format translation.

File

core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php, line 409
Contains \Drupal\config_translation\Tests\ConfigTranslationUiTest.

Class

ConfigTranslationUiTest
Translate settings and entities to various languages.

Namespace

Drupal\config_translation\Tests

Code

public function testDateFormatTranslation() {
  $this
    ->drupalLogin($this->adminUser);
  $this
    ->drupalGet('admin/config/regional/date-time');

  // Check for medium format.
  $this
    ->assertLinkByHref('admin/config/regional/date-time/formats/manage/medium');

  // Save default language configuration for a new format.
  $edit = array(
    'label' => 'Custom medium date',
    'id' => 'custom_medium',
    'date_format_pattern' => 'Y. m. d. H:i',
  );
  $this
    ->drupalPostForm('admin/config/regional/date-time/formats/add', $edit, t('Add format'));

  // Test translating a default shipped format and our custom format.
  $formats = array(
    'medium' => 'Default medium date',
    'custom_medium' => 'Custom medium date',
  );
  foreach ($formats as $id => $label) {
    $translation_base_url = 'admin/config/regional/date-time/formats/manage/' . $id . '/translate';
    $this
      ->drupalGet($translation_base_url);

    // 'Add' link should be present for French translation.
    $translation_page_url = "{$translation_base_url}/fr/add";
    $this
      ->assertLinkByHref($translation_page_url);

    // Make sure original text is present on this page.
    $this
      ->drupalGet($translation_page_url);
    $this
      ->assertText($label);

    // Make sure that the date library is added.
    $this
      ->assertRaw('core/modules/system/js/system.date.js');

    // Update translatable fields.
    $edit = array(
      'translation[config_names][core.date_format.' . $id . '][label]' => $id . ' - FR',
      'translation[config_names][core.date_format.' . $id . '][pattern]' => 'D',
    );

    // Save language specific version of form.
    $this
      ->drupalPostForm($translation_page_url, $edit, t('Save translation'));

    // Get translation and check we've got the right value.
    $override = \Drupal::languageManager()
      ->getLanguageConfigOverride('fr', 'core.date_format.' . $id);
    $expected = array(
      'label' => $id . ' - FR',
      'pattern' => 'D',
    );
    $this
      ->assertEqual($expected, $override
      ->get());

    // Formatting the date 8 / 27 / 1985 @ 13:37 EST with pattern D should
    // display "Tue".
    $formatted_date = format_date(494015820, $id, NULL, 'America/New_York', 'fr');
    $this
      ->assertEqual($formatted_date, 'Tue', 'Got the right formatted date using the date format translation pattern.');
  }
}