diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index c47db5e..c199ddf 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -2182,13 +2182,16 @@ function drupal_bootstrap($phase = NULL, $new_phase = TRUE) { */ function drupal_get_user_timezone() { global $user; - if (variable_get('configurable_timezones', 1) && $user->uid && $user->timezone) { + $config = config('system.date'); + + if ($config->get('timezone.user.configurable') && $user->uid && $user->timezone) { return $user->timezone; } else { // Ignore PHP strict notice if time zone has not yet been set in the php.ini // configuration. - return variable_get('date_default_timezone', @date_default_timezone_get()); + $config_data_default_timezone = $config->get('timezone.default'); + return !empty($config_data_default_timezone) ? $config_data_default_timezone : @date_default_timezone_get(); } } diff --git a/core/includes/common.inc b/core/includes/common.inc index a70b66e..1de9c2b 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -1827,11 +1827,11 @@ function format_interval($interval, $granularity = 2, $langcode = NULL) { * A UNIX timestamp to format. * @param $type * (optional) The format to use, one of: - * - One of the built-in formats: 'short', 'medium', 'long', 'html_datetime', - * 'html_date', 'html_time', 'html_yearless_date', 'html_week', - * 'html_month', 'html_year'. - * - The name of a date type defined by a module in hook_date_format_types(), - * if it's been assigned a format. + * - One of the built-in formats: 'short', 'medium', + * 'long', 'html_datetime', 'html_date', 'html_time', + * 'html_yearless_date', 'html_week', 'html_month', 'html_year'. + * - The name of a date type defined by a module in + * hook_date_format_types(), if it's been assigned a format. * - The machine name of an administrator-defined date format. * - 'custom', to use $format. * Defaults to 'medium'. @@ -1871,66 +1871,28 @@ function format_date($timestamp, $type = 'medium', $format = '', $timezone = NUL $langcode = language(LANGUAGE_TYPE_INTERFACE)->langcode; } - switch ($type) { - case 'short': - $format = variable_get('date_format_short', 'm/d/Y - H:i'); - break; - - case 'long': - $format = variable_get('date_format_long', 'l, F j, Y - H:i'); - break; - - case 'html_datetime': - $format = variable_get('date_format_html_datetime', 'Y-m-d\TH:i:sO'); - break; - - case 'html_date': - $format = variable_get('date_format_html_date', 'Y-m-d'); - break; - - case 'html_time': - $format = variable_get('date_format_html_time', 'H:i:s'); - break; - - case 'html_yearless_date': - $format = variable_get('date_format_html_yearless_date', 'm-d'); - break; - - case 'html_week': - $format = variable_get('date_format_html_week', 'Y-\WW'); - break; - - case 'html_month': - $format = variable_get('date_format_html_month', 'Y-m'); - break; - - case 'html_year': - $format = variable_get('date_format_html_year', 'Y'); - break; + // Create a DrupalDateTime object from the timestamp and timezone. + $date = new DrupalDateTime($timestamp, $timezones[$timezone]); - case 'custom': - // No change to format. - break; + // Find the appropriate format type. + $key = $date->canUseIntl() ? DrupalDateTime::INTL : DrupalDateTime::PHP; - case 'medium': - default: - // Retrieve the format of the custom $type passed. - if ($type != 'medium') { - $format = variable_get('date_format_' . $type, ''); - } - // Fall back to 'medium'. - if ($format === '') { - $format = variable_get('date_format_medium', 'D, m/d/Y - H:i'); - } - break; + // If we have a non-custom date format use the provided date format pattern. + if ($type != 'custom') { + $format = config('system.date')->get('formats.' . $type . '.pattern.' . $key); } - // Create a DrupalDateTime object from the timestamp and timezone. - $date_time = new DrupalDateTime($timestamp, $timezones[$timezone]); + // Fall back to medium if a format was not found. + if (empty($format)) { + $format = config('system.date')->get('formats.medium.pattern.' . $key); + } - // Call date_format(). - $settings = array('langcode' => $langcode); - return $date_time->format($format, $settings); + // Call $date->format(). + $settings = array( + 'langcode' => $langcode, + 'format_string_type' => $key, + ); + return $date->format($format, $settings); } /** diff --git a/core/includes/date.inc b/core/includes/date.inc deleted file mode 100644 index 01ab131..0000000 --- a/core/includes/date.inc +++ /dev/null @@ -1,196 +0,0 @@ - 'short', - 'format' => 'Y-m-d H:i', - 'locales' => array(), - ); - $formats[] = array( - 'type' => 'short', - 'format' => 'm/d/Y - H:i', - 'locales' => array('en-us'), - ); - $formats[] = array( - 'type' => 'short', - 'format' => 'd/m/Y - H:i', - 'locales' => array('en-gb', 'en-hk', 'en-ie', 'el-gr', 'es-es', 'fr-be', 'fr-fr', 'fr-lu', 'it-it', 'nl-be', 'pt-pt'), - ); - $formats[] = array( - 'type' => 'short', - 'format' => 'Y/m/d - H:i', - 'locales' => array('en-ca', 'fr-ca', 'no-no', 'sv-se'), - ); - $formats[] = array( - 'type' => 'short', - 'format' => 'd.m.Y - H:i', - 'locales' => array('de-ch', 'de-de', 'de-lu', 'fi-fi', 'fr-ch', 'is-is', 'pl-pl', 'ro-ro', 'ru-ru'), - ); - $formats[] = array( - 'type' => 'short', - 'format' => 'm/d/Y - g:ia', - 'locales' => array(), - ); - $formats[] = array( - 'type' => 'short', - 'format' => 'd/m/Y - g:ia', - 'locales' => array(), - ); - $formats[] = array( - 'type' => 'short', - 'format' => 'Y/m/d - g:ia', - 'locales' => array(), - ); - $formats[] = array( - 'type' => 'short', - 'format' => 'M j Y - H:i', - 'locales' => array(), - ); - $formats[] = array( - 'type' => 'short', - 'format' => 'j M Y - H:i', - 'locales' => array(), - ); - $formats[] = array( - 'type' => 'short', - 'format' => 'Y M j - H:i', - 'locales' => array(), - ); - $formats[] = array( - 'type' => 'short', - 'format' => 'M j Y - g:ia', - 'locales' => array(), - ); - $formats[] = array( - 'type' => 'short', - 'format' => 'j M Y - g:ia', - 'locales' => array(), - ); - $formats[] = array( - 'type' => 'short', - 'format' => 'Y M j - g:ia', - 'locales' => array(), - ); - - // Medium date formats. - $formats[] = array( - 'type' => 'medium', - 'format' => 'D, Y-m-d H:i', - 'locales' => array(), - ); - $formats[] = array( - 'type' => 'medium', - 'format' => 'D, m/d/Y - H:i', - 'locales' => array('en-us'), - ); - $formats[] = array( - 'type' => 'medium', - 'format' => 'D, d/m/Y - H:i', - 'locales' => array('en-gb', 'en-hk', 'en-ie', 'el-gr', 'es-es', 'fr-be', 'fr-fr', 'fr-lu', 'it-it', 'nl-be', 'pt-pt'), - ); - $formats[] = array( - 'type' => 'medium', - 'format' => 'D, Y/m/d - H:i', - 'locales' => array('en-ca', 'fr-ca', 'no-no', 'sv-se'), - ); - $formats[] = array( - 'type' => 'medium', - 'format' => 'F j, Y - H:i', - 'locales' => array(), - ); - $formats[] = array( - 'type' => 'medium', - 'format' => 'j F, Y - H:i', - 'locales' => array(), - ); - $formats[] = array( - 'type' => 'medium', - 'format' => 'Y, F j - H:i', - 'locales' => array(), - ); - $formats[] = array( - 'type' => 'medium', - 'format' => 'D, m/d/Y - g:ia', - 'locales' => array(), - ); - $formats[] = array( - 'type' => 'medium', - 'format' => 'D, d/m/Y - g:ia', - 'locales' => array(), - ); - $formats[] = array( - 'type' => 'medium', - 'format' => 'D, Y/m/d - g:ia', - 'locales' => array(), - ); - $formats[] = array( - 'type' => 'medium', - 'format' => 'F j, Y - g:ia', - 'locales' => array(), - ); - $formats[] = array( - 'type' => 'medium', - 'format' => 'j F Y - g:ia', - 'locales' => array(), - ); - $formats[] = array( - 'type' => 'medium', - 'format' => 'Y, F j - g:ia', - 'locales' => array(), - ); - $formats[] = array( - 'type' => 'medium', - 'format' => 'j. F Y - G:i', - 'locales' => array(), - ); - - // Long date formats. - $formats[] = array( - 'type' => 'long', - 'format' => 'l, F j, Y - H:i', - 'locales' => array(), - ); - $formats[] = array( - 'type' => 'long', - 'format' => 'l, j F, Y - H:i', - 'locales' => array(), - ); - $formats[] = array( - 'type' => 'long', - 'format' => 'l, Y, F j - H:i', - 'locales' => array(), - ); - $formats[] = array( - 'type' => 'long', - 'format' => 'l, F j, Y - g:ia', - 'locales' => array(), - ); - $formats[] = array( - 'type' => 'long', - 'format' => 'l, j F Y - g:ia', - 'locales' => array(), - ); - $formats[] = array( - 'type' => 'long', - 'format' => 'l, Y, F j - g:ia', - 'locales' => array(), - ); - $formats[] = array( - 'type' => 'long', - 'format' => 'l, j. F Y - G:i', - 'locales' => array(), - ); - - return $formats; -} diff --git a/core/includes/form.inc b/core/includes/form.inc index 002de6f..cbc786f 100644 --- a/core/includes/form.inc +++ b/core/includes/form.inc @@ -2996,7 +2996,8 @@ function form_process_date($element) { $element['#tree'] = TRUE; // Determine the order of day, month, year in the site's chosen date format. - $format = variable_get('date_format_short', 'm/d/Y - H:i'); + $format = config('system.date')->get('formats.short.pattern'); + $format = $format['php']; $sort = array(); $sort['day'] = max(strpos($format, 'd'), strpos($format, 'j')); $sort['month'] = max(strpos($format, 'm'), strpos($format, 'M')); diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index efeca48..5366436 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -1938,7 +1938,7 @@ function _install_configure_form($form, &$form_state, &$install_state) { '#type' => 'select', '#title' => st('Default country'), '#empty_value' => '', - '#default_value' => variable_get('site_default_country', NULL), + '#default_value' => config('system.date')->get('country.default'), '#options' => $countries, '#description' => st('Select the default country for the site.'), '#weight' => 0, @@ -2011,8 +2011,10 @@ function install_configure_form_submit($form, &$form_state) { ->set('mail', $form_state['values']['site_mail']) ->save(); - variable_set('date_default_timezone', $form_state['values']['date_default_timezone']); - variable_set('site_default_country', $form_state['values']['site_default_country']); + config('system.date') + ->set('timezone.default', $form_state['values']['date_default_timezone']) + ->set('country.default', $form_state['values']['site_default_country']) + ->save(); // Enable update.module if this option was selected. if ($form_state['values']['update_status_module'][1]) { diff --git a/core/lib/Drupal/Core/Datetime/DrupalDateTime.php b/core/lib/Drupal/Core/Datetime/DrupalDateTime.php index 775e668..6d60656 100644 --- a/core/lib/Drupal/Core/Datetime/DrupalDateTime.php +++ b/core/lib/Drupal/Core/Datetime/DrupalDateTime.php @@ -60,7 +60,7 @@ public function __construct($time = 'now', $timezone = NULL, $format = NULL, $se // We can set the langcode and country using Drupal values. $settings['langcode'] = !empty($settings['langcode']) ? $settings['langcode'] : language(LANGUAGE_TYPE_INTERFACE)->langcode; - $settings['country'] = !empty($settings['country']) ? $settings['country'] : variable_get('site_default_country'); + $settings['country'] = !empty($settings['country']) ? $settings['country'] : config('system.date')->get('country.default'); // Instantiate the parent class. parent::__construct($time, $timezone, $format, $settings); diff --git a/core/modules/aggregator/aggregator.pages.inc b/core/modules/aggregator/aggregator.pages.inc index 78ca5bc..0c04c7d 100644 --- a/core/modules/aggregator/aggregator.pages.inc +++ b/core/modules/aggregator/aggregator.pages.inc @@ -335,7 +335,7 @@ function template_preprocess_aggregator_item(&$variables) { $variables['source_date'] = t('%ago ago', array('%ago' => format_interval(REQUEST_TIME - $item->timestamp))); } else { - $variables['source_date'] = format_date($item->timestamp, 'custom', variable_get('date_format_medium', 'D, m/d/Y - H:i')); + $variables['source_date'] = format_date($item->timestamp, 'medium'); } $variables['categories'] = array(); diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module index 85ed5d1..7ed44b6 100644 --- a/core/modules/locale/locale.module +++ b/core/modules/locale/locale.module @@ -573,7 +573,7 @@ function locale_library_info_alter(&$libraries, $module) { 'ui' => array( 'datepicker' => array( 'isRTL' => $language_interface->direction == LANGUAGE_RTL, - 'firstDay' => variable_get('date_first_day', 0), + 'firstDay' => config('system.date')->get('first_day'), ), ), ), diff --git a/core/modules/openid/lib/Drupal/openid/Tests/OpenIDRegistrationTest.php b/core/modules/openid/lib/Drupal/openid/Tests/OpenIDRegistrationTest.php index 51c2160..51b16b3 100644 --- a/core/modules/openid/lib/Drupal/openid/Tests/OpenIDRegistrationTest.php +++ b/core/modules/openid/lib/Drupal/openid/Tests/OpenIDRegistrationTest.php @@ -41,8 +41,11 @@ function setUp() { */ function testRegisterUserWithEmailVerification() { config('user.settings')->set('verify_mail', TRUE)->save(); - variable_get('configurable_timezones', 1); - variable_set('date_default_timezone', 'Europe/Brussels'); + + config('system.date') + ->set('timezone.user.configurable', 1) + ->set('timezone.default', 'Europe/Brussels') + ->save(); // Tell openid_test.module to respond with these SREG fields. variable_set('openid_test_response', array( @@ -97,8 +100,11 @@ function testRegisterUserWithEmailVerification() { */ function testRegisterUserWithoutEmailVerification() { config('user.settings')->set('verify_mail', FALSE)->save(); - variable_get('configurable_timezones', 1); - variable_set('date_default_timezone', 'Europe/Brussels'); + + config('system.date') + ->set('timezone.user.configurable', 1) + ->set('timezone.default', 'Europe/Brussels') + ->save(); // Tell openid_test.module to respond with these SREG fields. variable_set('openid_test_response', array( @@ -137,8 +143,10 @@ function testRegisterUserWithoutEmailVerification() { * information (a username that is already taken, and no e-mail address). */ function testRegisterUserWithInvalidSreg() { - variable_get('configurable_timezones', 1); - variable_set('date_default_timezone', 'Europe/Brussels'); + config('system.date') + ->set('timezone.user.configurable', 1) + ->set('timezone.default', 'Europe/Brussels') + ->save(); // Tell openid_test.module to respond with these SREG fields. $web_user = $this->drupalCreateUser(array()); @@ -187,7 +195,6 @@ function testRegisterUserWithInvalidSreg() { * information (i.e. no username or e-mail address). */ function testRegisterUserWithoutSreg() { - variable_get('configurable_timezones', 1); // Load the front page to get the user login block. $this->drupalGet(''); @@ -226,7 +233,9 @@ function testRegisterUserWithoutSreg() { */ function testRegisterUserWithAXButNoSREG() { config('user.settings')->set('verify_mail', FALSE)->save(); - variable_set('date_default_timezone', 'Europe/Brussels'); + config('system.date') + ->set('timezone.default', 'Europe/Brussels') + ->save(); // Tell openid_test.module to respond with these AX fields. variable_set('openid_test_response', array( diff --git a/core/modules/system/config/system.date.yml b/core/modules/system/config/system.date.yml new file mode 100644 index 0000000..ab21797 --- /dev/null +++ b/core/modules/system/config/system.date.yml @@ -0,0 +1,70 @@ +first_day: '0' +country: + default: '' +timezone: + default: '' + user: + configurable: '1' + default: '0' + warn: '0' +formats: + long: + name: 'Default Long Date' + pattern: + php: 'l, F j, Y - H:i' + intl: 'EEEE, LLLL d, yyyy - kk:mm' + locked: 0 + medium: + name: 'Default Medium Date' + pattern: + php: 'D, m/d/Y - H:i' + intl: 'ccc, MM/dd/yyyy - kk:mm' + locked: 0 + short: + name: 'Default Short Date' + pattern: + php: 'm/d/Y - H:i' + intl: 'MM/dd/yyyy - kk:mm' + locked: 0 + html_datetime: + name: 'HTML Datetime' + pattern: + php: 'Y-m-d\TH:i:sO' + intl: "yyyy-MM-dd'Tkk:mm:ssZZ" + locked: 1 + html_date: + name: 'HTML Date' + pattern: + php: 'Y-m-d' + intl: 'yyyy-MM-dd' + locked: 1 + html_time: + name: 'HTML Time' + pattern: + php: 'H:i:s' + intl: 'H:mm:ss' + locked: 1 + html_yearless_date: + name: 'HTML Yearless date' + pattern: + php: 'm-d' + intl: 'MM-d' + locked: 1 + html_week: + name: 'HTML Week' + pattern: + php: 'Y-\WW' + intl: "Y-'WW" + locked: 1 + html_month: + name: 'HTML Month' + pattern: + php: 'Y-m' + intl: 'Y-MM' + locked: 1 + html_year: + name: 'HTML Year' + pattern: + php: 'Y' + intl: 'Y' + locked: 1 diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/FormatDateTest.php b/core/modules/system/lib/Drupal/system/Tests/Common/FormatDateTest.php index d3cd9e6..e89a302 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Common/FormatDateTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Common/FormatDateTest.php @@ -35,15 +35,19 @@ public static function getInfo() { } function setUp() { - parent::setUp(); - variable_set('configurable_timezones', 1); - variable_set('date_format_long', 'l, j. F Y - G:i'); - variable_set('date_format_medium', 'j. F Y - G:i'); - variable_set('date_format_short', 'Y M j - g:ia'); + parent::setUp('language'); + config('system.date') + ->set('timezone.user.configurable', 1) + ->set('formats.long.pattern.php', 'l, j. F Y - G:i') + ->set('formats.medium.pattern.php', 'j. F Y - G:i') + ->set('formats.short.pattern.php', 'Y M j - g:ia') + ->save(); + variable_set('locale_custom_strings_' . self::LANGCODE, array( '' => array('Sunday' => 'domingo'), 'Long month name' => array('March' => 'marzo'), )); + $this->refreshVariables(); } @@ -56,17 +60,12 @@ function testAdminDefinedFormatDate() { $this->drupalLogin($this->admin_user); // Add new date format. - $admin_date_format = 'j M y'; - $edit = array('date_format' => $admin_date_format); - $this->drupalPost('admin/config/regional/date-time/formats/add', $edit, 'Add format'); - - // Add new date type. $edit = array( - 'date_type' => 'Example Style', - 'machine_name' => 'example_style', - 'date_format' => $admin_date_format, + 'date_format_id' => 'example_style', + 'date_format_name' => 'Example Style', + 'date_format_pattern' => 'j M y', ); - $this->drupalPost('admin/config/regional/date-time/types/add', $edit, 'Add date type'); + $this->drupalPost('admin/config/regional/date-time/formats/add', $edit, t('Add format')); $timestamp = strtotime('2007-03-10T00:00:00+00:00'); $this->assertIdentical(format_date($timestamp, 'example_style', '', 'America/Los_Angeles'), '9 Mar 07', 'Test format_date() using an admin-defined date type.'); diff --git a/core/modules/system/lib/Drupal/system/Tests/Datetime/DrupalDateTimeTest.php b/core/modules/system/lib/Drupal/system/Tests/Datetime/DrupalDateTimeTest.php index ea10896..5539a61 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Datetime/DrupalDateTimeTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Datetime/DrupalDateTimeTest.php @@ -48,8 +48,8 @@ public function testDateTimezone() { $date_string = '2007-01-31 21:00:00'; // Make sure no site timezone has been set. - variable_set('date_default_timezone', NULL); - variable_set('configurable_timezones', 0); + config('system.date')->set('timezone.default', NULL)->save(); + config('system.date')->set('timezone.user.configurable', 0)->save(); // Detect the system timezone. $system_timezone = date_default_timezone_get(); @@ -66,7 +66,7 @@ public function testDateTimezone() { $this->assertTrue($timezone == 'America/Yellowknife', 'DrupalDateTime uses the specified timezone if provided.'); // Set a site timezone. - variable_set('date_default_timezone', 'Europe/Warsaw'); + config('system.date')->set('timezone.default', 'Europe/Warsaw')->save(); // Create a date object with an unspecified timezone, which should // end up using the site timezone. @@ -75,7 +75,7 @@ public function testDateTimezone() { $this->assertTrue($timezone == 'Europe/Warsaw', 'DrupalDateTime uses the site timezone if provided.'); // Create user. - variable_set('configurable_timezones', 1); + config('system.date')->set('timezone.user.configurable', 1)->save(); $test_user = $this->drupalCreateUser(array()); $this->drupalLogin($test_user); diff --git a/core/modules/system/lib/Drupal/system/Tests/System/DateFormatsLanguageTest.php b/core/modules/system/lib/Drupal/system/Tests/System/DateFormatsLanguageTest.php index 10f49b9..ff16e61 100644 --- a/core/modules/system/lib/Drupal/system/Tests/System/DateFormatsLanguageTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/System/DateFormatsLanguageTest.php @@ -19,7 +19,7 @@ class DateFormatsLanguageTest extends WebTestBase { * * @var array */ - public static $modules = array('node', 'language'); + public static $modules = array('node', 'locale'); public static function getInfo() { return array( @@ -57,20 +57,39 @@ function testLocalizeDateFormats() { ); $this->drupalPost('admin/config/regional/language/detection', $edit, t('Save settings')); + // Add new date format for French. + $edit = array( + 'date_format_id' => 'example_style_fr', + 'date_format_name' => 'Example Style', + 'date_format_pattern' => 'd.m.Y - H:i', + 'date_langcode[]' => array('fr'), + ); + $this->drupalPost('admin/config/regional/date-time/formats/add', $edit, t('Add format')); + + // Add new date format for English. + $edit = array( + 'date_format_id' => 'example_style_en', + 'date_format_name' => 'Example Style', + 'date_format_pattern' => 'j M Y - g:ia', + 'date_langcode[]' => array('en'), + ); + $this->drupalPost('admin/config/regional/date-time/formats/add', $edit, t('Add format')); + // Configure date formats. $this->drupalGet('admin/config/regional/date-time/locale'); $this->assertText('French', 'Configured languages appear.'); $edit = array( - 'date_format_long' => 'd.m.Y - H:i', - 'date_format_medium' => 'd.m.Y - H:i', - 'date_format_short' => 'd.m.Y - H:i', + 'date_format_long' => 'example_style_fr', + 'date_format_medium' => 'example_style_fr', + 'date_format_short' => 'example_style_fr', ); $this->drupalPost('admin/config/regional/date-time/locale/fr/edit', $edit, t('Save configuration')); $this->assertText(t('Configuration saved.'), 'French date formats updated.'); + $edit = array( - 'date_format_long' => 'j M Y - g:ia', - 'date_format_medium' => 'j M Y - g:ia', - 'date_format_short' => 'j M Y - g:ia', + 'date_format_long' => 'example_style_en', + 'date_format_medium' => 'example_style_en', + 'date_format_short' => 'example_style_en', ); $this->drupalPost('admin/config/regional/date-time/locale/en/edit', $edit, t('Save configuration')); $this->assertText(t('Configuration saved.'), 'English date formats updated.'); @@ -85,5 +104,10 @@ function testLocalizeDateFormats() { $this->drupalGet('fr/node/' . $node->nid); $french_date = format_date($node->created, 'custom', 'd.m.Y'); $this->assertText($french_date, 'French date format appears'); + + // Make sure we can reset dates back to default. + $this->drupalPost('admin/config/regional/date-time/locale/en/reset', array(), t('Reset')); + $this->drupalGet('node/' . $node->nid); + $this->assertNoText($english_date, 'English date format does not appear'); } } diff --git a/core/modules/system/lib/Drupal/system/Tests/System/DateTimeTest.php b/core/modules/system/lib/Drupal/system/Tests/System/DateTimeTest.php index 8483da2..2c6571a 100644 --- a/core/modules/system/lib/Drupal/system/Tests/System/DateTimeTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/System/DateTimeTest.php @@ -38,15 +38,16 @@ function setUp() { $this->drupalLogin($this->admin_user); } - /** * Test time zones and DST handling. */ function testTimeZoneHandling() { // Setup date/time settings for Honolulu time. - variable_set('date_default_timezone', 'Pacific/Honolulu'); - variable_set('configurable_timezones', 0); - variable_set('date_format_medium', 'Y-m-d H:i:s O'); + $config = config('system.date') + ->set('timezone.default', 'Pacific/Honolulu') + ->set('timezone.user.configurable', 0) + ->set('formats.medium.pattern.php', 'Y-m-d H:i:s O') + ->save(); // Create some nodes with different authored-on dates. $date1 = '2007-01-31 21:00:00 -1000'; @@ -61,7 +62,7 @@ function testTimeZoneHandling() { $this->assertText('2007-07-31 21:00:00 -1000', 'Date should be identical, with GMT offset of -10 hours.'); // Set time zone to Los Angeles time. - variable_set('date_default_timezone', 'America/Los_Angeles'); + $config->set('timezone.default', 'America/Los_Angeles')->save(); // Confirm date format and time zone. $this->drupalGet("node/$node1->nid"); @@ -71,64 +72,33 @@ function testTimeZoneHandling() { } /** - * Test date type configuration. - */ - function testDateTypeConfiguration() { - // Confirm system date types appear. - $this->drupalGet('admin/config/regional/date-time'); - $this->assertText(t('Medium'), 'System date types appear in date type list.'); - $this->assertNoRaw('href="/admin/config/regional/date-time/types/medium/delete"', 'No delete link appear for system date types.'); - - // Add custom date type. - $this->clickLink(t('Add date type')); - $date_type = strtolower($this->randomName(8)); - $machine_name = 'machine_' . $date_type; - $date_format = 'd.m.Y - H:i'; - $edit = array( - 'date_type' => $date_type, - 'machine_name' => $machine_name, - 'date_format' => $date_format, - ); - $this->drupalPost('admin/config/regional/date-time/types/add', $edit, t('Add date type')); - $this->assertEqual($this->getUrl(), url('admin/config/regional/date-time', array('absolute' => TRUE)), 'Correct page redirection.'); - $this->assertText(t('New date type added successfully.'), 'Date type added confirmation message appears.'); - $this->assertText($date_type, 'Custom date type appears in the date type list.'); - $this->assertText(t('delete'), 'Delete link for custom date type appears.'); - - // Delete custom date type. - $this->clickLink(t('delete')); - $this->drupalPost('admin/config/regional/date-time/types/' . $machine_name . '/delete', array(), t('Remove')); - $this->assertEqual($this->getUrl(), url('admin/config/regional/date-time', array('absolute' => TRUE)), 'Correct page redirection.'); - $this->assertText(t('Removed date type ' . $date_type), 'Custom date type removed.'); - } - - /** * Test date format configuration. */ function testDateFormatConfiguration() { // Confirm 'no custom date formats available' message appears. $this->drupalGet('admin/config/regional/date-time/formats'); - $this->assertText(t('No custom date formats available.'), 'No custom date formats message appears.'); // Add custom date format. $this->clickLink(t('Add format')); + $date_format_id = strtolower($this->randomName(8)); + $name = ucwords($date_format_id); + $date_format = 'd.m.Y - H:i'; $edit = array( - 'date_format' => 'Y', + 'date_format_id' => $date_format_id, + 'date_format_name' => $name, + 'date_format_pattern' => $date_format, ); $this->drupalPost('admin/config/regional/date-time/formats/add', $edit, t('Add format')); $this->assertEqual($this->getUrl(), url('admin/config/regional/date-time/formats', array('absolute' => TRUE)), 'Correct page redirection.'); - $this->assertNoText(t('No custom date formats available.'), 'No custom date formats message does not appear.'); - $this->assertText(t('Custom date format added.'), 'Custom date format added.'); - - // Ensure custom date format appears in date type configuration options. - $this->drupalGet('admin/config/regional/date-time'); - $this->assertRaw('