Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
3 |
# Copyright 2020 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 => 2; |
23 |
use Test::Exception; |
24 |
|
25 |
use t::lib::TestBuilder; |
26 |
use t::lib::Mocks; |
27 |
|
28 |
use Koha::Database; |
29 |
|
30 |
my $schema = Koha::Database->schema; |
31 |
my $builder = t::lib::TestBuilder->new; |
32 |
|
33 |
subtest 'filter_by_active() tests' => sub { |
34 |
|
35 |
plan tests => 4; |
36 |
|
37 |
$schema->storage->txn_begin; |
38 |
|
39 |
my $order_1 = $builder->build_object( |
40 |
{ |
41 |
class => 'Koha::Acquisition::Orders', |
42 |
value => { orderstatus => 'cancelled' } |
43 |
} |
44 |
); |
45 |
my $order_2 = $builder->build_object( |
46 |
{ |
47 |
class => 'Koha::Acquisition::Orders', |
48 |
value => { orderstatus => 'completed' } |
49 |
} |
50 |
); |
51 |
my $order_3 = $builder->build_object( |
52 |
{ |
53 |
class => 'Koha::Acquisition::Orders', |
54 |
value => { orderstatus => 'new' } |
55 |
} |
56 |
); |
57 |
my $order_4 = $builder->build_object( |
58 |
{ |
59 |
class => 'Koha::Acquisition::Orders', |
60 |
value => { orderstatus => 'ordered' } |
61 |
} |
62 |
); |
63 |
my $order_5 = $builder->build_object( |
64 |
{ |
65 |
class => 'Koha::Acquisition::Orders', |
66 |
value => { orderstatus => 'partial' } |
67 |
} |
68 |
); |
69 |
|
70 |
my $this_orders_rs = Koha::Acquisition::Orders->search( |
71 |
{ |
72 |
ordernumber => [ |
73 |
$order_1->ordernumber, |
74 |
$order_2->ordernumber, |
75 |
$order_3->ordernumber, |
76 |
$order_4->ordernumber, |
77 |
$order_5->ordernumber, |
78 |
] |
79 |
}, |
80 |
{ |
81 |
order_by => 'ordernumber' |
82 |
} |
83 |
); |
84 |
|
85 |
my $rs = $this_orders_rs->filter_by_active; |
86 |
|
87 |
is( $rs->count, 3, 'Only new, ordered and partial orders are returned' ); |
88 |
is( $rs->next->ordernumber, $order_3->ordernumber , 'Expected order in resultset' ); |
89 |
is( $rs->next->ordernumber, $order_4->ordernumber , 'Expected order in resultset' ); |
90 |
is( $rs->next->ordernumber, $order_5->ordernumber , 'Expected order in resultset' ); |
91 |
|
92 |
$schema->storage->txn_rollback; |
93 |
}; |
94 |
|
95 |
subtest 'filter_by_id_including_transfers() tests' => sub { |
96 |
|
97 |
plan tests => 6; |
98 |
|
99 |
$schema->storage->txn_begin; |
100 |
|
101 |
my $order_1 = $builder->build_object({ class => 'Koha::Acquisition::Orders' }); |
102 |
my $order_2 = $builder->build_object({ class => 'Koha::Acquisition::Orders' }); |
103 |
my $order_3 = $builder->build_object({ class => 'Koha::Acquisition::Orders' }); |
104 |
|
105 |
$builder->build( |
106 |
{ |
107 |
source => 'AqordersTransfer', |
108 |
value => { |
109 |
ordernumber_from => $order_1->ordernumber, |
110 |
ordernumber_to => $order_2->ordernumber |
111 |
} |
112 |
} |
113 |
); |
114 |
|
115 |
my $orders_rs = Koha::Acquisition::Orders->search; |
116 |
my $count = $orders_rs->count; |
117 |
|
118 |
throws_ok |
119 |
{ $orders_rs->filter_by_id_including_transfers() } |
120 |
'Koha::Exceptions::MissingParameter', |
121 |
'Exception thrown correctly'; |
122 |
|
123 |
$orders_rs = $orders_rs->filter_by_id_including_transfers({ ordernumber => $order_1->ordernumber }); |
124 |
|
125 |
is( $orders_rs->count, 2, 'The two referenced orders are returned' ); |
126 |
is( $orders_rs->next->ordernumber, $order_2->ordernumber, 'The right order is returned' ); |
127 |
is( $orders_rs->next->ordernumber, $order_1->ordernumber, 'The right order is returned' ); |
128 |
|
129 |
$orders_rs = $orders_rs->filter_by_id_including_transfers({ ordernumber => $order_2->ordernumber }); |
130 |
|
131 |
is( $orders_rs->count, 1, 'Only one order related to the specified ordernumber' ); |
132 |
is( $orders_rs->next->ordernumber, $order_2->ordernumber, 'The right order is returned' ); |
133 |
|
134 |
$schema->storage->txn_rollback; |
135 |
}; |