3 # Copyright 2017 Koha Development team
5 # This file is part of Koha
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22 use Test::More tests => 3;
23 use t::lib::TestBuilder;
29 use_ok('Koha::Acquisition::Basket');
30 use_ok('Koha::Acquisition::Baskets');
32 my $schema = Koha::Database->schema;
33 my $builder = t::lib::TestBuilder->new;
35 subtest 'create_items + effective_create_items tests' => sub {
39 $schema->storage->txn_begin;
41 my $basket = $builder->build_object(
43 class => 'Koha::Acquisition::Baskets',
44 value => { create_items => undef }
47 my $created_basketno = C4::Acquisition::NewBasket(
48 $basket->booksellerid, $basket->authorisedby,
49 $basket->basketname, $basket->note,
50 $basket->booksellernote, $basket->contractnumber,
51 $basket->deliveryplace, $basket->billingplace,
52 $basket->is_standing, $basket->create_items
54 my $created_basket = Koha::Acquisition::Baskets->find($created_basketno);
55 is( $created_basket->basketno, $created_basketno,
56 "Basket created by NewBasket matches db basket" );
57 is( $basket->create_items, undef, "Create items value can be null" );
59 t::lib::Mocks::mock_preference( 'AcqCreateItem', 'cataloguing' );
60 is( $basket->effective_create_items,
62 "We use AcqCreateItem if basket create items is not set" );
63 C4::Acquisition::ModBasketHeader(
64 $basket->basketno, $basket->basketname,
65 $basket->note, $basket->booksellernote,
66 $basket->contractnumber, $basket->booksellerid,
67 $basket->deliveryplace, $basket->billingplace,
68 $basket->is_standing, "ordering"
70 my $retrieved_basket = Koha::Acquisition::Baskets->find( $basket->basketno );
71 $basket->create_items("ordering");
72 is( $retrieved_basket->create_items, "ordering", "Should be able to set with ModBasketHeader" );
73 is( $basket->create_items, "ordering", "Should be able to set with object methods" );
74 is_deeply( $retrieved_basket->unblessed,
75 $basket->unblessed, "Correct basket found and updated" );
76 is( $retrieved_basket->effective_create_items,
77 "ordering", "We use basket create items if it is set" );
79 $schema->storage->txn_rollback;