Issue #981524 by das-peter, Pisco, sun: Fixed system_date_format_save() doesn't save localized date formats.

8.0.x
webchick 2011-08-01 21:08:28 -07:00
parent bf704dd7a1
commit fae2323ecf
2 changed files with 70 additions and 2 deletions

View File

@ -3871,7 +3871,7 @@ function system_date_format_save($date_format, $dfid = 0) {
if (!empty($date_format['locales'])) {
foreach ($date_format['locales'] as $langcode) {
// Only proceed if language is enabled.
if (in_array($langcode, $languages)) {
if (isset($languages[$langcode])) {
$is_existing = (bool) db_query_range('SELECT 1 FROM {date_format_locale} WHERE type = :type AND language = :language', 0, 1, array(':type' => $date_format['type'], ':language' => $langcode))->fetchField();
if (!$is_existing) {
$locale_format['language'] = $langcode;

View File

@ -1091,7 +1091,7 @@ class DateTimeFunctionalTest extends DrupalWebTestCase {
}
function setUp() {
parent::setUp();
parent::setUp(array('locale'));
// Create admin user and log in admin user.
$this->admin_user = $this->drupalCreateUser(array('administer site configuration'));
@ -1200,6 +1200,74 @@ class DateTimeFunctionalTest extends DrupalWebTestCase {
$this->assertEqual($this->getUrl(), url('admin/config/regional/date-time/formats', array('absolute' => TRUE)), t('Correct page redirection.'));
$this->assertText(t('Removed date format'), 'Custom date format removed successfully.');
}
/**
* Test if the date formats are stored properly.
*/
function testDateFormatStorage() {
$date_format = array(
'type' => 'short',
'format' => 'dmYHis',
'locked' => 0,
'is_new' => 1,
);
system_date_format_save($date_format);
$format = db_select('date_formats', 'df')
->fields('df', array('format'))
->condition('type', 'short')
->condition('format', 'dmYHis')
->execute()
->fetchField();
$this->verbose($format);
$this->assertEqual('dmYHis', $format, 'Unlocalized date format resides in general table.');
$format = db_select('date_format_locale', 'dfl')
->fields('dfl', array('format'))
->condition('type', 'short')
->condition('format', 'dmYHis')
->execute()
->fetchField();
$this->assertFalse($format, 'Unlocalized date format resides not in localized table.');
// Enable German language
locale_add_language('de', NULL, NULL, LANGUAGE_LTR, '', '', TRUE, 'en');
$date_format = array(
'type' => 'short',
'format' => 'YMDHis',
'locales' => array('de', 'tr'),
'locked' => 0,
'is_new' => 1,
);
system_date_format_save($date_format);
$format = db_select('date_format_locale', 'dfl')
->fields('dfl', array('format'))
->condition('type', 'short')
->condition('format', 'YMDHis')
->condition('language', 'de')
->execute()
->fetchField();
$this->assertEqual('YMDHis', $format, 'Localized date format resides in localized table.');
$format = db_select('date_formats', 'df')
->fields('df', array('format'))
->condition('type', 'short')
->condition('format', 'YMDHis')
->execute()
->fetchField();
$this->assertEqual('YMDHis', $format, 'Localized date format resides in general table too.');
$format = db_select('date_format_locale', 'dfl')
->fields('dfl', array('format'))
->condition('type', 'short')
->condition('format', 'YMDHis')
->condition('language', 'tr')
->execute()
->fetchColumn();
$this->assertFalse($format, 'Localized date format for disabled language is ignored.');
}
}
class PageTitleFiltering extends DrupalWebTestCase {