From c7eee93d2f7540dedc3badc00af48d4905f605db Mon Sep 17 00:00:00 2001 From: Robin Sheat Date: Tue, 23 Sep 2014 17:32:57 +1200 Subject: [PATCH] Bug 12478 - add test cases Signed-off-by: Nick Clemens Signed-off-by: Jesse Weaver Signed-off-by: Tomas Cohen Arazi Signed-off-by: Kyle M Hall Signed-off-by: Brendan Gallagher --- t/db_dependent/Koha/Biblio.t | 4 +- .../Koha/{ItemTypes.pm => ItemTypes.t} | 57 ++++++++++++------- 2 files changed, 39 insertions(+), 22 deletions(-) rename t/db_dependent/Koha/{ItemTypes.pm => ItemTypes.t} (55%) diff --git a/t/db_dependent/Koha/Biblio.t b/t/db_dependent/Koha/Biblio.t index be340b6db6..b247d8bbbd 100755 --- a/t/db_dependent/Koha/Biblio.t +++ b/t/db_dependent/Koha/Biblio.t @@ -1,5 +1,7 @@ #!/usr/bin/perl - +# +# Copyright 2014 Catalyst IT +# # This file is part of Koha. # # Koha is free software; you can redistribute it and/or modify it diff --git a/t/db_dependent/Koha/ItemTypes.pm b/t/db_dependent/Koha/ItemTypes.t similarity index 55% rename from t/db_dependent/Koha/ItemTypes.pm rename to t/db_dependent/Koha/ItemTypes.t index dfefd08ce8..b6e61bcc13 100755 --- a/t/db_dependent/Koha/ItemTypes.pm +++ b/t/db_dependent/Koha/ItemTypes.t @@ -17,49 +17,64 @@ # with Koha; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -# XXX This doesn't work because I need to figure out how to do transactions -# in a test-case with DBIx::Class - use Modern::Perl; -use Test::More tests => 8; +use Test::More tests => 17; use Data::Dumper; +use Koha::Database; BEGIN { use_ok('Koha::ItemTypes'); } -my $dbh = C4::Context->dbh; - -# Start transaction -$dbh->{AutoCommit} = 0; -$dbh->{RaiseError} = 1; - -my $prep = $dbh->prepare('INSERT INTO itemtypes (itemtype, description, rentalcharge, imageurl, summary, checkinmsg, checkinmsgtype) VALUES (?,?,?,?,?,?,?)'); -$prep->execute('type1', 'description', 'rentalcharge', 'imageurl', 'summary', 'checkinmsg', 'checkinmsgtype'); -$prep->execute('type2', 'description', 'rentalcharge', 'imageurl', 'summary', 'checkinmsg', 'checkinmsgtype'); +my $database = Koha::Database->new(); +my $schema = $database->schema(); +$schema->txn_begin; +$schema->resultset('Itemtype')->create( + { + itemtype => 'type1', + description => 'description', + rentalcharge => '0.00', + imageurl => 'imageurl', + summary => 'summary', + checkinmsg => 'checkinmsg', + checkinmsgtype => 'checkinmsgtype', + } +); +$schema->resultset('Itemtype')->create( + { + itemtype => 'type2', + description => 'description', + rentalcharge => '0.00', + imageurl => 'imageurl', + summary => 'summary', + checkinmsg => 'checkinmsg', + checkinmsgtype => 'checkinmsgtype', + } +); my $itypes = Koha::ItemTypes->new(); -my @types = $itypes->get_itemtype('type1', 'type2'); +my @types = $itypes->get_itemtype( 'type1', 'type2' ); -die Dumper(\@types); my $type = $types[0]; -ok(defined($type), 'first result'); -is( $type->code, 'type1', 'itemtype/code' ); +ok( defined($type), 'first result' ); +is( $type->code, 'type1', 'itemtype/code' ); is( $type->description, 'description', 'description' ); -is( $type->rentalcharge, 'rentalcharge', 'rentalcharge' ); +is( $type->rentalcharge, '0.0000', 'rentalcharge' ); is( $type->imageurl, 'imageurl', 'imageurl' ); is( $type->summary, 'summary', 'summary' ); is( $type->checkinmsg, 'checkinmsg', 'checkinmsg' ); is( $type->checkinmsgtype, 'checkinmsgtype', 'checkinmsgtype' ); $type = $types[1]; -ok(defined($type), 'second result'); -is( $type->code, 'type2', 'itemtype/code' ); +ok( defined($type), 'second result' ); +is( $type->code, 'type2', 'itemtype/code' ); is( $type->description, 'description', 'description' ); -is( $type->rentalcharge, 'rentalcharge', 'rentalcharge' ); +is( $type->rentalcharge, '0.0000', 'rentalcharge' ); is( $type->imageurl, 'imageurl', 'imageurl' ); is( $type->summary, 'summary', 'summary' ); is( $type->checkinmsg, 'checkinmsg', 'checkinmsg' ); is( $type->checkinmsgtype, 'checkinmsgtype', 'checkinmsgtype' ); + +$schema->txn_rollback; -- 2.39.5