From e1f940ee7853bffae6e15a5fc932796fd5a9829a Mon Sep 17 00:00:00 2001 From: Martin Persson Date: Mon, 1 Jun 2015 13:56:56 +0200 Subject: [PATCH] Bug 14246: Update NewsChannel tests This commit adds the new 'borrowernumber' field to the existing test framework to make it pass. It does not include new tests. Sponsored-by: Halland County Library Signed-off-by: Nick Clemens --- t/db_dependent/NewsChannels.t | 45 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/NewsChannels.t b/t/db_dependent/NewsChannels.t index f0a86e0..3818dac 100644 --- a/t/db_dependent/NewsChannels.t +++ b/t/db_dependent/NewsChannels.t @@ -3,7 +3,7 @@ use Modern::Perl; use C4::Dates qw(format_date); use C4::Branch qw(GetBranchName); -use Test::More tests => 10; +use Test::More tests => 11; BEGIN { use_ok('C4::NewsChannels'); @@ -22,6 +22,46 @@ if ( !GetBranchName($addbra) ) { undef, ( $addbra, "$addbra branch" ) ); } +# Add CAT1, if it doesn't exist. +my $addcat = 'CAT1'; +{ + my $sth = $dbh->prepare( q{ SELECT categorycode FROM categories WHERE categorycode = ? } ); + $sth->execute ( $addcat ); + if ( not defined $sth->fetchrow () ) { + diag("Category $addcat not found, inserting"); + $dbh->do( q{ INSERT INTO categories (categorycode,description) VALUES (?,?) }, + undef, ( $addcat, "$addcat description") ); + } +} + +# Add a test user if not already present. +my $addbrwr = 'BRWR1'; +my $brwrnmbr; +{ + my $query = + q{ SELECT borrowernumber from borrowers WHERE surname = ? AND branchcode = ? AND categorycode = ? }; + my $sth = $dbh->prepare( $query ); + $sth->execute( ($addbrwr, $addbra, $addcat) ); + $brwrnmbr = $sth->fetchrow; + + # Not found, let us insert it. + if ( not defined $brwrnmbr ) { + diag("Borrower $addbrwr not found, inserting"); + $dbh->do( q{ INSERT INTO borrowers (surname, address, city, branchcode, categorycode) VALUES (?, ?, ?, ?, ?) }, + undef, ($addbrwr, '(test) address', '(test) city', $addbra, $addcat) ); + + # Retrieve the njew borrower number. + $query = + q{ SELECT borrowernumber from borrowers WHERE surname = ? AND branchcode = ? AND categorycode = ? }; + my $sth = $dbh->prepare( $query ); + $sth->execute( ($addbrwr, $addbra, $addcat) ); + $brwrnmbr = $sth->fetchrow; + } +} + +# Must have valid borrower number, or tests are meaningless. +ok ( defined $brwrnmbr ); + # Test add_opac_new my $rv = add_opac_new(); # intentionally bad ok( $rv == 0, 'Correctly failed on no parameter!' ); @@ -52,6 +92,7 @@ my $href_entry2 = { expirationdate => $expirationdate2, timestamp => $timestamp2, number => $number2, + borrowernumber => $brwrnmbr, branchcode => 'LIB1', }; $rv = add_opac_new($href_entry2); @@ -95,6 +136,7 @@ is_deeply( expirationdate => $expirationdate1, timestamp => $timestamp1, number => $number1, + borrowernumber => undef, idnew => $idnew1, branchname => "$addbra branch", branchcode => $addbra, @@ -117,6 +159,7 @@ is_deeply( expirationdate => $expirationdate2, timestamp => $timestamp2, number => $number2, + borrowernumber => $brwrnmbr, idnew => $idnew2, branchname => "$addbra branch", branchcode => $addbra, -- 1.9.1