From a0f3b881800e25acb1cc30f27f1b4ab1b6f44a40 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 --- t/db_dependent/Koha/Biblio.t | 54 +++++++++++++++++++++ t/db_dependent/Koha/{ItemTypes.pm => ItemTypes.t} | 57 ++++++++++++++--------- 2 files changed, 90 insertions(+), 21 deletions(-) create mode 100755 t/db_dependent/Koha/Biblio.t 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 new file mode 100755 index 0000000..4596015 --- /dev/null +++ b/t/db_dependent/Koha/Biblio.t @@ -0,0 +1,54 @@ +#!/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 under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Test::More tests => 17; +use Data::Dumper; +use Koha::Database; + +BEGIN { + use_ok('Koha::Biblio'); +} + +my $database = Koha::Database->new(); +my $schema = $database->schema(); +$schema->txn_begin; + +# Make a MARC::Record + +# Make a Koha::Biblio from it + +# Verify that the fields saved correctly + +# Delete all biblios currently in the DB (for testing) + +# Save our biblio to the database (will need to implement this) + +# Fetch it + +# Verify that the fields are correct + +# Get an iterator + +# Verify that the biblio it returns is correct + +my $biblios = Koha::ItemTypes->new(); + +$schema->txn_rollback; 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 dfefd08..b6e61bc 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; -- 1.9.1