Bug 26384: Fix executable flags
[koha.git] / t / db_dependent / Koha / Acquisition / Invoice / Adjustments.t
blob3419672b797341a5d795fc37a3df84903e4e4c49
1 #!/usr/bin/perl
3 # Copyright 2015 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 => 8;
24 use Koha::Database;
26 use t::lib::TestBuilder;
28 BEGIN {
29 use_ok('Koha::Acquisition::Invoice::Adjustments');
32 my $schema = Koha::Database->new->schema;
33 $schema->storage->txn_begin;
35 my $builder = t::lib::TestBuilder->new;
36 my $nb_of_adjs = Koha::Acquisition::Invoice::Adjustments->search->count;
37 my $budget_id = $builder->build({source=>'Aqbudget'})->{budget_id};
38 my $invoice_id = $builder->build({source=>'Aqinvoice'})->{invoiceid};
40 my $new_adj = Koha::Acquisition::Invoice::Adjustment->new({
41 note => 'noted',
42 invoiceid => $invoice_id,
43 adjustment => '3',
44 reason => 'unreasonable',
45 budget_id => $budget_id,
46 })->store;
48 like( $new_adj->adjustment_id, qr|^\d+$|, 'Adding a new adjustment should have set the adjustment_id');
50 my $new_adj2 = Koha::Acquisition::Invoice::Adjustment->new({
51 note => 'not noted',
52 invoiceid => $invoice_id,
53 adjustment => '-3',
54 reason => 'unreasonable',
55 budget_id => $budget_id,
56 })->store;
58 ok( $new_adj->adjustment_id < $new_adj2->adjustment_id, 'Adding a new adjustment should increment');
59 is( Koha::Acquisition::Invoice::Adjustments->search->count, $nb_of_adjs + 2, 'The 2 adjustments should have been added' );
61 my $retrieved_adj = Koha::Acquisition::Invoice::Adjustments->find( $new_adj->adjustment_id );
62 is( $retrieved_adj->reason, $new_adj->reason, 'Find an adjustment by id should return the correct adjustment' );
64 $retrieved_adj->delete;
65 is( Koha::Acquisition::Invoice::Adjustments->search->count, $nb_of_adjs + 1, 'Delete should have deleted the adjustment' );
67 subtest 'invoice' => sub {
68 plan tests => 2;
70 my $invoice = $retrieved_adj->invoice;
71 is( ref( $invoice ), 'Koha::Acquisition::Invoice', 'Koha::Acquisition::Invoice::Adjustment->invoice should return a Koha::Acquisition::Invoice' );
72 is( $invoice->invoiceid, $retrieved_adj->invoiceid, 'Koha::Acquisition::Invoice::Adjustment->invoice should return the correct invoice' );
75 subtest 'fund' => sub {
76 plan tests => 2;
78 my $fund = $retrieved_adj->fund;
79 is( ref( $fund ), 'Koha::Acquisition::Fund', 'Koha::Acquisition::Invoice::Adjustment->fund should return a Koha::Acquisition::Fund' );
80 is( $fund->budget_id, $retrieved_adj->budget_id, 'Koha::Acquisition::Invoice::Adjustment->fund should return the correct fund ' );
83 $schema->storage->txn_rollback;