Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
3 |
# Copyright 2021 Joonas Kylmälä <joonas.kylmala@iki.fi> |
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 => 2; |
23 |
|
24 |
use Koha::Edifact::Order; |
25 |
|
26 |
use t::lib::TestBuilder; |
27 |
|
28 |
my $schema = Koha::Database->new->schema; |
29 |
|
30 |
my $builder = t::lib::TestBuilder->new; |
31 |
|
32 |
subtest 'order_line() tests' => sub { |
33 |
# TODO: Split up order_line() to smaller methods in order |
34 |
# to allow better testing |
35 |
plan tests => 2; |
36 |
|
37 |
$schema->storage->txn_begin; |
38 |
|
39 |
my $biblio = $builder->build_sample_biblio(); |
40 |
my $ean = $builder->build( { source => 'EdifactEan' } ); |
41 |
my $order = $builder->build_object( |
42 |
{ |
43 |
class => 'Koha::Acquisition::Orders', |
44 |
value => { biblionumber => $biblio->biblionumber } |
45 |
} |
46 |
); |
47 |
|
48 |
my $vendor = $builder->build( |
49 |
{ |
50 |
source => 'VendorEdiAccount', |
51 |
value => { |
52 |
vendor_id => $order->basket->bookseller->id, |
53 |
} |
54 |
} |
55 |
); |
56 |
|
57 |
my @orders = $schema->resultset('Aqorder') |
58 |
->search( { basketno => $order->basket->basketno } )->all; |
59 |
|
60 |
my $edi_order = Koha::Edifact::Order->new( |
61 |
{ |
62 |
orderlines => \@orders, |
63 |
vendor => $vendor, |
64 |
ean => $ean |
65 |
} |
66 |
); |
67 |
|
68 |
$order->basket->create_items('ordering')->store; |
69 |
|
70 |
is( $edi_order->order_line( 1, $orders[0] ), |
71 |
undef, 'Orderline message formed with with "ordering"' ); |
72 |
|
73 |
$order->basket->create_items('receiving')->store; |
74 |
|
75 |
is( $edi_order->order_line( 1, $orders[0] ), |
76 |
undef, 'Orderline message formed with "receiving"' ); |
77 |
|
78 |
$schema->storage->txn_rollback; |
79 |
}; |
80 |
|
81 |
subtest 'filename() tests' => sub { |
82 |
plan tests => 1; |
83 |
|
84 |
$schema->storage->txn_begin; |
85 |
|
86 |
my $ean = $builder->build( { source => 'EdifactEan' } ); |
87 |
my $order = |
88 |
$builder->build_object( { class => 'Koha::Acquisition::Orders' } ); |
89 |
my $vendor = $builder->build( |
90 |
{ |
91 |
source => 'VendorEdiAccount', |
92 |
value => { vendor_id => $order->basket->bookseller->id } |
93 |
} |
94 |
); |
95 |
|
96 |
my @orders = $schema->resultset('Aqorder') |
97 |
->search( { basketno => $order->basket->basketno } )->all; |
98 |
|
99 |
my $edi_order = Koha::Edifact::Order->new( |
100 |
{ |
101 |
orderlines => \@orders, |
102 |
vendor => $vendor, |
103 |
ean => $ean |
104 |
} |
105 |
); |
106 |
|
107 |
my $expected_filename = 'ordr' . $order->basket->basketno . '.CEP'; |
108 |
is( $edi_order->filename, $expected_filename, |
109 |
'Filename is formed from the basket number' ); |
110 |
|
111 |
$schema->storage->txn_rollback; |
112 |
}; |