You are here

class PHP4Dates in Date 5.2

Same name and namespace in other branches
  1. 6 tests/date_timezone.test \PHP4Dates

Test PHP 4 Timezone Conversion

Hierarchy

Expanded class hierarchy of PHP4Dates

File

tests/date_timezone.test, line 5

View source
class PHP4Dates extends DrupalTestCase {
  function get_info() {
    return array(
      'name' => t('PHP 4 date and timezone handling'),
      'desc' => t('Test PHP 4 versions of date_create(), timezone_open(), date_timezone_set(), etc. Tests only provide meaningful results when run in PHP 4 environment.'),
      'group' => 'Date tests',
    );
  }
  function testPHP4Timezone() {
    require_once './' . drupal_get_path('module', 'date_php4') . '/date_php4.inc';
    $date = date_create('2007-03-11 01:59:59');
    $this
      ->assertEqual($date->value, '2007-03-11 01:59:59', 'Create the a date 2007-03-11 01:59:59');
    $date = date_create('2007-03-11 01:59:59', timezone_open('America/Chicago'));
    $this
      ->assertEqual($date->timezone, 'America/Chicago', 'Create the timezone America/Chicago');
    $format = date_format($date, 'm/d/Y g:i a');
    $this
      ->assertEqual($format, '03/11/2007 1:59 am', 'Test date_format()');
    $date = date_create('2007-01-01', timezone_open('US/Central'));
    $result = date_format(date_modify($date, '+3 month'), 'Y-m-d');
    $this
      ->assertEqual('2007-04-01', $result, "Check date_modify('2007-01-01', '+3 month'), should be '2007-04-01'");
    $date = date_create('2007-01-01', timezone_open('US/Central'));
    $result = date_format(date_modify($date, '-1 month'), 'Y-m-d');
    $this
      ->assertEqual('2006-12-01', $result, "Check date_modify('2007-01-01', '-1 month'), should be '2006-12-01'");
    $date = date_create('2007-01-01', timezone_open('US/Central'));
    $result = date_format(date_modify($date, '-1 day'), 'Y-m-d');
    $this
      ->assertEqual('2006-12-31', $result, "Check date_modify('2007-01-01', '-1 day'), should be '2006-12-31'");
    $date = date_create('2005-02-28', timezone_open('US/Central'));
    $result = date_format(date_modify($date, '+1 day'), 'Y-m-d');
    $this
      ->assertEqual('2005-03-01', $result, "Check date_modify('2005-02-28', '+1 day'), should be '2005-03-01'");
    $date = date_create('2004-02-28', timezone_open('US/Central'));
    $result = date_format(date_modify($date, '+1 day'), 'Y-m-d');
    $this
      ->assertEqual('2004-02-29', $result, "Check date_modify('2004-02-28', '+1 day'), should be '2004-02-29'");
    $date = date_create('2004-03-01', timezone_open('US/Central'));
    $result = date_format(date_modify($date, '-1 day'), 'Y-m-d');
    $this
      ->assertEqual('2004-02-29', $result, "Check date_modify('2004-03-01', '-1 day'), should be '2004-02-29'");
    $date = date_create('2005-03-01', timezone_open('US/Central'));
    $result = date_format(date_modify($date, '-1 day'), 'Y-m-d');
    $this
      ->assertEqual('2005-02-28', $result, "Check date_modify('2005-03-01', '-1 day'), should be '2005-02-28'");
    $timezone = timezone_open('America/Chicago');
    $date = date_create('2007-03-11 01:59:59', $timezone);
    $this
      ->assertEqual(date_offset_get($date), -21600, 'The offset 1 minute before start of CDT, 2am on Mar 11, 2007 is -21600, returned ' . date_offset_get($date));
    $date = date_create('2007-03-11 02:00:00', $timezone);
    $this
      ->assertEqual(date_offset_get($date), -18000, 'New DST rules: The offset at start of CDT, 2am on Mar 11, 2007 is -18000, returned ' . date_offset_get($date));
    $date = date_create('2001-03-11 02:00:00', $timezone);
    $this
      ->assertEqual(date_offset_get($date), -21600, 'Old DST rules: The offset at 2am on Mar 11, 2001 is -21600, returned ' . date_offset_get($date));
    $date = date_create('1970-01-01 00:00:00', $timezone);
    $date = date_timezone_set($date, timezone_open('Asia/Tokyo'));
    $format = date_format($date, 'm/d/Y h:i a');
    $this
      ->assertEqual($format, '01/01/1970 03:00 pm', 'Convert date using date_timezone_set(), 1970-01-01 00:00:00 in America/Chicago becomes 01/01/1970 03:00 pm in Asia/Tokyo, returned ' . $format);

    // Test offsets for DST and non DST in various parts of the world.
    $date = '2007-02-01 00:00:00';
    $date2 = '2007-08-07 00:00:00';
    $vals = array(
      // This is tricky, Honolulu does not observe dst
      array(
        'val' => $date,
        'tz' => 'Pacific/Honolulu',
        'offset' => -36000,
      ),
      array(
        'val' => $date2,
        'tz' => 'Pacific/Honolulu',
        'offset' => -36000,
      ),
      array(
        'val' => $date,
        'tz' => 'America/Vancouver',
        'offset' => -28800,
      ),
      array(
        'val' => $date2,
        'tz' => 'America/Vancouver',
        'offset' => -25200,
      ),
      // Mexico changes to dst at different times in different states,
      // too complex to get this working in PHP 4.

      //array('val' => $date, 'tz' => 'America/Mexico_City', 'offset' => -21600),

      //array('val' => $date2, 'tz' => 'America/Mexico_City', 'offset' => -18000),
      array(
        'val' => $date,
        'tz' => 'America/New_York',
        'offset' => -18000,
      ),
      array(
        'val' => $date2,
        'tz' => 'America/New_York',
        'offset' => -14400,
      ),
      array(
        'val' => $date,
        'tz' => 'Europe/London',
        'offset' => 0,
      ),
      array(
        'val' => $date2,
        'tz' => 'Europe/London',
        'offset' => 3600,
      ),
      array(
        'val' => $date,
        'tz' => 'Europe/Brussels',
        'offset' => 3600,
      ),
      array(
        'val' => $date2,
        'tz' => 'Europe/Brussels',
        'offset' => 7200,
      ),
      array(
        'val' => $date,
        'tz' => 'Europe/Kiev',
        'offset' => 7200,
      ),
      array(
        'val' => $date2,
        'tz' => 'Europe/Kiev',
        'offset' => 10800,
      ),
      array(
        'val' => $date,
        'tz' => 'Asia/Calcutta',
        'offset' => 19800,
      ),
      array(
        'val' => $date2,
        'tz' => 'Asia/Calcutta',
        'offset' => 19800,
      ),
      array(
        'val' => $date,
        'tz' => 'Asia/Shanghai',
        'offset' => 28800,
      ),
      array(
        'val' => $date2,
        'tz' => 'Asia/Shanghai',
        'offset' => 28800,
      ),
      array(
        'val' => $date,
        'tz' => 'Asia/Tokyo',
        'offset' => 32400,
      ),
      array(
        'val' => $date2,
        'tz' => 'Asia/Tokyo',
        'offset' => 32400,
      ),
      // Southern hemisphere rules get reversed.
      array(
        'val' => $date,
        'tz' => 'Australia/Sydney',
        'offset' => 39600,
      ),
      array(
        'val' => $date2,
        'tz' => 'Australia/Sydney',
        'offset' => 36000,
      ),
    );
    foreach ($vals as $val) {
      $timezone = timezone_open($val['tz']);
      $date = date_create($val['val'], $timezone);
      $this
        ->assertEqual(date_offset_get($date), $val['offset'], "Testing date_create('" . $val['val'] . "', timezone_open('" . $val['tz'] . "')) offset should be " . $val['offset'] . ", result is " . date_offset_get($date));
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DrupalTestCase::$_cleanupModules property
DrupalTestCase::$_cleanupRoles property
DrupalTestCase::$_cleanupUsers property
DrupalTestCase::$_cleanupVariables property
DrupalTestCase::$_content property
DrupalTestCase::assertCopy function Will trigger a pass if both parameters refer to different objects. Fail otherwise.
DrupalTestCase::assertEqual function Will trigger a pass if the two parameters have the same value only. Otherwise a fail.
DrupalTestCase::assertError function Confirms that an error has occurred and optionally that the error text matches exactly.
DrupalTestCase::assertErrorPattern function Confirms that an error has occurred and that the error text matches a Perl regular expression.
DrupalTestCase::assertIdentical function Will trigger a pass if the two parameters have the same value and same type. Otherwise a fail.
DrupalTestCase::assertIsA function Type and class test. Will pass if class matches the type name or is a subclass or if not an object, but the type is correct.
DrupalTestCase::assertNoErrors function Confirms that no errors have occurred so far in the test method.
DrupalTestCase::assertNotA function Type and class mismatch test. Will pass if class name or underling type does not match the one specified.
DrupalTestCase::assertNotEqual function Will trigger a pass if the two parameters have a different value. Otherwise a fail.
DrupalTestCase::assertNotIdentical function Will trigger a pass if the two parameters have the different value or different type.
DrupalTestCase::assertNotNull function Will be true if the value is set.
DrupalTestCase::assertNoUnwantedPattern function Will trigger a pass if the Perl regex pattern is not present in subject. Fail if found.
DrupalTestCase::assertNoUnwantedRaw function Will trigger a pass if the raw text is NOT found on the loaded page Fail otherwise.
DrupalTestCase::assertNull function Will be true if the value is null.
DrupalTestCase::assertReference function Will trigger a pass if both parameters refer to the same object. Fail otherwise.
DrupalTestCase::assertWantedPattern function Will trigger a pass if the Perl regex pattern is found in the subject. Fail otherwise.
DrupalTestCase::assertWantedRaw function Will trigger a pass if the raw text is found on the loaded page Fail otherwise.
DrupalTestCase::clickLink function Follows a link by name. Will click the first link found with this link text by default, or a later one if an index is given. Match is case insensitive with normalised space. Does make assertations if the click was sucessful or not and it does…
DrupalTestCase::drupalCheckAuth function @abstract Checks to see if we need to send a http-auth header to authenticate when browsing a site.
DrupalTestCase::drupalCreateRolePerm function Create a role / perm combination specified by permissions
DrupalTestCase::drupalCreateUserRolePerm function Creates a user / role / permissions combination specified by permissions
DrupalTestCase::drupalGet function @abstract Brokder for the get function adds the authentication headers if necessary @author Earnest Berry III <earnest.berry@gmail.com>
DrupalTestCase::drupalGetContent function @TODO: needs documentation
DrupalTestCase::drupalLoginUser function Logs in a user with the internal browser
DrupalTestCase::drupalModuleDisable function Disables a drupal module
DrupalTestCase::drupalModuleEnable function Enables a drupal module
DrupalTestCase::drupalPostRequest function Do a post request on a drupal page. It will be done as usual post request with SimpleBrowser
DrupalTestCase::drupalRawPost function @abstract Broker for the post function adds the authentication headers if necessary @author Earnest Berry III <earnest.berry@gmail.com>
DrupalTestCase::DrupalTestCase function
DrupalTestCase::drupalVariableSet function Set a druapl variable and keep track of the changes for tearDown()
DrupalTestCase::randomName function Generates a random string, to be used as name or whatever
DrupalTestCase::run function Just some info for the reporter
DrupalTestCase::tearDown function tearDown implementation, setting back switched modules etc 1
PHP4Dates::get_info function
PHP4Dates::testPHP4Timezone function