summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwebchick <webchick@24967.no-reply.drupal.org>2011-08-01 21:08:34 -0700
committerwebchick <webchick@24967.no-reply.drupal.org>2011-08-01 21:08:34 -0700
commit115fb7545cb4bdd85d345968c584ac046f854a6b (patch)
tree26db7a39113cab46b4a4b3a5a118e48508a3adae
parentd676fe412c46c94ed2497b1ca47de42cd0177c3b (diff)
downloadbrdo-115fb7545cb4bdd85d345968c584ac046f854a6b.tar.gz
brdo-115fb7545cb4bdd85d345968c584ac046f854a6b.tar.bz2
Issue #981524 by das-peter, Pisco, sun: Fixed system_date_format_save() doesn't save localized date formats.
-rw-r--r--modules/system/system.module2
-rw-r--r--modules/system/system.test70
2 files changed, 70 insertions, 2 deletions
diff --git a/modules/system/system.module b/modules/system/system.module
index 754177ca6..4136ecd57 100644
--- a/modules/system/system.module
+++ b/modules/system/system.module
@@ -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;
diff --git a/modules/system/system.test b/modules/system/system.test
index 8a29ce531..b69eed341 100644
--- a/modules/system/system.test
+++ b/modules/system/system.test
@@ -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 {