Lines 2-8
Link Here
|
2 |
|
2 |
|
3 |
use Modern::Perl; |
3 |
use Modern::Perl; |
4 |
|
4 |
|
5 |
use Test::More tests => 86; |
5 |
use Test::More tests => 88; |
6 |
use Test::MockModule; |
6 |
use Test::MockModule; |
7 |
use Test::Warn; |
7 |
use Test::Warn; |
8 |
|
8 |
|
Lines 18-23
use Koha::Acquisition::Order;
Link Here
|
18 |
|
18 |
|
19 |
BEGIN { |
19 |
BEGIN { |
20 |
use_ok('C4::Bookseller'); |
20 |
use_ok('C4::Bookseller'); |
|
|
21 |
use_ok('Koha::Acquisition::Bookseller'); |
21 |
} |
22 |
} |
22 |
|
23 |
|
23 |
can_ok( |
24 |
can_ok( |
Lines 25-32
can_ok(
Link Here
|
25 |
'C4::Bookseller', qw( |
26 |
'C4::Bookseller', qw( |
26 |
AddBookseller |
27 |
AddBookseller |
27 |
DelBookseller |
28 |
DelBookseller |
28 |
GetBookSeller |
|
|
29 |
GetBookSellerFromId |
30 |
GetBooksellersWithLateOrders |
29 |
GetBooksellersWithLateOrders |
31 |
ModBookseller ) |
30 |
ModBookseller ) |
32 |
); |
31 |
); |
Lines 43-49
$dbh->do(q|DELETE FROM aqbooksellers|);
Link Here
|
43 |
$dbh->do(q|DELETE FROM subscription|); |
42 |
$dbh->do(q|DELETE FROM subscription|); |
44 |
|
43 |
|
45 |
#Test AddBookseller |
44 |
#Test AddBookseller |
46 |
my $count = scalar( C4::Bookseller::GetBookSeller('') ); |
45 |
my $count = scalar( Koha::Acquisition::Bookseller->search() ); |
47 |
my $sample_supplier1 = { |
46 |
my $sample_supplier1 = { |
48 |
name => 'Name1', |
47 |
name => 'Name1', |
49 |
address1 => 'address1_1', |
48 |
address1 => 'address1_1', |
Lines 92-122
my $id_supplier2 = C4::Bookseller::AddBookseller($sample_supplier2);
Link Here
|
92 |
|
91 |
|
93 |
like( $id_supplier1, '/^\d+$/', "AddBookseller for supplier1 return an id" ); |
92 |
like( $id_supplier1, '/^\d+$/', "AddBookseller for supplier1 return an id" ); |
94 |
like( $id_supplier2, '/^\d+$/', "AddBookseller for supplier2 return an id" ); |
93 |
like( $id_supplier2, '/^\d+$/', "AddBookseller for supplier2 return an id" ); |
95 |
is( scalar( C4::Bookseller::GetBookSeller('') ), |
94 |
my @b = Koha::Acquisition::Bookseller->search(); |
|
|
95 |
is ( scalar(@b), |
96 |
$count + 2, "Supplier1 and Supplier2 have been added" ); |
96 |
$count + 2, "Supplier1 and Supplier2 have been added" ); |
97 |
|
97 |
|
98 |
#Test DelBookseller |
98 |
#Test DelBookseller |
99 |
my $del = C4::Bookseller::DelBookseller($id_supplier1); |
99 |
my $del = C4::Bookseller::DelBookseller($id_supplier1); |
100 |
is( $del, 1, "DelBookseller returns 1 - 1 supplier has been deleted " ); |
100 |
is( $del, 1, "DelBookseller returns 1 - 1 supplier has been deleted " ); |
101 |
is( C4::Bookseller::GetBookSellerFromId($id_supplier1), |
101 |
my $b = Koha::Acquisition::Bookseller->fetch({id => $id_supplier1}); |
102 |
undef, "Supplier1 has been deleted - id_supplier1 doesnt exist anymore" ); |
102 |
is( $b, |
|
|
103 |
undef, "Supplier1 has been deleted - id_supplier1 $id_supplier1 doesnt exist anymore" ); |
103 |
|
104 |
|
104 |
#Test GetBookSeller |
105 |
#Test GetBookSeller |
105 |
my @bookseller2 = C4::Bookseller::GetBookSeller( $sample_supplier2->{name} ); |
106 |
my @bookseller2 = Koha::Acquisition::Bookseller->search({name => $sample_supplier2->{name} }); |
106 |
is( scalar(@bookseller2), 1, "Get only Supplier2" ); |
107 |
is( scalar(@bookseller2), 1, "Get only Supplier2" ); |
107 |
$bookseller2[0] = field_filter( $bookseller2[0] ); |
108 |
$bookseller2[0] = field_filter( $bookseller2[0] ); |
108 |
delete $bookseller2[0]->{basketcount}; |
|
|
109 |
|
109 |
|
110 |
$sample_supplier2->{id} = $id_supplier2; |
110 |
$sample_supplier2->{id} = $id_supplier2; |
111 |
is_deeply( $bookseller2[0], $sample_supplier2, |
111 |
is_deeply( $bookseller2[0], $sample_supplier2, |
112 |
"GetBookSeller returns the right informations about $sample_supplier2" ); |
112 |
"Koha::Acquisition::Bookseller->search returns the right informations about $sample_supplier2" ); |
113 |
|
113 |
|
114 |
$id_supplier1 = C4::Bookseller::AddBookseller($sample_supplier1); |
114 |
$id_supplier1 = C4::Bookseller::AddBookseller($sample_supplier1); |
115 |
my @booksellers = C4::Bookseller::GetBookSeller('') |
115 |
my @booksellers = Koha::Acquisition::Bookseller->search(); #NOTE :without params, it returns all the booksellers |
116 |
; #NOTE :without params, it returns all the booksellers |
|
|
117 |
for my $i ( 0 .. scalar(@booksellers) - 1 ) { |
116 |
for my $i ( 0 .. scalar(@booksellers) - 1 ) { |
118 |
$booksellers[$i] = field_filter( $booksellers[$i] ); |
117 |
$booksellers[$i] = field_filter( $booksellers[$i] ); |
119 |
delete $booksellers[$i]->{basketcount}; |
|
|
120 |
} |
118 |
} |
121 |
|
119 |
|
122 |
$sample_supplier1->{id} = $id_supplier1; |
120 |
$sample_supplier1->{id} = $id_supplier1; |
Lines 125-157
my @tab = ( $sample_supplier1, $sample_supplier2 );
Link Here
|
125 |
is_deeply( \@booksellers, \@tab, |
123 |
is_deeply( \@booksellers, \@tab, |
126 |
"Returns right fields of Supplier1 and Supplier2" ); |
124 |
"Returns right fields of Supplier1 and Supplier2" ); |
127 |
|
125 |
|
128 |
#Test basketcount |
126 |
#Test basket_count |
129 |
my @bookseller1 = C4::Bookseller::GetBookSeller( $sample_supplier1->{name} ); |
127 |
my @bookseller1 = Koha::Acquisition::Bookseller->search({name => $sample_supplier1->{name} }); |
130 |
#FIXME : if there is 0 basket, GetBookSeller returns 1 as basketcount |
128 |
is( $bookseller1[0]->basket_count, 0, 'Supplier1 has 0 basket' ); |
131 |
#is( $bookseller1[0]->{basketcount}, 0, 'Supplier1 has 0 basket' ); |
|
|
132 |
my $basketno1 = |
129 |
my $basketno1 = |
133 |
C4::Acquisition::NewBasket( $id_supplier1, 'authorisedby1', 'basketname1' ); |
130 |
C4::Acquisition::NewBasket( $id_supplier1, 'authorisedby1', 'basketname1' ); |
134 |
my $basketno2 = |
131 |
my $basketno2 = |
135 |
C4::Acquisition::NewBasket( $id_supplier1, 'authorisedby2', 'basketname2' ); |
132 |
C4::Acquisition::NewBasket( $id_supplier1, 'authorisedby2', 'basketname2' ); |
136 |
@bookseller1 = C4::Bookseller::GetBookSeller( $sample_supplier1->{name} ); |
133 |
@bookseller1 = Koha::Acquisition::Bookseller::search({ name => $sample_supplier1->{name} }); |
137 |
is( $bookseller1[0]->{basketcount}, 2, 'Supplier1 has 2 baskets' ); |
134 |
is( $bookseller1[0]->basket_count, 2, 'Supplier1 has 2 baskets' ); |
138 |
|
135 |
|
139 |
#Test GetBookSellerFromId |
136 |
#Test Koha::Acquisition::Bookseller->new using id |
140 |
my $bookseller1fromid = C4::Bookseller::GetBookSellerFromId(); |
137 |
my $bookseller1fromid = Koha::Acquisition::Bookseller->fetch; |
141 |
is( $bookseller1fromid, undef, |
138 |
is( $bookseller1fromid, undef, |
142 |
"GetBookSellerFromId returns undef if no id given" ); |
139 |
"fetch returns undef if no id given" ); |
143 |
$bookseller1fromid = C4::Bookseller::GetBookSellerFromId($id_supplier1); |
140 |
$bookseller1fromid = Koha::Acquisition::Bookseller->fetch({ id => $id_supplier1}); |
144 |
$bookseller1fromid = field_filter($bookseller1fromid); |
141 |
$bookseller1fromid = field_filter($bookseller1fromid); |
145 |
delete $bookseller1fromid->{basketcount}; |
|
|
146 |
delete $bookseller1fromid->{subscriptioncount}; |
147 |
is_deeply( $bookseller1fromid, $sample_supplier1, |
142 |
is_deeply( $bookseller1fromid, $sample_supplier1, |
148 |
"Get Supplier1 (GetBookSellerFromId)" ); |
143 |
"Get Supplier1 (GetBookSellerFromId)" ); |
149 |
|
144 |
|
150 |
#Test basketcount |
145 |
#Test basket_count |
151 |
$bookseller1fromid = C4::Bookseller::GetBookSellerFromId($id_supplier1); |
146 |
$bookseller1fromid = Koha::Acquisition::Bookseller->fetch({ id => $id_supplier1}); |
152 |
is( $bookseller1fromid->{basketcount}, 2, 'Supplier1 has 2 baskets' ); |
147 |
is( $bookseller1fromid->basket_count, 2, 'Supplier1 has 2 baskets' ); |
153 |
|
148 |
|
154 |
#Test subscriptioncount |
149 |
#Test subscription_count |
155 |
my $dt_today = dt_from_string; |
150 |
my $dt_today = dt_from_string; |
156 |
my $today = output_pref({ dt => $dt_today, dateformat => 'iso', timeformat => '24hr', dateonly => 1 }); |
151 |
my $today = output_pref({ dt => $dt_today, dateformat => 'iso', timeformat => '24hr', dateonly => 1 }); |
157 |
|
152 |
|
Lines 178-185
$bib->append_fields(
Link Here
|
178 |
MARC::Field->new('500', ' ', ' ', a => 'bib notes'), |
173 |
MARC::Field->new('500', ' ', ' ', a => 'bib notes'), |
179 |
); |
174 |
); |
180 |
my ($biblionumber, $biblioitemnumber) = AddBiblio($bib, ''); |
175 |
my ($biblionumber, $biblioitemnumber) = AddBiblio($bib, ''); |
181 |
$bookseller1fromid = C4::Bookseller::GetBookSellerFromId($id_supplier1); |
176 |
$bookseller1fromid = Koha::Acquisition::Bookseller->fetch({ id => $id_supplier1 }); |
182 |
is( $bookseller1fromid->{subscriptioncount}, |
177 |
is( $bookseller1fromid->subscription_count, |
183 |
0, 'Supplier1 has 0 subscription' ); |
178 |
0, 'Supplier1 has 0 subscription' ); |
184 |
|
179 |
|
185 |
my $id_subscription1 = NewSubscription( |
180 |
my $id_subscription1 = NewSubscription( |
Lines 203-210
my $id_subscription2 = NewSubscription(
Link Here
|
203 |
undef, undef, 0, undef, '2013-07-31', 0 |
198 |
undef, undef, 0, undef, '2013-07-31', 0 |
204 |
); |
199 |
); |
205 |
|
200 |
|
206 |
$bookseller1fromid = C4::Bookseller::GetBookSellerFromId($id_supplier1); |
201 |
$bookseller1fromid = Koha::Acquisition::Bookseller->fetch({ id => $id_supplier1 }); |
207 |
is( $bookseller1fromid->{subscriptioncount}, |
202 |
is( $bookseller1fromid->subscription_count, |
208 |
2, 'Supplier1 has 2 subscriptions' ); |
203 |
2, 'Supplier1 has 2 subscriptions' ); |
209 |
|
204 |
|
210 |
#Test ModBookseller |
205 |
#Test ModBookseller |
Lines 235-241
is( $modif1, undef,
Link Here
|
235 |
"ModBookseller returns undef if no params given - Nothing happened" ); |
230 |
"ModBookseller returns undef if no params given - Nothing happened" ); |
236 |
$modif1 = C4::Bookseller::ModBookseller($sample_supplier2); |
231 |
$modif1 = C4::Bookseller::ModBookseller($sample_supplier2); |
237 |
is( $modif1, 1, "ModBookseller modifies only the supplier2" ); |
232 |
is( $modif1, 1, "ModBookseller modifies only the supplier2" ); |
238 |
is( scalar( C4::Bookseller::GetBookSeller('') ), |
233 |
is( scalar( Koha::Acquisition::Bookseller->search ), |
239 |
$count + 2, "Supplier2 has been modified - Nothing added" ); |
234 |
$count + 2, "Supplier2 has been modified - Nothing added" ); |
240 |
|
235 |
|
241 |
$modif1 = C4::Bookseller::ModBookseller( |
236 |
$modif1 = C4::Bookseller::ModBookseller( |
Lines 695-711
my $booksellerid = C4::Bookseller::AddBookseller(
Link Here
|
695 |
] |
690 |
] |
696 |
); |
691 |
); |
697 |
|
692 |
|
698 |
@booksellers = C4::Bookseller::GetBookSeller('my vendor'); |
693 |
@booksellers = Koha::Acquisition::Bookseller->search({ name => 'my vendor' }); |
699 |
ok( |
694 |
ok( |
700 |
( grep { $_->{'id'} == $booksellerid } @booksellers ), |
695 |
( grep { $_->{'id'} == $booksellerid } @booksellers ), |
701 |
'GetBookSeller returns correct record when passed a name' |
696 |
'Koha::Acquisition::Bookseller->search returns correct record when passed a name' |
702 |
); |
697 |
); |
703 |
|
698 |
|
704 |
my $bookseller = C4::Bookseller::GetBookSellerFromId($booksellerid); |
699 |
my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); |
705 |
is( $bookseller->{'id'}, $booksellerid, 'Retrieved desired record' ); |
700 |
is( $bookseller->{'id'}, $booksellerid, 'Retrieved desired record' ); |
706 |
is( $bookseller->{'phone'}, '0123456', 'New bookseller has expected phone' ); |
701 |
is( $bookseller->{'phone'}, '0123456', 'New bookseller has expected phone' ); |
707 |
is( ref $bookseller->{'contacts'}, |
702 |
my $contacts = $bookseller->contacts; |
708 |
'ARRAY', 'GetBookSellerFromId returns arrayref of contacts' ); |
703 |
is( ref $bookseller->contacts, |
|
|
704 |
'ARRAY', 'Koha::Acquisition::Bookseller->fetch returns arrayref of contacts' ); |
709 |
is( |
705 |
is( |
710 |
ref $bookseller->{'contacts'}->[0], |
706 |
ref $bookseller->{'contacts'}->[0], |
711 |
'C4::Bookseller::Contact', |
707 |
'C4::Bookseller::Contact', |
Lines 720-746
$bookseller->{'name'} = 'your vendor';
Link Here
|
720 |
$bookseller->{'contacts'}->[0]->phone('654321'); |
716 |
$bookseller->{'contacts'}->[0]->phone('654321'); |
721 |
C4::Bookseller::ModBookseller($bookseller); |
717 |
C4::Bookseller::ModBookseller($bookseller); |
722 |
|
718 |
|
723 |
$bookseller = C4::Bookseller::GetBookSellerFromId($booksellerid); |
719 |
$bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); |
|
|
720 |
$contacts = $bookseller->contacts; |
724 |
is( $bookseller->{'name'}, 'your vendor', |
721 |
is( $bookseller->{'name'}, 'your vendor', |
725 |
'Successfully changed name of vendor' ); |
722 |
'Successfully changed name of vendor' ); |
726 |
is( $bookseller->{'contacts'}->[0]->phone, |
723 |
is( $contacts->[0]->phone, |
727 |
'654321', |
724 |
'654321', |
728 |
'Successfully changed contact phone number by modifying bookseller hash' ); |
725 |
'Successfully changed contact phone number by modifying bookseller hash' ); |
729 |
is( scalar @{ $bookseller->{'contacts'} }, |
726 |
is( scalar @$contacts, |
730 |
1, 'Only one contact after modification' ); |
727 |
1, 'Only one contact after modification' ); |
731 |
|
728 |
|
732 |
C4::Bookseller::ModBookseller( $bookseller, |
729 |
C4::Bookseller::ModBookseller( $bookseller, |
733 |
[ { name => 'John Jacob Jingleheimer Schmidt' } ] ); |
730 |
[ { name => 'John Jacob Jingleheimer Schmidt' } ] ); |
734 |
|
731 |
|
735 |
$bookseller = C4::Bookseller::GetBookSellerFromId($booksellerid); |
732 |
$bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); |
|
|
733 |
$contacts = $bookseller->contacts; |
736 |
is( |
734 |
is( |
737 |
$bookseller->{'contacts'}->[0]->name, |
735 |
$contacts->[0]->name, |
738 |
'John Jacob Jingleheimer Schmidt', |
736 |
'John Jacob Jingleheimer Schmidt', |
739 |
'Changed name of contact' |
737 |
'Changed name of contact' |
740 |
); |
738 |
); |
741 |
is( $bookseller->{'contacts'}->[0]->phone, |
739 |
is( $contacts->[0]->phone, |
742 |
undef, 'Removed phone number from contact' ); |
740 |
undef, 'Removed phone number from contact' ); |
743 |
is( scalar @{ $bookseller->{'contacts'} }, |
741 |
is( scalar @$contacts, |
744 |
1, 'Only one contact after modification' ); |
742 |
1, 'Only one contact after modification' ); |
745 |
|
743 |
|
746 |
#End transaction |
744 |
#End transaction |