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