Bug 20199: Add tests for Koha::Acq::Order->store
[koha.git] / t / db_dependent / Koha / Acquisition / Order.t
blobed9ebc0c48230da64326f9359a7d60b72111f71c
1 #!/usr/bin/perl
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>.
20 use Modern::Perl;
22 use Test::More tests => 2;
24 use t::lib::TestBuilder;
25 use t::lib::Mocks;
27 use Koha::Database;
29 my $schema = Koha::Database->schema;
30 my $builder = t::lib::TestBuilder->new;
32 subtest 'basket() tests' => sub {
34 plan tests => 2;
36 $schema->storage->txn_begin;
38 my $basket = $builder->build_object(
40 class => 'Koha::Acquisition::Baskets'
43 my $order = $builder->build_object(
45 class => 'Koha::Acquisition::Orders',
46 value => { basketno => $basket->basketno }
50 my $retrieved_basket = $order->basket;
51 is( ref($retrieved_basket), 'Koha::Acquisition::Basket',
52 'Type is correct for ->basket' );
53 is_deeply( $retrieved_basket->unblessed,
54 $basket->unblessed, "Correct basket found and updated" );
56 $schema->storage->txn_rollback;
59 subtest 'store' => sub {
60 plan tests => 1;
62 $schema->storage->txn_begin;
63 my $o = $builder->build_object(
65 class => 'Koha::Acquisition::Orders'
69 subtest 'entrydate' => sub {
70 plan tests => 2;
72 my $order;
74 t::lib::Mocks::mock_preference( 'TimeFormat', '12hr' );
75 $order = Koha::Acquisition::Order->new(
77 basketno => $o->basketno,
78 biblionumber => $o->biblionumber,
79 budget_id => $o->budget_id,
81 )->store;
82 $order->discard_changes;
83 like( $order->entrydate, qr|^\d{4}-\d{2}-\d{2}$| );
85 t::lib::Mocks::mock_preference( 'TimeFormat', '24hr' );
86 $order = Koha::Acquisition::Order->new(
88 basketno => $o->basketno,
89 biblionumber => $o->biblionumber,
90 budget_id => $o->budget_id,
92 )->store;
93 $order->discard_changes;
94 like( $order->entrydate, qr|^\d{4}-\d{2}-\d{2}$| );
96 $schema->storage->txn_rollback;