From fde4a2ab6964fabc5591e7268602277e07b3ffd8 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Sun, 28 Feb 2016 14:13:45 +0100 Subject: [PATCH] Bug 15956: Rearranging some SIP unit tests Content-Type: text/plain; charset=utf-8 The original SIP_ILS.t is split up into SIP/Patron.t and SIP/Transaction.t. The assumption on a hardcoded existing and non-existing card number is replaced by adding and deleting a card number (:patron) with TestBuilder. Test plan: Run SIP/Patron.t Run SIP/Transaction.t Signed-off-by: Marcel de Rooy --- t/db_dependent/SIP/Patron.t | 29 +++++++++++++++++++++++++++++ t/db_dependent/SIP/Transaction.t | 28 ++++++++++++++++++++++++++++ t/db_dependent/SIP_ILS.t | 27 --------------------------- 3 files changed, 57 insertions(+), 27 deletions(-) create mode 100755 t/db_dependent/SIP/Patron.t create mode 100755 t/db_dependent/SIP/Transaction.t delete mode 100755 t/db_dependent/SIP_ILS.t diff --git a/t/db_dependent/SIP/Patron.t b/t/db_dependent/SIP/Patron.t new file mode 100755 index 0000000..b089ca0 --- /dev/null +++ b/t/db_dependent/SIP/Patron.t @@ -0,0 +1,29 @@ +#!/usr/bin/perl + +# Some tests for SIP::ILS::Patron +# This needs to be extended! Your help is appreciated.. + +use Modern::Perl; +use Test::More tests => 2; + +use Koha::Database; +use t::lib::TestBuilder; +use C4::SIP::ILS::Patron; + +my $schema = Koha::Database->new->schema; +$schema->storage->txn_begin; + +my $builder = t::lib::TestBuilder->new(); +my $patron1 = $builder->build({ source => 'Borrower' }); +my $card = $patron1->{cardnumber}; + +# Check existing card number +my $sip_patron = C4::SIP::ILS::Patron->new( $card ); +is( defined $sip_patron, 1, "Patron is valid" ); + +# Check invalid cardnumber by deleting patron +$schema->resultset('Borrower')->search({ cardnumber => $card })->delete; +my $sip_patron2 = C4::SIP::ILS::Patron->new( $card ); +is( $sip_patron2, undef, "Patron is not valid (anymore)" ); + +$schema->storage->txn_rollback; diff --git a/t/db_dependent/SIP/Transaction.t b/t/db_dependent/SIP/Transaction.t new file mode 100755 index 0000000..01889b4 --- /dev/null +++ b/t/db_dependent/SIP/Transaction.t @@ -0,0 +1,28 @@ +#!/usr/bin/perl + +# Tests for SIP::ILS::Transaction +# Current state is very rudimentary. Please help to extend it! + +use Modern::Perl; +use Test::More tests => 3; + +use Koha::Database; +use t::lib::TestBuilder; +use C4::SIP::ILS::Patron; +use C4::SIP::ILS::Transaction::RenewAll; + +my $schema = Koha::Database->new->schema; +$schema->storage->txn_begin; + +my $builder = t::lib::TestBuilder->new(); +my $borr1 = $builder->build({ source => 'Borrower' }); +my $card = $borr1->{cardnumber}; +my $sip_patron = C4::SIP::ILS::Patron->new( $card ); + +# Create transaction RenewAll, assign patron, and run (no items) +my $transaction = C4::SIP::ILS::Transaction::RenewAll->new(); +is( ref $transaction, "C4::SIP::ILS::Transaction::RenewAll", "New transaction created" ); +is( $transaction->patron( $sip_patron ), $sip_patron, "Patron assigned to transaction" ); +isnt( $transaction->do_renew_all, undef, "RenewAll on zero items" ); + +$schema->storage->txn_rollback; diff --git a/t/db_dependent/SIP_ILS.t b/t/db_dependent/SIP_ILS.t deleted file mode 100755 index c9879dc..0000000 --- a/t/db_dependent/SIP_ILS.t +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/perl -# -# This Koha test module is a stub! -# Add more tests here!!! - -use strict; -use warnings; - -use Test::More tests => 4; - -BEGIN { - use_ok('C4::SIP::ILS'); -}; - -my $transaction = C4::SIP::ILS::Transaction::RenewAll->new(); - -$transaction->patron(my $patron = C4::SIP::ILS::Patron->new(23529000120056)); - -ok(defined $patron, "patron code: 23529000120056 is valid"); - -my $transaction2 = C4::SIP::ILS::Transaction::RenewAll->new(); -$transaction2->patron(my $patron2 = C4::SIP::ILS::Patron->new("ABCDE12345")); - -#This test assumes that the patron code ABCDE12345 is invalid -ok(!defined $patron2, "patron code: ABCDE12345 is invalid"); - -ok($transaction->do_renew_all(), "items renewed correctly"); -- 1.7.10.4