Bugzilla – Attachment 42673 Details for
Bug 14368
Add discharges history
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 14368: Add some missing tests
Bug-14368-Add-some-missing-tests.patch (text/plain), 7.85 KB, created by
Jonathan Druart
on 2015-09-17 14:03:30 UTC
(
hide
)
Description:
Bug 14368: Add some missing tests
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2015-09-17 14:03:30 UTC
Size:
7.85 KB
patch
obsolete
>From 3e79b7d5334d5d2934cb663281737d326f4a09a7 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Thu, 17 Sep 2015 10:27:42 +0100 >Subject: [PATCH] Bug 14368: Add some missing tests > >Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >--- > members/discharge.pl | 1 - > t/db_dependent/Borrower_Discharge.t | 70 ++++++++++++++++++++++--------------- > 2 files changed, 42 insertions(+), 29 deletions(-) > >diff --git a/members/discharge.pl b/members/discharge.pl >index 61a73fa..d1a021d 100755 >--- a/members/discharge.pl >+++ b/members/discharge.pl >@@ -101,7 +101,6 @@ if ( $input->param('borrowernumber') ) { > # Already generated discharges > my $validated_discharges = Koha::Borrower::Discharge::get_validated({ > borrowernumber => $borrowernumber, >- branchcode => $data->{'branchcode'}, > }); > > $template->param( >diff --git a/t/db_dependent/Borrower_Discharge.t b/t/db_dependent/Borrower_Discharge.t >index 793283c..97b22d7 100644 >--- a/t/db_dependent/Borrower_Discharge.t >+++ b/t/db_dependent/Borrower_Discharge.t >@@ -1,7 +1,7 @@ > #!/usr/bin/perl; > > use Modern::Perl; >-use Test::More; >+use Test::More tests => 15; > use Test::Warn; > use MARC::Record; > >@@ -11,62 +11,78 @@ use C4::Context; > use C4::Items qw( AddItem ); > use C4::Members qw( AddMember GetMember ); > >+use t::lib::TestBuilder; > use Koha::Borrower::Discharge; > >+my $builder = t::lib::TestBuilder->new; > my $dbh = C4::Context->dbh; >-$dbh->{AutoCommit} = 0; >-$dbh->{RaiseError} = 1; >- > $dbh->do(q|DELETE FROM discharges|); > > C4::Context->_new_userenv('xxx'); > C4::Context->set_userenv(0, 0, 0, 'firstname', 'surname', 'CPL', 'CPL', '', '', '', '', ''); >- >-my $borrowernumber = AddMember( >- cardnumber => 'UTCARD1', >- firstname => 'my firstname', >- surname => 'my surname', >- categorycode => 'S', >- branchcode => 'CPL', >-); >-my $borrower = GetMember( borrowernumber => $borrowernumber ); >+my $branchcode = 'CPL'; >+my $another_branchcode = 'MPL'; >+my $borrower = $builder->build({ >+ source => 'Borrower', >+ value => { >+ branchcode => $branchcode, >+ } >+}); >+my $borrower2 = $builder->build({ >+ source => 'Borrower', >+ value => { >+ branchcode => $branchcode, >+ } >+}); >+my $borrower3 = $builder->build({ >+ source => 'Borrower', >+ value => { >+ branchcode => $another_branchcode, >+ } >+}); > > # Discharge not possible with issues > my ( $biblionumber ) = AddBiblio( MARC::Record->new, ''); > my $barcode = 'BARCODE42'; > my ( undef, undef, $itemnumber ) = AddItem({ homebranch => 'CPL', holdingbranch => 'CPL', barcode => $barcode }, $biblionumber); > AddIssue( $borrower, $barcode ); >-is( Koha::Borrower::Discharge::can_be_discharged({ borrowernumber => $borrowernumber }), 0, 'A patron with issues cannot be discharged' ); >+is( Koha::Borrower::Discharge::can_be_discharged({ borrowernumber => $borrower->{borrowernumber} }), 0, 'A patron with issues cannot be discharged' ); > >-is( Koha::Borrower::Discharge::request({ borrowernumber => $borrowernumber }), undef, 'No request done if patron has issues' ); >-is( Koha::Borrower::Discharge::discharge({ borrowernumber => $borrowernumber }), undef, 'No discharge done if patron has issues' ); >+is( Koha::Borrower::Discharge::request({ borrowernumber => $borrower->{borrowernumber} }), undef, 'No request done if patron has issues' ); >+is( Koha::Borrower::Discharge::discharge({ borrowernumber => $borrower->{borrowernumber} }), undef, 'No discharge done if patron has issues' ); > is_deeply( Koha::Borrower::Discharge::get_pendings(), [], 'There is no pending discharge request' ); >+is_deeply( Koha::Borrower::Discharge::get_validated(), [], 'There is no validated discharge' ); > > AddReturn( $barcode ); > > # Discharge possible without issue >-is( Koha::Borrower::Discharge::can_be_discharged({ borrowernumber => $borrowernumber }), 1, 'A patron without issues can be discharged' ); >+is( Koha::Borrower::Discharge::can_be_discharged({ borrowernumber => $borrower->{borrowernumber} }), 1, 'A patron without issues can be discharged' ); > > is(Koha::Borrower::Discharge::generate_as_pdf,undef,"Confirm failure when lacking borrower number"); > > # Verify that the user is not discharged anymore if the restriction has been lifted >-Koha::Borrower::Discharge::discharge({ borrowernumber => $borrowernumber }); >-is( Koha::Borrower::Discharge::is_discharged({ borrowernumber => $borrowernumber }), 1, 'The patron has been discharged' ); >-is(Koha::Borrower::Debarments::IsDebarred($borrowernumber), '9999-12-31', 'The patron has been debarred after discharge'); >-Koha::Borrower::Debarments::DelUniqueDebarment({'borrowernumber' => $borrowernumber, 'type' => 'DISCHARGE'}); >-ok(! Koha::Borrower::Debarments::IsDebarred($borrowernumber), 'The debarment has been lifted'); >-ok(! Koha::Borrower::Discharge::is_discharged({ borrowernumber => $borrowernumber }), 'The patron is not discharged after the restriction has been lifted' ); >+Koha::Borrower::Discharge::discharge( { borrowernumber => $borrower->{borrowernumber} } ); >+Koha::Borrower::Discharge::discharge( { borrowernumber => $borrower2->{borrowernumber} } ); >+Koha::Borrower::Discharge::discharge( { borrowernumber => $borrower3->{borrowernumber} } ); >+is( Koha::Borrower::Discharge::is_discharged( { borrowernumber => $borrower->{borrowernumber} } ), 1, 'The patron has been discharged' ); >+is( Koha::Borrower::Debarments::IsDebarred( $borrower->{borrowernumber} ), '9999-12-31', 'The patron has been debarred after discharge' ); >+is( scalar( @{ Koha::Borrower::Discharge::get_validated() } ), 3, 'There are 3 validated discharges' ); >+is( scalar( @{ Koha::Borrower::Discharge::get_validated( { borrowernumber => $borrower->{borrowernumber} } ) } ), 1, 'There is 1 validated discharge for a given patron' ); >+is( scalar( @{ Koha::Borrower::Discharge::get_validated( { branchcode => 'CPL' } ) } ), 2, 'There is 2 validated discharges for a given branchcode' ); # This is not used in the code yet >+Koha::Borrower::Debarments::DelUniqueDebarment( { 'borrowernumber' => $borrower->{borrowernumber}, 'type' => 'DISCHARGE' } ); >+ok( !Koha::Borrower::Debarments::IsDebarred( $borrower->{borrowernumber} ), 'The debarment has been lifted' ); >+ok( !Koha::Borrower::Discharge::is_discharged( { borrowernumber => $borrower->{borrowernumber} } ), 'The patron is not discharged after the restriction has been lifted' ); > > # Check if PDF::FromHTML is installed. > my $check = eval { require PDF::FromHTML; }; > > # Tests for if PDF::FromHTML is installed > if ($check) { >- isnt( Koha::Borrower::Discharge::generate_as_pdf({ borrowernumber => $borrowernumber }), undef, "Temporary PDF generated." ); >+ isnt( Koha::Borrower::Discharge::generate_as_pdf({ borrowernumber => $borrower->{borrowernumber} }), undef, "Temporary PDF generated." ); > } > # Tests for if PDF::FromHTML is not installed > else { >- warning_like { Koha::Borrower::Discharge::generate_as_pdf({ borrowernumber => $borrowernumber, testing => 1 }) } >+ warning_like { Koha::Borrower::Discharge::generate_as_pdf({ borrowernumber => $borrower->{borrowernumber}, testing => 1 }) } > [ qr/Can't locate PDF\/FromHTML.pm in \@INC/ ], > "Expected failure because of missing PDF::FromHTML."; > } >@@ -79,6 +95,4 @@ else { > # Even if we switch off this flag, the connection will be blocked. > # The error is: > # DBIx::Class::ResultSet::create(): DBI Exception: DBD::mysql::st execute failed: Lock wait timeout exceeded; try restarting transaction [for Statement "INSERT INTO discharges ( borrower, needed, validated) VALUES ( ?, ?, ? )" with ParamValues: 0='121', 1='2014-01-08T16:38:29', 2=undef] at /home/koha/src/Koha/DataObject/Discharge.pm line 33 >-#is( Koha::Service::Borrower::Discharge::request({ borrowernumber => $borrowernumber }), 1, 'Discharge request sent' ); >- >-done_testing; >+#is( Koha::Service::Borrower::Discharge::request({ borrowernumber => $borrower->{borrowernumber} }), 1, 'Discharge request sent' ); >-- >2.1.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 14368
:
40079
|
40171
|
40508
|
40512
|
42593
|
42598
|
42640
|
42670
|
42671
|
42672
| 42673 |
42720
|
42723
|
42930