1 locale.test LocaleDateFormatsFunctionalTest::testLocalizeDateFormats()

Functional tests for localizing date formats.

File

core/modules/locale/tests/locale.test, line 2736
Tests for locale.module.

Class

LocaleDateFormatsFunctionalTest
Functional tests for localizing date formats.

Code

function testLocalizeDateFormats() {
  // Add language.
  $edit = array(
    'predefined_langcode' => 'fr',
  );
  $this->backdropPost('admin/config/regional/language/add', $edit, t('Add language'));

  // Set language negotiation.
  $language_type = LANGUAGE_TYPE_INTERFACE;
  $edit = array(
    "{$language_type}[locale-url][enabled]" => TRUE,
  );
  $this->backdropPost('admin/config/regional/language/detection', $edit, t('Save settings'));

  // Ensure generated URLs stick with English.
  $GLOBALS['language_url'] = language_default();

  // Add new date format.
  $edit = array(
    'label' => 'Example Style',
    'name' => 'example_style',
    'pattern' => 'd.m.Y - H:i',
  );
  $this->backdropPost('admin/config/regional/date-time/formats/add', $edit, t('Add format'));

  // Configure the example format.
  $edit = array(
    'locales[en]' => 'm.d.Y - H:i',
    'locales[fr]' => 'Y.m.d - H:i',
  );
  $this->backdropPost('admin/config/regional/date-time/formats/example_style/localize', $edit, t('Save configuration'));
  $this->assertText(t('Date localizations saved.'), 'Localized date formats saved.');

  // Ensure that the original date format is still used on this page's
  // display, not the localized English version. Hour and minute are omitted
  // to avoid race conditions between the GET and the assert.
  $this->backdropGet('admin/config/regional/date-time/formats');
  $this->assertText(format_date(REQUEST_TIME, 'custom', 'd.m.Y'));

  // Configure the medium format.
  $edit = array(
    'locales[en]' => 'D, m/d/Y - g:ia',
    'locales[fr]' => 'D, Y/m/Y - H:i',
  );
  $this->backdropPost('admin/config/regional/date-time/formats/medium/localize', $edit, t('Save configuration'));
  $this->assertText(t('Date localizations saved.'), 'Medium date formats updated.');

  // Create node content.
  $node = $this->backdropCreateNode(array('type' => 'post'));

  // Configure format for the node posted date changes with the language.
  $this->backdropGet('node/' . $node->nid);
  $english_date = format_date($node->created, 'custom', 'D, m/d/Y - g:ia');
  $this->assertText($english_date, 'English date format appears');
  $this->backdropGet('fr/node/' . $node->nid);
  $french_date = format_date($node->created, 'custom', 'D, Y/m/Y - H:i');
  $this->assertText($french_date, 'French date format appears');
}