Fix the tests, to be month-agnostic.
Patch by kareila.
diffs (97 lines):
diff -r 3790a30e36df -r dee8e6dde855 t/paid-time.t
--- a/t/paid-time.t Fri Jun 11 11:40:23 2010 +0800
+++ b/t/paid-time.t Fri Jun 11 13:12:39 2010 +0800
@@ -10,6 +10,11 @@ plan tests => 29;
plan tests => 29;
my $u1 = temp_user();
+my $paidmos = 0;
+
+my @lt = localtime();
+my $mdays = LJ::days_in_month( $lt[4] + 1, $lt[5] + 1900 );
+die "Could not calculate days in month" unless $mdays;
my $dbh = LJ::get_db_writer();
@@ -17,17 +22,19 @@ sub rst {
sub rst {
$dbh->do( 'DELETE FROM dw_paidstatus WHERE userid = ?', undef, $_ )
foreach ( $u1->id );
+ $paidmos = 0;
}
sub assert {
- my ( $u, $type, $secs ) = @_;
+ my ( $u, $type ) = @_;
my ($typeid) = grep { $LJ::CAP{$_}->{_account_type} eq $type } keys
%LJ::CAP;
ok( $typeid, 'valid class' );
my $ps = DW::Pay::get_paid_status( $u );
+ my $secs = 86400 * $paidmos;
ok( $ps, 'got paid status' );
ok( $ps->{typeid} == $typeid, 'typeids match' );
- ok( $ps->{expiresin} == $secs, 'secs match' );
+ ok( abs( $ps->{expiresin} - $secs) < 60, 'secs match within a minute' );
}
################################################################################
@@ -36,46 +43,52 @@ rst();
# free->paid 1 month
DW::Pay::add_paid_time( $u1, 'paid', 1 )
or die DW::Pay::error_text();
+$paidmos += $mdays; # 30
-assert( $u1, 'paid', 30*86400 );
+assert( $u1, 'paid' );
# paid +1 month
DW::Pay::add_paid_time( $u1, 'paid', 1 )
or die DW::Pay::error_text();
+$paidmos += $mdays; # 60
-assert( $u1, 'paid', 60*86400 );
+assert( $u1, 'paid' );
# premium +1 month
DW::Pay::add_paid_time( $u1, 'premium', 1 )
or die DW::Pay::error_text();
+$paidmos = $paidmos * 0.7 + $mdays;
# should be 72 days... they bought 1 month of premium time (30 days)
# and they had 60 days of paid. 60 days of paid converts to 42 days
# of premium, 42+30 = 72 days premium.
-assert( $u1, 'premium', 72*86400 );
+assert( $u1, 'premium' );
# premium +1 month
DW::Pay::add_paid_time( $u1, 'premium', 1 )
or die DW::Pay::error_text();
+$paidmos += $mdays; # 102
-assert( $u1, 'premium', 102*86400 );
+assert( $u1, 'premium' );
# paid +1 month == premium +21 days
DW::Pay::add_paid_time( $u1, 'paid', 1 )
or die DW::Pay::error_text();
+$paidmos += int( $mdays * 0.7 ); # 123
-assert( $u1, 'premium', 123*86400 );
+assert( $u1, 'premium' );
################################################################################
# seed account
DW::Pay::add_paid_time( $u1, 'seed', 99 )
or die DW::Pay::error_text();
+$paidmos = 0; # never expires
-assert( $u1, 'seed', 0 );
+assert( $u1, 'seed' );
ok( ! DW::Pay::add_paid_time( $u1, 'paid', 1 ), 'adding paid time fails' );
-assert( $u1, 'seed', 0 );
+assert( $u1, 'seed' );
################################################################################
_______________________________________________
dw-changelog mailing list
[email protected]
http://lists.dwscoalition.org/mailman/listinfo/dw-changelog