[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/project/usage/tests/ -> date_rounding.test (source)

   1  <?php
   2  // $Id: date_rounding.test,v 1.1 2007/09/14 16:17:55 dww Exp $
   3  
   4  class ProjectUsageGetDateTests extends DrupalTestCase {
   5    function get_info() {
   6      return array(
   7        'name' => 'project_usage_gmgetdate()',
   8        'desc' => 'Test the project_usage_gmgetdate() function.',
   9        'group' => 'Project Usage',
  10      );
  11    }
  12  
  13    function test_timestamp_param() {
  14      $time = time();
  15      $parts = project_usage_gmgetdate($time);
  16      
  17      // PHP's getdate() takes the timezone into account. project_usage_gmgetdate() 
  18      // should subtract the timezone from the timestamp to cancel it out. We
  19      // can compare the input to the timestamp in the returned array and make 
  20      // sure they differ by the timezone offset.
  21      $offset = date('Z', $time);
  22      $expected = $time - $offset;
  23  
  24      $this->assertTrue(is_array($parts), "Returns an array");
  25      $this->assertEqual($parts[0], $expected, "Timestamps differ by the server's offset ($offset seconds)");
  26    }
  27  
  28    function test_default_param() {
  29      // This is actually a little dodgy... we're assuming that these two lines
  30      // will be executed in the same second.
  31      $time = time();
  32      $parts = project_usage_gmgetdate();
  33      
  34      // PHP's getdate() takes the timezone into account. project_usage_gmgetdate() 
  35      // should subtract the timezone from the timestamp to cancel it out. We
  36      // can compare the input to the timestamp in the returned array and make 
  37      // sure they differ by the timezone offset.
  38      $offset = date('Z', $time);
  39      $expected = $time - $offset;
  40  
  41      $this->assertTrue(is_array($parts), "Returns an array");
  42      $this->assertEqual($parts[0], $expected, "Timestamps differ by the server's offset ($offset seconds)");
  43    }
  44  }
  45  
  46  
  47  
  48  class ProjectUsageUsageDailyTimestampTests extends DrupalTestCase {
  49    function get_info() {
  50      return array(
  51        'name' => 'project_usage_daily_timestamp()',
  52        'desc' => 'Test the project_usage_daily_timestamp() function.',
  53        'group' => 'Project Usage',
  54      );
  55    }
  56  
  57    function format_date($timestamp) {
  58      return format_date($timestamp, 'short', NULL, 0);
  59    }
  60    
  61    function test_default_param() {
  62      $time = time();
  63      $expected = project_usage_daily_timestamp($time);
  64      $actual = project_usage_daily_timestamp();
  65  
  66      $this->assertEqual($expected, $actual, $this->format_date($time) .' should round to '. $this->format_date($expected) .' got '. $this->format_date($actual));
  67    }  
  68    function test_timestamp_param() {
  69      $time = 1189700682;
  70      $expected = 1189641600;
  71      $actual = project_usage_daily_timestamp($time);
  72  
  73      $this->assertEqual($expected, $actual, $this->format_date($time) .' should round to '. $this->format_date($expected) .' got '. $this->format_date($actual));
  74    }
  75    function test_array_param() {
  76      $time = 1189700682;
  77      $expected = 1189641600;
  78      $actual = project_usage_daily_timestamp(project_usage_gmgetdate($time));
  79  
  80      $this->assertEqual($expected, $actual, $this->format_date($time) .' should round to '. $this->format_date($expected) .' got '. $this->format_date($actual));
  81    }
  82  }
  83  
  84  
  85  class ProjectUsageUsageWeeklyTimestampTests extends DrupalTestCase {
  86    function get_info() {
  87      return array(
  88        'name' => 'project_usage_weekly_timestamp()',
  89        'desc' => 'Test the project_usage_weekly_timestamp() function.',
  90        'group' => 'Project Usage',
  91      );
  92    }
  93  
  94    function format_date($timestamp) {
  95      return format_date($timestamp, 'short', NULL, 0);
  96    }
  97  
  98    function test_default_param() {
  99      $time = time();
 100      $expected = project_usage_weekly_timestamp($time);
 101      $actual = project_usage_weekly_timestamp();
 102  
 103      $this->assertEqual($expected, $actual, $this->format_date($time) .' should round to '. $this->format_date($expected) .' got '. $this->format_date($actual));
 104    }
 105    function test_timestamp_param() {
 106      $time = 1189700682;
 107      $expected = 1189296000;
 108      $actual = project_usage_weekly_timestamp($time);
 109  
 110      $this->assertEqual($expected, $actual, $this->format_date($time) .' should round to '. $this->format_date($expected) .' got '. $this->format_date($actual));
 111    }
 112    function test_array_param() {
 113      $time = 1189700682;
 114      $expected = 1189296000;
 115      $actual = project_usage_weekly_timestamp(project_usage_gmgetdate($time));
 116  
 117      $this->assertEqual($expected, $actual, $this->format_date($time) .' should round to '. $this->format_date($expected) .' got '. $this->format_date($actual));
 118    }
 119  }
 120  
 121  
 122  class ProjectUsageGetWeeksSinceTests extends DrupalTestCase {
 123    function get_info() {
 124      return array(
 125        'name' => 'project_usage_get_weeks_since()',
 126        'desc' => 'Test the project_usage_get_weeks_since() function.',
 127        'group' => 'Project Usage',
 128      );
 129    }
 130  
 131    function format_date($timestamp) {
 132      return format_date($timestamp, 'short', NULL, 0);
 133    }
 134  
 135    function testIt() {
 136      $time = 1188600682;
 137      $expected_first = project_usage_weekly_timestamp($time);
 138      $expected_last = project_usage_weekly_timestamp();
 139  
 140      $actual = project_usage_get_weeks_since($time);
 141      $actual_first = array_shift($actual);
 142      $actual_last = array_pop($actual);
 143  
 144      $this->assertTrue(is_array($actual), "Returns an array");
 145      $this->assertEqual($actual_first, $expected_first, "First value should be ". $this->format_date($expected_first) .' got '. $this->format_date($actual_first));
 146      $this->assertEqual($actual_last, $expected_last, "Last value should be ". $this->format_date($expected_last) .' got '. $this->format_date($actual_last));
 147    }
 148  }
 149  


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7