|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
| 3 |
# Copyright 2017 Koha Development team |
| 4 |
# |
| 5 |
# This file is part of Koha |
| 6 |
# |
| 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. |
| 11 |
# |
| 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. |
| 16 |
# |
| 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>. |
| 19 |
|
| 20 |
use Modern::Perl; |
| 21 |
use Test::More tests => 8; |
| 22 |
use Koha::Database; |
| 23 |
use t::lib::TestBuilder; |
| 24 |
use t::lib::Mocks; |
| 25 |
use C4::Acquisition; |
| 26 |
|
| 27 |
use_ok('Koha::Acquisition::Basket'); |
| 28 |
use_ok('Koha::Acquisition::Baskets'); |
| 29 |
|
| 30 |
my $schema = Koha::Database->schema; |
| 31 |
$schema->storage->txn_begin; |
| 32 |
my $dbh = C4::Context->dbh; |
| 33 |
|
| 34 |
# Start transaction |
| 35 |
$dbh->{RaiseError} = 1; |
| 36 |
|
| 37 |
my $builder = t::lib::TestBuilder->new; |
| 38 |
my $basket = $builder->build_object({ class => 'Koha::Acquisition::Baskets', value => { create_items => undef } }); |
| 39 |
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); |
| 40 |
my $created_basket = Koha::Acquisition::Baskets->find({ basketno => $created_basketno }); |
| 41 |
is($created_basket->basketno, $created_basketno, "Basket created by NewBasket matches db basket"); |
| 42 |
is( $basket->create_items, undef, "Create items value can be null"); |
| 43 |
t::lib::Mocks::mock_preference('AcqCreateItem', 'cataloguing'); |
| 44 |
is( $basket->effective_create_items, "cataloguing","We use AcqCreateItem if basket create items is not set"); |
| 45 |
C4::Acquisition::ModBasketHeader($basket->basketno, $basket->basketname, $basket->note, $basket->booksellernote, $basket->contractnumber, $basket->booksellerid, $basket->deliveryplace, $basket->billingplace, $basket->is_standing, "ordering"); |
| 46 |
my $retrieved_basket = Koha::Acquisition::Baskets->find({ basketno => $basket->basketno }); |
| 47 |
$basket->create_items("ordering"); |
| 48 |
is( $retrieved_basket->create_items, "ordering", "Should be able to set with ModBasketHeader"); |
| 49 |
is( $basket->create_items, "ordering", "Should be able to set with object methods"); |
| 50 |
is_deeply($retrieved_basket->unblessed, $basket->unblessed, "Correct basket found and updated"); |
| 51 |
is( $retrieved_basket->effective_create_items, "ordering","We use basket create items if it is set"); |