From 6d31aa88bf3abeaf1b6f220f5e520438cc70c164 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Thu, 5 Oct 2017 11:12:57 -0300 Subject: [PATCH] Bug 15685: (QA followup) Tidy tests Signed-off-by: Tomas Cohen Arazi Signed-off-by: Nick Clemens --- t/db_dependent/Koha/Acquisition/Basket.t | 73 ++++++++++++++++++++++---------- 1 file changed, 51 insertions(+), 22 deletions(-) diff --git a/t/db_dependent/Koha/Acquisition/Basket.t b/t/db_dependent/Koha/Acquisition/Basket.t index 0ba7367..8965c89 100644 --- a/t/db_dependent/Koha/Acquisition/Basket.t +++ b/t/db_dependent/Koha/Acquisition/Basket.t @@ -18,34 +18,63 @@ # along with Koha; if not, see . use Modern::Perl; -use Test::More tests => 8; -use Koha::Database; + +use Test::More tests => 3; use t::lib::TestBuilder; use t::lib::Mocks; + use C4::Acquisition; +use Koha::Database; use_ok('Koha::Acquisition::Basket'); use_ok('Koha::Acquisition::Baskets'); -my $schema = Koha::Database->schema; -$schema->storage->txn_begin; -my $dbh = C4::Context->dbh; +my $schema = Koha::Database->schema; +my $builder = t::lib::TestBuilder->new; + +subtest 'create_items + effective_create_items tests' => sub { -# Start transaction -$dbh->{RaiseError} = 1; + plan tests => 7; -my $builder = t::lib::TestBuilder->new; -my $basket = $builder->build_object({ class => 'Koha::Acquisition::Baskets', value => { create_items => undef } }); -my $created_basketno = C4::Acquisition::NewBasket($basket->booksellerid, $basket->authorisedby, $basket->basketname,$basket->note, $basket->booksellernote, $basket->contractnumber, $basket->deliveryplace, $basket->billingplace, $basket->is_standing, $basket->create_items); -my $created_basket = Koha::Acquisition::Baskets->find({ basketno => $created_basketno }); -is($created_basket->basketno, $created_basketno, "Basket created by NewBasket matches db basket"); -is( $basket->create_items, undef, "Create items value can be null"); -t::lib::Mocks::mock_preference('AcqCreateItem', 'cataloguing'); -is( $basket->effective_create_items, "cataloguing","We use AcqCreateItem if basket create items is not set"); -C4::Acquisition::ModBasketHeader($basket->basketno, $basket->basketname, $basket->note, $basket->booksellernote, $basket->contractnumber, $basket->booksellerid, $basket->deliveryplace, $basket->billingplace, $basket->is_standing, "ordering"); -my $retrieved_basket = Koha::Acquisition::Baskets->find({ basketno => $basket->basketno }); -$basket->create_items("ordering"); -is( $retrieved_basket->create_items, "ordering", "Should be able to set with ModBasketHeader"); -is( $basket->create_items, "ordering", "Should be able to set with object methods"); -is_deeply($retrieved_basket->unblessed, $basket->unblessed, "Correct basket found and updated"); -is( $retrieved_basket->effective_create_items, "ordering","We use basket create items if it is set"); + $schema->storage->txn_begin; + + my $basket = $builder->build_object( + { + class => 'Koha::Acquisition::Baskets', + value => { create_items => undef } + } + ); + my $created_basketno = C4::Acquisition::NewBasket( + $basket->booksellerid, $basket->authorisedby, + $basket->basketname, $basket->note, + $basket->booksellernote, $basket->contractnumber, + $basket->deliveryplace, $basket->billingplace, + $basket->is_standing, $basket->create_items + ); + my $created_basket = Koha::Acquisition::Baskets->find($created_basketno); + is( $created_basket->basketno, $created_basketno, + "Basket created by NewBasket matches db basket" ); + is( $basket->create_items, undef, "Create items value can be null" ); + + t::lib::Mocks::mock_preference( 'AcqCreateItem', 'cataloguing' ); + is( $basket->effective_create_items, + "cataloguing", + "We use AcqCreateItem if basket create items is not set" ); + C4::Acquisition::ModBasketHeader( + $basket->basketno, $basket->basketname, + $basket->note, $basket->booksellernote, + $basket->contractnumber, $basket->booksellerid, + $basket->deliveryplace, $basket->billingplace, + $basket->is_standing, "ordering" + ); + my $retrieved_basket = Koha::Acquisition::Baskets->find( $basket->basketno ); + $basket->create_items("ordering"); + is( $retrieved_basket->create_items, "ordering", "Should be able to set with ModBasketHeader" ); + is( $basket->create_items, "ordering", "Should be able to set with object methods" ); + is_deeply( $retrieved_basket->unblessed, + $basket->unblessed, "Correct basket found and updated" ); + is( $retrieved_basket->effective_create_items, + "ordering", "We use basket create items if it is set" ); + + $schema->storage->txn_rollback; +}; -- 2.1.4