[Koha-patches] [PATCH] Follow up for bug 5880: Improved unit test
Julian Maurice
julian.maurice at biblibre.com
Thu Mar 17 14:33:02 CET 2011
The unit test Koha.t now skip tests of the two subroutines if the insert
query failed.
---
t/db_dependent/Koha.t | 22 +++++++++++++++-------
1 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/t/db_dependent/Koha.t b/t/db_dependent/Koha.t
index bdbb348..016525a 100644
--- a/t/db_dependent/Koha.t
+++ b/t/db_dependent/Koha.t
@@ -7,7 +7,7 @@ use strict;
use warnings;
use C4::Context;
-use Test::More tests => 3;
+use Test::More tests => 4;
BEGIN {
use_ok('C4::Koha');
@@ -26,14 +26,22 @@ my $dbh = C4::Context->dbh;
# Insert an entry into authorised_value table
my $query = "INSERT INTO authorised_values (category, authorised_value, lib, lib_opac, imageurl) VALUES (?,?,?,?,?);";
my $sth = $dbh->prepare($query);
-$sth->execute($data->{category}, $data->{authorised_value}, $data->{lib}, $data->{lib_opac}, $data->{imageurl});
+my $insert_success = $sth->execute($data->{category}, $data->{authorised_value}, $data->{lib}, $data->{lib_opac}, $data->{imageurl});
+ok($insert_success, "Insert data in database");
+
# Tests
-is ( GetAuthorisedValueByCode($data->{category}, $data->{authorised_value}), $data->{lib}, "GetAuthorisedValueByCode" );
-is ( GetKohaImageurlFromAuthorisedValues($data->{category}, $data->{lib}), $data->{imageurl}, "GetKohaImageurlFromAuthorisedValues" );
+SKIP: {
+ skip "INSERT failed", 2 unless $insert_success;
+
+ is ( GetAuthorisedValueByCode($data->{category}, $data->{authorised_value}), $data->{lib}, "GetAuthorisedValueByCode" );
+ is ( GetKohaImageurlFromAuthorisedValues($data->{category}, $data->{lib}), $data->{imageurl}, "GetKohaImageurlFromAuthorisedValues" );
+}
# Clean up
-$query = "DELETE FROM authorised_values WHERE category=? AND authorised_value=? AND lib=? AND lib_opac=? AND imageurl=?;";
-$sth = $dbh->prepare($query);
-$sth->execute($data->{category}, $data->{authorised_value}, $data->{lib}, $data->{lib_opac}, $data->{imageurl});
+if($insert_success){
+ $query = "DELETE FROM authorised_values WHERE category=? AND authorised_value=? AND lib=? AND lib_opac=? AND imageurl=?;";
+ $sth = $dbh->prepare($query);
+ $sth->execute($data->{category}, $data->{authorised_value}, $data->{lib}, $data->{lib_opac}, $data->{imageurl});
+}
--
1.7.4.1
More information about the Koha-patches
mailing list