Lines 2-8
Link Here
|
2 |
|
2 |
|
3 |
use Modern::Perl; |
3 |
use Modern::Perl; |
4 |
|
4 |
|
5 |
use Test::More tests => 88; |
5 |
use Test::More tests => 86; |
6 |
use Test::MockModule; |
6 |
use Test::MockModule; |
7 |
use Test::Warn; |
7 |
use Test::Warn; |
8 |
|
8 |
|
Lines 15-35
use C4::Serials;
Link Here
|
15 |
use C4::Budgets; |
15 |
use C4::Budgets; |
16 |
use C4::Biblio; |
16 |
use C4::Biblio; |
17 |
|
17 |
|
|
|
18 |
use Koha::Acquisition::Booksellers; |
18 |
use Koha::Acquisition::Order; |
19 |
use Koha::Acquisition::Order; |
19 |
use Koha::Database; |
20 |
use Koha::Database; |
20 |
|
21 |
|
21 |
BEGIN { |
22 |
BEGIN { |
22 |
use_ok('C4::Bookseller'); |
23 |
use_ok('C4::Bookseller'); |
23 |
use_ok('Koha::Acquisition::Bookseller'); |
|
|
24 |
} |
24 |
} |
25 |
|
25 |
|
26 |
can_ok( |
26 |
can_ok( |
27 |
|
27 |
|
28 |
'C4::Bookseller', qw( |
28 |
'C4::Bookseller', qw( |
29 |
AddBookseller |
|
|
30 |
DelBookseller |
31 |
GetBooksellersWithLateOrders |
29 |
GetBooksellersWithLateOrders |
32 |
ModBookseller ) |
30 |
) |
33 |
); |
31 |
); |
34 |
|
32 |
|
35 |
#Start transaction |
33 |
#Start transaction |
Lines 47-53
$dbh->do(q|DELETE FROM aqbooksellers|);
Link Here
|
47 |
$dbh->do(q|DELETE FROM subscription|); |
45 |
$dbh->do(q|DELETE FROM subscription|); |
48 |
|
46 |
|
49 |
#Test AddBookseller |
47 |
#Test AddBookseller |
50 |
my $count = scalar( Koha::Acquisition::Bookseller->search() ); |
48 |
my $count = Koha::Acquisition::Booksellers->search()->count(); |
51 |
my $sample_supplier1 = { |
49 |
my $sample_supplier1 = { |
52 |
name => 'Name1', |
50 |
name => 'Name1', |
53 |
address1 => 'address1_1', |
51 |
address1 => 'address1_1', |
Lines 89-125
my $sample_supplier2 = {
Link Here
|
89 |
deliverytime => 2 |
87 |
deliverytime => 2 |
90 |
}; |
88 |
}; |
91 |
|
89 |
|
92 |
my $id_supplier1 = C4::Bookseller::AddBookseller($sample_supplier1); |
90 |
my $supplier1 = Koha::Acquisition::Bookseller->new($sample_supplier1)->store; |
93 |
my $id_supplier2 = C4::Bookseller::AddBookseller($sample_supplier2); |
91 |
my $id_supplier1 = $supplier1->id; |
94 |
|
92 |
my $supplier2 = Koha::Acquisition::Bookseller->new($sample_supplier2)->store; |
95 |
#my $id_bookseller3 = C4::Bookseller::AddBookseller();# NOTE : Doesn't work because the field name cannot be null |
93 |
my $id_supplier2 = $supplier2->id; |
96 |
|
94 |
|
97 |
like( $id_supplier1, '/^\d+$/', "AddBookseller for supplier1 return an id" ); |
95 |
like( $id_supplier1, '/^\d+$/', "AddBookseller for supplier1 return an id" ); |
98 |
like( $id_supplier2, '/^\d+$/', "AddBookseller for supplier2 return an id" ); |
96 |
like( $id_supplier2, '/^\d+$/', "AddBookseller for supplier2 return an id" ); |
99 |
my @b = Koha::Acquisition::Bookseller->search(); |
97 |
is( Koha::Acquisition::Booksellers->search()->count, |
100 |
is ( scalar(@b), |
|
|
101 |
$count + 2, "Supplier1 and Supplier2 have been added" ); |
98 |
$count + 2, "Supplier1 and Supplier2 have been added" ); |
102 |
|
99 |
|
103 |
#Test DelBookseller |
100 |
#Test DelBookseller |
104 |
my $del = C4::Bookseller::DelBookseller($id_supplier1); |
101 |
my $del = $supplier1->delete; |
105 |
is( $del, 1, "DelBookseller returns 1 - 1 supplier has been deleted " ); |
102 |
is( $del, 1, "DelBookseller returns 1 - 1 supplier has been deleted " ); |
106 |
my $b = Koha::Acquisition::Bookseller->fetch({id => $id_supplier1}); |
103 |
my $b = Koha::Acquisition::Booksellers->find( $id_supplier1 ); |
107 |
is( $b, |
104 |
is( $b, |
108 |
undef, "Supplier1 has been deleted - id_supplier1 $id_supplier1 doesnt exist anymore" ); |
105 |
undef, "Supplier1 has been deleted - id_supplier1 $id_supplier1 doesnt exist anymore" ); |
109 |
|
106 |
|
110 |
#Test get bookseller |
107 |
#Test get bookseller |
111 |
my @bookseller2 = Koha::Acquisition::Bookseller->search({name => $sample_supplier2->{name} }); |
108 |
my @bookseller2 = Koha::Acquisition::Booksellers->search({name => $sample_supplier2->{name} }); |
112 |
is( scalar(@bookseller2), 1, "Get only Supplier2" ); |
109 |
is( scalar(@bookseller2), 1, "Get only Supplier2" ); |
113 |
$bookseller2[0] = field_filter( $bookseller2[0] ); |
110 |
for my $bookseller ( @bookseller2 ) { |
|
|
111 |
$bookseller = field_filter( $bookseller->unblessed ); |
112 |
} |
114 |
|
113 |
|
115 |
$sample_supplier2->{id} = $id_supplier2; |
114 |
$sample_supplier2->{id} = $id_supplier2; |
116 |
is_deeply( $bookseller2[0], $sample_supplier2, |
115 |
is_deeply( $bookseller2[0], $sample_supplier2, |
117 |
"Koha::Acquisition::Bookseller->search returns the right informations about $sample_supplier2" ); |
116 |
"Koha::Acquisition::Booksellers->search returns the right informations about supplier $sample_supplier2->{name}" ); |
118 |
|
117 |
|
119 |
$id_supplier1 = C4::Bookseller::AddBookseller($sample_supplier1); |
118 |
$supplier1 = Koha::Acquisition::Bookseller->new($sample_supplier1)->store; |
120 |
my @booksellers = Koha::Acquisition::Bookseller->search(); #NOTE :without params, it returns all the booksellers |
119 |
$id_supplier1 = $supplier1->id; |
121 |
for my $i ( 0 .. scalar(@booksellers) - 1 ) { |
120 |
my @booksellers = Koha::Acquisition::Booksellers->search(); |
122 |
$booksellers[$i] = field_filter( $booksellers[$i] ); |
121 |
for my $bookseller ( @booksellers ) { |
|
|
122 |
$bookseller = field_filter( $bookseller->unblessed ); |
123 |
} |
123 |
} |
124 |
|
124 |
|
125 |
$sample_supplier1->{id} = $id_supplier1; |
125 |
$sample_supplier1->{id} = $id_supplier1; |
Lines 128-157
my @tab = ( $sample_supplier1, $sample_supplier2 );
Link Here
|
128 |
is_deeply( \@booksellers, \@tab, |
128 |
is_deeply( \@booksellers, \@tab, |
129 |
"Returns right fields of Supplier1 and Supplier2" ); |
129 |
"Returns right fields of Supplier1 and Supplier2" ); |
130 |
|
130 |
|
131 |
#Test basket_count |
131 |
#Test baskets |
132 |
my @bookseller1 = Koha::Acquisition::Bookseller->search({name => $sample_supplier1->{name} }); |
132 |
my @bookseller1 = Koha::Acquisition::Booksellers->search({name => $sample_supplier1->{name} }); |
133 |
is( $bookseller1[0]->basket_count, 0, 'Supplier1 has 0 basket' ); |
133 |
is( $bookseller1[0]->baskets->count, 0, 'Supplier1 has 0 basket' ); |
134 |
my $basketno1 = |
134 |
my $basketno1 = |
135 |
C4::Acquisition::NewBasket( $id_supplier1, 'authorisedby1', 'basketname1' ); |
135 |
C4::Acquisition::NewBasket( $id_supplier1, 'authorisedby1', 'basketname1' ); |
136 |
my $basketno2 = |
136 |
my $basketno2 = |
137 |
C4::Acquisition::NewBasket( $id_supplier1, 'authorisedby2', 'basketname2' ); |
137 |
C4::Acquisition::NewBasket( $id_supplier1, 'authorisedby2', 'basketname2' ); |
138 |
@bookseller1 = Koha::Acquisition::Bookseller::search({ name => $sample_supplier1->{name} }); |
138 |
@bookseller1 = Koha::Acquisition::Booksellers->search({ name => $sample_supplier1->{name} }); |
139 |
is( $bookseller1[0]->basket_count, 2, 'Supplier1 has 2 baskets' ); |
139 |
is( $bookseller1[0]->baskets->count, 2, 'Supplier1 has 2 baskets' ); |
140 |
|
140 |
|
141 |
#Test Koha::Acquisition::Bookseller->new using id |
141 |
#Test Koha::Acquisition::Bookseller->new using id |
142 |
my $bookseller1fromid = Koha::Acquisition::Bookseller->fetch; |
142 |
my $bookseller1fromid = Koha::Acquisition::Booksellers->find; |
143 |
is( $bookseller1fromid, undef, |
143 |
is( $bookseller1fromid, undef, |
144 |
"fetch returns undef if no id given" ); |
144 |
"find returns undef if no id given" ); |
145 |
$bookseller1fromid = Koha::Acquisition::Bookseller->fetch({ id => $id_supplier1}); |
145 |
$bookseller1fromid = Koha::Acquisition::Booksellers->find( $id_supplier1 ); |
146 |
$bookseller1fromid = field_filter($bookseller1fromid); |
146 |
$bookseller1fromid = field_filter($bookseller1fromid->unblessed); |
147 |
is_deeply( $bookseller1fromid, $sample_supplier1, |
147 |
is_deeply( $bookseller1fromid, $sample_supplier1, |
148 |
"Get Supplier1 (fetch a bookseller by id)" ); |
148 |
"Get Supplier1 (find a bookseller by id)" ); |
149 |
|
149 |
|
150 |
#Test basket_count |
150 |
$bookseller1fromid = Koha::Acquisition::Booksellers->find( $id_supplier1 ); |
151 |
$bookseller1fromid = Koha::Acquisition::Bookseller->fetch({ id => $id_supplier1}); |
151 |
is( $bookseller1fromid->baskets->count, 2, 'Supplier1 has 2 baskets' ); |
152 |
is( $bookseller1fromid->basket_count, 2, 'Supplier1 has 2 baskets' ); |
|
|
153 |
|
152 |
|
154 |
#Test subscription_count |
153 |
#Test subscriptions |
155 |
my $dt_today = dt_from_string; |
154 |
my $dt_today = dt_from_string; |
156 |
my $today = output_pref({ dt => $dt_today, dateformat => 'iso', timeformat => '24hr', dateonly => 1 }); |
155 |
my $today = output_pref({ dt => $dt_today, dateformat => 'iso', timeformat => '24hr', dateonly => 1 }); |
157 |
|
156 |
|
Lines 178-185
$bib->append_fields(
Link Here
|
178 |
MARC::Field->new('500', ' ', ' ', a => 'bib notes'), |
177 |
MARC::Field->new('500', ' ', ' ', a => 'bib notes'), |
179 |
); |
178 |
); |
180 |
my ($biblionumber, $biblioitemnumber) = AddBiblio($bib, ''); |
179 |
my ($biblionumber, $biblioitemnumber) = AddBiblio($bib, ''); |
181 |
$bookseller1fromid = Koha::Acquisition::Bookseller->fetch({ id => $id_supplier1 }); |
180 |
$bookseller1fromid = Koha::Acquisition::Booksellers->find( $id_supplier1 ); |
182 |
is( $bookseller1fromid->subscription_count, |
181 |
is( $bookseller1fromid->subscriptions->count, |
183 |
0, 'Supplier1 has 0 subscription' ); |
182 |
0, 'Supplier1 has 0 subscription' ); |
184 |
|
183 |
|
185 |
my $id_subscription1 = NewSubscription( |
184 |
my $id_subscription1 = NewSubscription( |
Lines 203-210
my $id_subscription2 = NewSubscription(
Link Here
|
203 |
undef, undef, 0, undef, '2013-07-31', 0 |
202 |
undef, undef, 0, undef, '2013-07-31', 0 |
204 |
); |
203 |
); |
205 |
|
204 |
|
206 |
$bookseller1fromid = Koha::Acquisition::Bookseller->fetch({ id => $id_supplier1 }); |
205 |
$bookseller1fromid = Koha::Acquisition::Booksellers->find( $id_supplier1 ); |
207 |
is( $bookseller1fromid->subscription_count, |
206 |
is( $bookseller1fromid->subscriptions->count, |
208 |
2, 'Supplier1 has 2 subscriptions' ); |
207 |
2, 'Supplier1 has 2 subscriptions' ); |
209 |
|
208 |
|
210 |
#Test ModBookseller |
209 |
#Test ModBookseller |
Lines 230-251
$sample_supplier2 = {
Link Here
|
230 |
deliverytime => 2, |
229 |
deliverytime => 2, |
231 |
}; |
230 |
}; |
232 |
|
231 |
|
233 |
my $modif1 = C4::Bookseller::ModBookseller(); |
232 |
my $modif1 = Koha::Acquisition::Booksellers->find($id_supplier2)->set($sample_supplier2)->store; |
234 |
is( $modif1, undef, |
233 |
is( ref $modif1, 'Koha::Acquisition::Bookseller', "ModBookseller has updated the bookseller" ); |
235 |
"ModBookseller returns undef if no params given - Nothing happened" ); |
234 |
is( Koha::Acquisition::Booksellers->search->count, |
236 |
$modif1 = C4::Bookseller::ModBookseller($sample_supplier2); |
|
|
237 |
is( $modif1, 1, "ModBookseller modifies only the supplier2" ); |
238 |
is( scalar( Koha::Acquisition::Bookseller->search ), |
239 |
$count + 2, "Supplier2 has been modified - Nothing added" ); |
235 |
$count + 2, "Supplier2 has been modified - Nothing added" ); |
240 |
|
236 |
$supplier2 = Koha::Acquisition::Booksellers->find($id_supplier2); |
241 |
$modif1 = C4::Bookseller::ModBookseller( |
237 |
is( $supplier2->name, 'Name2 modified', "supplier's name should have been modified" ); |
242 |
{ |
|
|
243 |
id => -1, |
244 |
name => 'name3' |
245 |
} |
246 |
); |
247 |
#is( $modif1, '0E0', |
248 |
# "ModBookseller returns OEO if the id doesnt exist - Nothing modified" ); |
249 |
|
238 |
|
250 |
#Test GetBooksellersWithLateOrders |
239 |
#Test GetBooksellersWithLateOrders |
251 |
#Add 2 suppliers |
240 |
#Add 2 suppliers |
Lines 288-295
my $sample_supplier4 = {
Link Here
|
288 |
discount => '3.0000', |
277 |
discount => '3.0000', |
289 |
notes => 'notes3', |
278 |
notes => 'notes3', |
290 |
}; |
279 |
}; |
291 |
my $id_supplier3 = C4::Bookseller::AddBookseller($sample_supplier3); |
280 |
my $supplier3 = Koha::Acquisition::Bookseller->new($sample_supplier3)->store; |
292 |
my $id_supplier4 = C4::Bookseller::AddBookseller($sample_supplier4); |
281 |
my $id_supplier3 = $supplier3->id; |
|
|
282 |
my $supplier4 = Koha::Acquisition::Bookseller->new($sample_supplier4)->store; |
283 |
my $id_supplier4 = $supplier4->id; |
293 |
|
284 |
|
294 |
#Add 2 baskets |
285 |
#Add 2 baskets |
295 |
my $basketno3 = |
286 |
my $basketno3 = |
Lines 681-749
is(
Link Here
|
681 |
3, |
672 |
3, |
682 |
'superlibrarian can see all subscriptions with IndependentBranches on (bug 12048)' |
673 |
'superlibrarian can see all subscriptions with IndependentBranches on (bug 12048)' |
683 |
); |
674 |
); |
|
|
675 |
|
684 |
#Test contact editing |
676 |
#Test contact editing |
685 |
my $booksellerid = C4::Bookseller::AddBookseller( |
677 |
my $sample_supplier = { |
686 |
{ |
|
|
687 |
name => "my vendor", |
678 |
name => "my vendor", |
688 |
address1 => "bookseller's address", |
679 |
address1 => "bookseller's address", |
689 |
phone => "0123456", |
680 |
phone => "0123456", |
690 |
active => 1 |
681 |
active => 1 |
691 |
}, |
682 |
}; |
692 |
[ |
683 |
my $supplier = Koha::Acquisition::Bookseller->new($sample_supplier)->store; |
693 |
{ name => 'John Smith', phone => '0123456x1' }, |
684 |
my $booksellerid = $supplier->id; |
694 |
{ name => 'Leo Tolstoy', phone => '0123456x2' }, |
685 |
my $contact1 = Koha::Acquisition::Bookseller::Contact->new({ |
695 |
] |
686 |
name => 'John Smith', |
696 |
); |
687 |
phone => '0123456x1', |
697 |
|
688 |
booksellerid => $booksellerid, |
698 |
@booksellers = Koha::Acquisition::Bookseller->search({ name => 'my vendor' }); |
689 |
})->store; |
|
|
690 |
my $contact2 = Koha::Acquisition::Bookseller::Contact->new({ |
691 |
name => 'Leo Tolstoy', |
692 |
phone => '0123456x2', |
693 |
booksellerid => $booksellerid, |
694 |
})->store; |
695 |
|
696 |
@booksellers = Koha::Acquisition::Booksellers->search({ name => 'my vendor' }); |
699 |
ok( |
697 |
ok( |
700 |
( grep { $_->{'id'} == $booksellerid } @booksellers ), |
698 |
( grep { $_->id == $booksellerid } @booksellers ), |
701 |
'Koha::Acquisition::Bookseller->search returns correct record when passed a name' |
699 |
'Koha::Acquisition::Booksellers->search returns correct record when passed a name' |
702 |
); |
700 |
); |
703 |
|
701 |
|
704 |
my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); |
702 |
my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid ); |
705 |
is( $bookseller->{'id'}, $booksellerid, 'Retrieved desired record' ); |
703 |
is( $bookseller->id, $booksellerid, 'Retrieved desired record' ); |
706 |
is( $bookseller->{'phone'}, '0123456', 'New bookseller has expected phone' ); |
704 |
is( $bookseller->phone, '0123456', 'New bookseller has expected phone' ); |
707 |
my $contacts = $bookseller->contacts; |
705 |
my $contacts = $bookseller->contacts; |
708 |
is( ref $bookseller->contacts, |
706 |
is( $contacts->count, |
709 |
'ARRAY', 'Koha::Acquisition::Bookseller->fetch returns arrayref of contacts' ); |
707 |
2, 'bookseller should have 2 contacts' ); |
|
|
708 |
my $first_contact = $contacts->next; |
710 |
is( |
709 |
is( |
711 |
ref $bookseller->{'contacts'}->[0], |
710 |
ref $first_contact, |
712 |
'C4::Bookseller::Contact', |
711 |
'Koha::Acquisition::Bookseller::Contact', |
713 |
'First contact is a contact object' |
712 |
'First contact is a AqContact' |
714 |
); |
713 |
); |
715 |
is( $bookseller->{'contacts'}->[0]->phone, |
714 |
is( $first_contact->phone, |
716 |
'0123456x1', 'Contact has expected phone number' ); |
715 |
'0123456x1', 'Contact has expected phone number' ); |
717 |
is( scalar @{ $bookseller->{'contacts'} }, 2, 'Saved two contacts' ); |
|
|
718 |
|
716 |
|
719 |
pop @{ $bookseller->{'contacts'} }; |
717 |
my $second_contact = $contacts->next; |
720 |
$bookseller->{'name'} = 'your vendor'; |
718 |
$second_contact->delete; |
721 |
$bookseller->{'contacts'}->[0]->phone('654321'); |
719 |
$bookseller = Koha::Acquisition::Booksellers->find( $booksellerid ); |
722 |
C4::Bookseller::ModBookseller($bookseller); |
720 |
$bookseller->name('your vendor')->store; |
723 |
|
|
|
724 |
$bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); |
725 |
$contacts = $bookseller->contacts; |
721 |
$contacts = $bookseller->contacts; |
726 |
is( $bookseller->{'name'}, 'your vendor', |
722 |
$first_contact = $contacts->next; |
|
|
723 |
$first_contact->phone('654321'); |
724 |
$first_contact->store; |
725 |
|
726 |
$bookseller = Koha::Acquisition::Booksellers->find( $booksellerid ); |
727 |
is( $bookseller->name, 'your vendor', |
727 |
'Successfully changed name of vendor' ); |
728 |
'Successfully changed name of vendor' ); |
728 |
is( $contacts->[0]->phone, |
729 |
$contacts = $bookseller->contacts; |
|
|
730 |
is( $contacts->count, |
731 |
1, 'Only one contact after modification' ); |
732 |
$first_contact = $contacts->next; |
733 |
is( $first_contact->phone, |
729 |
'654321', |
734 |
'654321', |
730 |
'Successfully changed contact phone number by modifying bookseller hash' ); |
735 |
'Successfully changed contact phone number by modifying bookseller hash' ); |
731 |
is( scalar @$contacts, |
|
|
732 |
1, 'Only one contact after modification' ); |
733 |
|
736 |
|
734 |
C4::Bookseller::ModBookseller( $bookseller, |
737 |
$first_contact->name( 'John Jacob Jingleheimer Schmidt' ); |
735 |
[ { name => 'John Jacob Jingleheimer Schmidt' } ] ); |
738 |
$first_contact->phone(undef); |
|
|
739 |
$first_contact->store; |
736 |
|
740 |
|
737 |
$bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); |
741 |
$bookseller = Koha::Acquisition::Booksellers->find( $booksellerid ); |
738 |
$contacts = $bookseller->contacts; |
742 |
$contacts = $bookseller->contacts; |
|
|
743 |
$first_contact = $contacts->next; |
739 |
is( |
744 |
is( |
740 |
$contacts->[0]->name, |
745 |
$first_contact->name, |
741 |
'John Jacob Jingleheimer Schmidt', |
746 |
'John Jacob Jingleheimer Schmidt', |
742 |
'Changed name of contact' |
747 |
'Changed name of contact' |
743 |
); |
748 |
); |
744 |
is( $contacts->[0]->phone, |
749 |
is( $first_contact->phone, |
745 |
undef, 'Removed phone number from contact' ); |
750 |
undef, 'Removed phone number from contact' ); |
746 |
is( scalar @$contacts, |
751 |
is( $contacts->count, |
747 |
1, 'Only one contact after modification' ); |
752 |
1, 'Only one contact after modification' ); |
748 |
|
753 |
|
749 |
#End transaction |
754 |
#End transaction |