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