Bug 21087: Hash passwords in ->update_password
[koha.git] / t / db_dependent / Koha / Acquisition / Basket.t
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
22 use Test::More tests => 3;
23 use t::lib::TestBuilder;
24 use t::lib::Mocks;
25
26 use C4::Acquisition;
27 use Koha::Database;
28
29 use_ok('Koha::Acquisition::Basket');
30 use_ok('Koha::Acquisition::Baskets');
31
32 my $schema  = Koha::Database->schema;
33 my $builder = t::lib::TestBuilder->new;
34
35 subtest 'create_items + effective_create_items tests' => sub {
36
37     plan tests => 7;
38
39     $schema->storage->txn_begin;
40
41     my $basket = $builder->build_object(
42         {
43             class => 'Koha::Acquisition::Baskets',
44             value => { create_items => undef }
45         }
46     );
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
53     );
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" );
58
59     t::lib::Mocks::mock_preference( 'AcqCreateItem', 'cataloguing' );
60     is( $basket->effective_create_items,
61         "cataloguing",
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"
69     );
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" );
78
79     $schema->storage->txn_rollback;
80 };