Bugzilla – Attachment 65358 Details for
Bug 17699
DateTime durations are not correctly subtracted
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 17699: Add more tests to highlight the problem
Bug-17699-Add-more-tests-to-highlight-the-problem.patch (text/plain), 8.76 KB, created by
Jonathan Druart
on 2017-07-31 15:16:25 UTC
(
hide
)
Description:
Bug 17699: Add more tests to highlight the problem
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2017-07-31 15:16:25 UTC
Size:
8.76 KB
patch
obsolete
>From 3964f03ff15784fc55bb9c13bb9bc5d0efe6c4ee Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Mon, 31 Jul 2017 11:02:42 -0300 >Subject: [PATCH] Bug 17699: Add more tests to highlight the problem > >Add problematic cases to highlight the problem. >--- > t/db_dependent/Koha/Patrons.t | 148 ++++++++++++++++++++++-------------------- > 1 file changed, 77 insertions(+), 71 deletions(-) > >diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t >index 4210d74943..f5f68252a4 100644 >--- a/t/db_dependent/Koha/Patrons.t >+++ b/t/db_dependent/Koha/Patrons.t >@@ -21,6 +21,7 @@ use Modern::Perl; > > use Test::More tests => 22; > use Test::Warn; >+use Time::Fake; > use DateTime; > > use C4::Biblio; >@@ -242,80 +243,85 @@ subtest 'is_going_to_expire' => sub { > > > subtest 'renew_account' => sub { >- plan tests => 10; >- my $a_month_ago = dt_from_string->subtract( months => 1, end_of_month => 'wrap' )->truncate( to => 'day' ); >- my $a_year_later = dt_from_string->add( months => 12 )->truncate( to => 'day' ); >- my $a_year_later_minus_a_month = dt_from_string->add( months => 11 )->truncate( to => 'day' ); >- my $a_month_later = dt_from_string->add( months => 1 )->truncate( to => 'day' ); >- my $a_year_later_plus_a_month = dt_from_string->add( months => 13 )->truncate( to => 'day' ); >- my $patron_category = $builder->build( >- { source => 'Category', >- value => { >- enrolmentperiod => 12, >- enrolmentperioddate => undef, >+ plan tests => 30; >+ >+ for my $date ( '2016-03-31', '2016-11-30', dt_from_string() ) { >+ my $dt = dt_from_string( $date, 'iso' ); >+ Time::Fake->offset( $dt->epoch ); >+ my $a_month_ago = $dt->clone->subtract( months => 1, end_of_month => "wrap" )->truncate( to => 'day' ); >+ my $a_year_later = $dt->clone->add( months => 12 )->truncate( to => 'day' ); >+ my $a_year_later_minus_a_month = $dt->clone->add( months => 11 )->truncate( to => 'day' ); >+ my $a_month_later = $dt->clone->add( months => 1 )->truncate( to => 'day' ); >+ my $a_year_later_plus_a_month = $dt->clone->add( months => 13 )->truncate( to => 'day' ); >+ my $patron_category = $builder->build( >+ { source => 'Category', >+ value => { >+ enrolmentperiod => 12, >+ enrolmentperioddate => undef, >+ } > } >- } >- ); >- my $patron = $builder->build( >- { source => 'Borrower', >- value => { >- dateexpiry => $a_month_ago, >- categorycode => $patron_category->{categorycode}, >+ ); >+ my $patron = $builder->build( >+ { source => 'Borrower', >+ value => { >+ dateexpiry => $a_month_ago, >+ categorycode => $patron_category->{categorycode}, >+ } > } >- } >- ); >- my $patron_2 = $builder->build( >- { source => 'Borrower', >- value => { >- dateexpiry => $a_month_ago, >- categorycode => $patron_category->{categorycode}, >+ ); >+ my $patron_2 = $builder->build( >+ { source => 'Borrower', >+ value => { >+ dateexpiry => $a_month_ago, >+ categorycode => $patron_category->{categorycode}, >+ } > } >- } >- ); >- my $patron_3 = $builder->build( >- { source => 'Borrower', >- value => { >- dateexpiry => $a_month_later, >- categorycode => $patron_category->{categorycode}, >- } >- } >- ); >- my $retrieved_patron = Koha::Patrons->find( $patron->{borrowernumber} ); >- my $retrieved_patron_2 = Koha::Patrons->find( $patron_2->{borrowernumber} ); >- my $retrieved_patron_3 = Koha::Patrons->find( $patron_3->{borrowernumber} ); >- >- t::lib::Mocks::mock_preference( 'BorrowerRenewalPeriodBase', 'dateexpiry' ); >- t::lib::Mocks::mock_preference( 'BorrowersLog', 1 ); >- my $expiry_date = $retrieved_patron->renew_account; >- is( $expiry_date, $a_year_later_minus_a_month, ); >- my $retrieved_expiry_date = Koha::Patrons->find( $patron->{borrowernumber} )->dateexpiry; >- is( dt_from_string($retrieved_expiry_date), $a_year_later_minus_a_month ); >- my $number_of_logs = $schema->resultset('ActionLog')->search( { module => 'MEMBERS', action => 'RENEW', object => $retrieved_patron->borrowernumber } )->count; >- is( $number_of_logs, 1, 'With BorrowerLogs, Koha::Patron->renew_account should have logged' ); >- >- t::lib::Mocks::mock_preference( 'BorrowerRenewalPeriodBase', 'now' ); >- t::lib::Mocks::mock_preference( 'BorrowersLog', 0 ); >- $expiry_date = $retrieved_patron->renew_account; >- is( $expiry_date, $a_year_later, ); >- $retrieved_expiry_date = Koha::Patrons->find( $patron->{borrowernumber} )->dateexpiry; >- is( dt_from_string($retrieved_expiry_date), $a_year_later ); >- $number_of_logs = $schema->resultset('ActionLog')->search( { module => 'MEMBERS', action => 'RENEW', object => $retrieved_patron->borrowernumber } )->count; >- is( $number_of_logs, 1, 'Without BorrowerLogs, Koha::Patron->renew_account should not have logged' ); >- >- t::lib::Mocks::mock_preference( 'BorrowerRenewalPeriodBase', 'combination' ); >- $expiry_date = $retrieved_patron_2->renew_account; >- is( $expiry_date, $a_year_later ); >- $retrieved_expiry_date = Koha::Patrons->find( $patron_2->{borrowernumber} )->dateexpiry; >- is( dt_from_string($retrieved_expiry_date), $a_year_later ); >- >- $expiry_date = $retrieved_patron_3->renew_account; >- is( $expiry_date, $a_year_later_plus_a_month ); >- $retrieved_expiry_date = Koha::Patrons->find( $patron_3->{borrowernumber} )->dateexpiry; >- is( dt_from_string($retrieved_expiry_date), $a_year_later_plus_a_month ); >- >- $retrieved_patron->delete; >- $retrieved_patron_2->delete; >- $retrieved_patron_3->delete; >+ ); >+ my $patron_3 = $builder->build( >+ { source => 'Borrower', >+ value => { >+ dateexpiry => $a_month_later, >+ categorycode => $patron_category->{categorycode}, >+ } >+ } >+ ); >+ my $retrieved_patron = Koha::Patrons->find( $patron->{borrowernumber} ); >+ my $retrieved_patron_2 = Koha::Patrons->find( $patron_2->{borrowernumber} ); >+ my $retrieved_patron_3 = Koha::Patrons->find( $patron_3->{borrowernumber} ); >+ >+ t::lib::Mocks::mock_preference( 'BorrowerRenewalPeriodBase', 'dateexpiry' ); >+ t::lib::Mocks::mock_preference( 'BorrowersLog', 1 ); >+ my $expiry_date = $retrieved_patron->renew_account; >+ is( $expiry_date, $a_year_later_minus_a_month, ); >+ my $retrieved_expiry_date = Koha::Patrons->find( $patron->{borrowernumber} )->dateexpiry; >+ is( dt_from_string($retrieved_expiry_date), $a_year_later_minus_a_month ); >+ my $number_of_logs = $schema->resultset('ActionLog')->search( { module => 'MEMBERS', action => 'RENEW', object => $retrieved_patron->borrowernumber } )->count; >+ is( $number_of_logs, 1, 'With BorrowerLogs, Koha::Patron->renew_account should have logged' ); >+ >+ t::lib::Mocks::mock_preference( 'BorrowerRenewalPeriodBase', 'now' ); >+ t::lib::Mocks::mock_preference( 'BorrowersLog', 0 ); >+ $expiry_date = $retrieved_patron->renew_account; >+ is( $expiry_date, $a_year_later, ); >+ $retrieved_expiry_date = Koha::Patrons->find( $patron->{borrowernumber} )->dateexpiry; >+ is( dt_from_string($retrieved_expiry_date), $a_year_later ); >+ $number_of_logs = $schema->resultset('ActionLog')->search( { module => 'MEMBERS', action => 'RENEW', object => $retrieved_patron->borrowernumber } )->count; >+ is( $number_of_logs, 1, 'Without BorrowerLogs, Koha::Patron->renew_account should not have logged' ); >+ >+ t::lib::Mocks::mock_preference( 'BorrowerRenewalPeriodBase', 'combination' ); >+ $expiry_date = $retrieved_patron_2->renew_account; >+ is( $expiry_date, $a_year_later ); >+ $retrieved_expiry_date = Koha::Patrons->find( $patron_2->{borrowernumber} )->dateexpiry; >+ is( dt_from_string($retrieved_expiry_date), $a_year_later ); >+ >+ $expiry_date = $retrieved_patron_3->renew_account; >+ is( $expiry_date, $a_year_later_plus_a_month ); >+ $retrieved_expiry_date = Koha::Patrons->find( $patron_3->{borrowernumber} )->dateexpiry; >+ is( dt_from_string($retrieved_expiry_date), $a_year_later_plus_a_month ); >+ >+ $retrieved_patron->delete; >+ $retrieved_patron_2->delete; >+ $retrieved_patron_3->delete; >+ } > }; > > subtest "move_to_deleted" => sub { >-- >2.11.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 17699
:
57827
|
65358
|
65359
|
65360
|
65365
|
65366
|
65367
|
65369
|
65370
|
65371
|
65372
|
65400
|
65419
|
65420
|
65421
|
65422