[Bps-public-commit] r9502 - RT-Extension-SLA/t

sunnavy at bestpractical.com sunnavy at bestpractical.com
Tue Oct 30 09:09:31 EDT 2007


Author: sunnavy
Date: Tue Oct 30 09:09:30 2007
New Revision: 9502

Modified:
   RT-Extension-SLA/t/starts.t

Log:
more accuate tests

Modified: RT-Extension-SLA/t/starts.t
==============================================================================
--- RT-Extension-SLA/t/starts.t	(original)
+++ RT-Extension-SLA/t/starts.t	Tue Oct 30 09:09:30 2007
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 9;
+use Test::More tests => 12; 
 
 require 't/utils.pl';
 
@@ -15,51 +15,68 @@
 
 use_ok 'RT::Extension::SLA';
 
+use Test::MockTime qw( :all );
+
 my $bhours = RT::Extension::SLA->BusinessHours;
 
 diag 'check Starts date';
 {
     %RT::SLA = (
         Default => 'standard',
-        Levels => {
+        Levels  => {
             'standard' => {
-                Response => 2*60,
-                Resolve => 7*60*24,
+                Response => 2 * 60,
+                Resolve  => 7 * 60 * 24,
             },
         },
     );
+    %RT::BusinessHours = (
+        Default => {
+            1 => {
+                Name  => 'Monday',
+                Start => '09:00',
+                End   => '17:00'
+            },
+            2 => {
+                Name  => 'Tuesday',
+                Start => '09:00',
+                End   => '17:00'
+            },
+        }
+    );
 
-    my $time = time;
-
-    my $ticket = RT::Ticket->new( $RT::SystemUser );
-    my ($id) = $ticket->Create( Queue => 'General', Subject => 'xxx' );
-    ok $id, "created ticket #$id";
+    my %time = (
+        '2007-01-01T13:15:00Z' => 1167657300,    # 2007-01-01T13:15:00Z
+        '2007-01-01T19:15:00Z' => 1167728400,    # 2007-01-02T09:00:00Z
+        '2007-01-06T13:15:00Z' => 1168246800,    # 2007-01-08T09:00:00Z
+    );
 
-    my $starts = $ticket->StartsObj->Unix;
-    ok $starts > 0, 'Starts date is set';
-    if ( $bhours->first_after($time) == $time ) {
-        # in hours
-        ok $starts - $time < 5, 'Starts is quite correct';
-    } else {
-        ok $starts - $time > 5 , 'Starts is quite correct';
+    for my $time ( keys %time ) {
+        set_absolute_time($time);
+        my $ticket = RT::Ticket->new($RT::SystemUser);
+        my ($id) = $ticket->Create( Queue => 'General', Subject => 'xxx' );
+        ok $id, "created ticket #$id";
+        is $ticket->StartsObj->Unix, $time{$time}, 'Starts date is right';
     }
+
+    restore_time();
 }
 
 diag 'check Starts date with StartImmediately enabled';
 {
     %RT::SLA = (
         Default => 'start immediately',
-        Levels => {
+        Levels  => {
             'start immediately' => {
                 StartImmediately => 1,
-                Response => 2*60,
-                Resolve => 7*60*24,
+                Response         => 2 * 60,
+                Resolve          => 7 * 60 * 24,
             },
         },
     );
     my $time = time;
 
-    my $ticket = RT::Ticket->new( $RT::SystemUser );
+    my $ticket = RT::Ticket->new($RT::SystemUser);
     my ($id) = $ticket->Create( Queue => 'General', Subject => 'xxx' );
     ok $id, "created ticket #$id";
 



More information about the Bps-public-commit mailing list