Lines 14-23
use C4::Debug;
Link Here
|
14 |
use C4::Bookseller; |
14 |
use C4::Bookseller; |
15 |
use C4::Biblio; |
15 |
use C4::Biblio; |
16 |
use C4::Budgets; |
16 |
use C4::Budgets; |
|
|
17 |
use C4::Items; |
17 |
use Test::More tests => 35; |
18 |
use Test::More tests => 35; |
18 |
|
19 |
|
19 |
BEGIN { |
20 |
BEGIN { |
20 |
use_ok('C4::Serials'); |
21 |
use_ok('C4::Serials'); |
21 |
} |
22 |
} |
22 |
|
23 |
|
23 |
my $dbh = C4::Context->dbh; |
24 |
my $dbh = C4::Context->dbh; |
Lines 27-75
$dbh->{AutoCommit} = 0;
Link Here
|
27 |
$dbh->{RaiseError} = 1; |
28 |
$dbh->{RaiseError} = 1; |
28 |
|
29 |
|
29 |
my $booksellerid = C4::Bookseller::AddBookseller( |
30 |
my $booksellerid = C4::Bookseller::AddBookseller( |
30 |
{ |
31 |
{ |
31 |
name => "my vendor", |
32 |
name => "my vendor", |
32 |
address1 => "bookseller's address", |
33 |
address1 => "bookseller's address", |
33 |
phone => "0123456", |
34 |
phone => "0123456", |
34 |
active => 1 |
35 |
active => 1 |
35 |
} |
36 |
} |
36 |
); |
37 |
); |
37 |
|
38 |
|
38 |
my ($biblionumber, $biblioitemnumber) = AddBiblio(MARC::Record->new, ''); |
39 |
my ( $biblionumber, $biblioitemnumber ) = AddBiblio( MARC::Record->new, '' ); |
39 |
|
40 |
|
40 |
my $budgetid; |
41 |
my $budgetid; |
41 |
my $bpid = AddBudgetPeriod({ |
42 |
my $bpid = AddBudgetPeriod( |
42 |
budget_period_startdate => '01-01-2015', |
43 |
{ |
43 |
budget_period_enddate => '12-31-2015', |
44 |
budget_period_startdate => '01-01-2015', |
44 |
budget_description => "budget desc" |
45 |
budget_period_enddate => '12-31-2015', |
45 |
}); |
46 |
budget_description => "budget desc" |
46 |
|
47 |
} |
47 |
my $budget_id = AddBudget({ |
48 |
); |
48 |
budget_code => "ABCD", |
49 |
|
49 |
budget_amount => "123.132", |
50 |
my $budget_id = AddBudget( |
50 |
budget_name => "Périodiques", |
51 |
{ |
51 |
budget_notes => "This is a note", |
52 |
budget_code => "ABCD", |
52 |
budget_description => "Serials", |
53 |
budget_amount => "123.132", |
53 |
budget_active => 1, |
54 |
budget_name => "Périodiques", |
54 |
budget_period_id => $bpid |
55 |
budget_notes => "This is a note", |
55 |
}); |
56 |
budget_description => "Serials", |
56 |
|
57 |
budget_active => 1, |
57 |
my $frequency_id = AddSubscriptionFrequency({ description => "Test frequency 1" }); |
58 |
budget_period_id => $bpid |
58 |
my $pattern_id = AddSubscriptionNumberpattern({ |
59 |
} |
59 |
label => 'Test numberpattern 1', |
60 |
); |
60 |
numberingmethod => '{X}' |
61 |
|
61 |
}); |
62 |
my $frequency_id = |
|
|
63 |
AddSubscriptionFrequency( { description => "Test frequency 1" } ); |
64 |
my $pattern_id = AddSubscriptionNumberpattern( |
65 |
{ |
66 |
label => 'Test numberpattern 1', |
67 |
numberingmethod => '{X}' |
68 |
} |
69 |
); |
62 |
|
70 |
|
63 |
my $subscriptionid = NewSubscription( |
71 |
my $subscriptionid = NewSubscription( |
64 |
undef, "", undef, undef, $budget_id, $biblionumber, |
72 |
undef, "", undef, undef, |
65 |
'2013-01-01', $frequency_id, undef, undef, undef, |
73 |
$budget_id, $biblionumber, '2013-01-01', $frequency_id, |
66 |
undef, undef, undef, undef, undef, undef, |
74 |
undef, undef, undef, undef, |
67 |
1, "notes",undef, '2013-01-01', undef, $pattern_id, |
75 |
undef, undef, undef, undef, |
68 |
undef, undef, 0, "intnotes", 0, |
76 |
undef, 1, "notes", undef, |
69 |
undef, undef, 0, undef, '2013-12-31', 0 |
77 |
'2013-01-01', undef, $pattern_id, undef, |
|
|
78 |
undef, 0, "intnotes", 0, |
79 |
undef, undef, 0, undef, |
80 |
'2013-12-31', 0 |
70 |
); |
81 |
); |
71 |
|
82 |
|
72 |
my $subscriptioninformation = GetSubscription( $subscriptionid ); |
83 |
my $subscriptioninformation = GetSubscription($subscriptionid); |
73 |
|
84 |
|
74 |
my @subscriptions = GetSubscriptions( $$subscriptioninformation{bibliotitle} ); |
85 |
my @subscriptions = GetSubscriptions( $$subscriptioninformation{bibliotitle} ); |
75 |
isa_ok( \@subscriptions, 'ARRAY' ); |
86 |
isa_ok( \@subscriptions, 'ARRAY' ); |
Lines 77-183
isa_ok( \@subscriptions, 'ARRAY' );
Link Here
|
77 |
@subscriptions = GetSubscriptions( undef, $$subscriptioninformation{issn} ); |
88 |
@subscriptions = GetSubscriptions( undef, $$subscriptioninformation{issn} ); |
78 |
isa_ok( \@subscriptions, 'ARRAY' ); |
89 |
isa_ok( \@subscriptions, 'ARRAY' ); |
79 |
|
90 |
|
80 |
@subscriptions = GetSubscriptions( undef, undef, $$subscriptioninformation{ean} ); |
91 |
@subscriptions = |
|
|
92 |
GetSubscriptions( undef, undef, $$subscriptioninformation{ean} ); |
81 |
isa_ok( \@subscriptions, 'ARRAY' ); |
93 |
isa_ok( \@subscriptions, 'ARRAY' ); |
82 |
|
94 |
|
83 |
@subscriptions = GetSubscriptions( undef, undef, undef, $$subscriptioninformation{bibnum} ); |
95 |
@subscriptions = |
|
|
96 |
GetSubscriptions( undef, undef, undef, $$subscriptioninformation{bibnum} ); |
84 |
isa_ok( \@subscriptions, 'ARRAY' ); |
97 |
isa_ok( \@subscriptions, 'ARRAY' ); |
85 |
|
98 |
|
86 |
my $frequency = GetSubscriptionFrequency($subscriptioninformation->{periodicity}); |
99 |
my $frequency = |
|
|
100 |
GetSubscriptionFrequency( $subscriptioninformation->{periodicity} ); |
87 |
my $old_frequency; |
101 |
my $old_frequency; |
88 |
if (not $frequency->{unit}) { |
102 |
if ( not $frequency->{unit} ) { |
89 |
$old_frequency = $frequency->{id}; |
103 |
$old_frequency = $frequency->{id}; |
90 |
$frequency->{unit} = "month"; |
104 |
$frequency->{unit} = "month"; |
91 |
$frequency->{unitsperissue} = 1; |
105 |
$frequency->{unitsperissue} = 1; |
92 |
$frequency->{issuesperunit} = 1; |
106 |
$frequency->{issuesperunit} = 1; |
93 |
$frequency->{description} = "Frequency created by t/db_dependant/Serials.t"; |
107 |
$frequency->{description} = "Frequency created by t/db_dependant/Serials.t"; |
94 |
$subscriptioninformation->{periodicity} = AddSubscriptionFrequency($frequency); |
108 |
$subscriptioninformation->{periodicity} = |
95 |
|
109 |
AddSubscriptionFrequency($frequency); |
96 |
ModSubscription( @$subscriptioninformation{qw( |
110 |
|
97 |
librarian branchcode aqbooksellerid cost aqbudgetid startdate |
111 |
ModSubscription( |
98 |
periodicity firstacquidate irregularity numberpattern locale |
112 |
@$subscriptioninformation{ |
99 |
numberlength weeklength monthlength lastvalue1 innerloop1 lastvalue2 |
113 |
qw( |
100 |
innerloop2 lastvalue3 innerloop3 status biblionumber callnumber notes |
114 |
librarian branchcode aqbooksellerid cost aqbudgetid startdate |
101 |
letter manualhistory internalnotes serialsadditems staffdisplaycount |
115 |
periodicity firstacquidate irregularity numberpattern locale |
102 |
opacdisplaycount graceperiod location enddate subscriptionid |
116 |
numberlength weeklength monthlength lastvalue1 innerloop1 lastvalue2 |
103 |
skip_serialseq |
117 |
innerloop2 lastvalue3 innerloop3 status biblionumber callnumber notes |
104 |
)} ); |
118 |
letter manualhistory internalnotes serialsadditems staffdisplaycount |
|
|
119 |
opacdisplaycount graceperiod location enddate subscriptionid |
120 |
skip_serialseq |
121 |
) |
122 |
} |
123 |
); |
105 |
} |
124 |
} |
106 |
my $expirationdate = GetExpirationDate($subscriptionid) ; |
125 |
my $expirationdate = GetExpirationDate($subscriptionid); |
107 |
ok( $expirationdate, "expiration date is not NULL" ); |
126 |
ok( $expirationdate, "expiration date is not NULL" ); |
108 |
|
127 |
|
109 |
is(C4::Serials::GetLateIssues(), undef, 'test getting late issues'); |
128 |
is( C4::Serials::GetLateIssues(), undef, 'test getting late issues' ); |
110 |
|
129 |
|
111 |
ok(C4::Serials::GetSubscriptionHistoryFromSubscriptionId($subscriptionid), 'test getting history from sub-scription'); |
130 |
ok( C4::Serials::GetSubscriptionHistoryFromSubscriptionId($subscriptionid), |
|
|
131 |
'test getting history from sub-scription' ); |
112 |
|
132 |
|
113 |
my ($serials_count, @serials) = GetSerials($subscriptionid); |
133 |
my ( $serials_count, @serials ) = GetSerials($subscriptionid); |
114 |
ok($serials_count > 0, 'Subscription has at least one serial'); |
134 |
ok( $serials_count > 0, 'Subscription has at least one serial' ); |
115 |
my $serial = $serials[0]; |
135 |
my $serial = $serials[0]; |
116 |
|
136 |
|
117 |
ok(C4::Serials::GetSerialStatusFromSerialId($serial->{serialid}), 'test getting Serial Status From Serial Id'); |
137 |
ok( C4::Serials::GetSerialStatusFromSerialId( $serial->{serialid} ), |
|
|
138 |
'test getting Serial Status From Serial Id' ); |
118 |
|
139 |
|
119 |
isa_ok(C4::Serials::GetSerialInformation($serial->{serialid}), 'HASH', 'test getting Serial Information'); |
140 |
isa_ok( C4::Serials::GetSerialInformation( $serial->{serialid} ), |
|
|
141 |
'HASH', 'test getting Serial Information' ); |
120 |
|
142 |
|
121 |
# Delete created frequency |
143 |
# Delete created frequency |
122 |
if ($old_frequency) { |
144 |
if ($old_frequency) { |
123 |
my $freq_to_delete = $subscriptioninformation->{periodicity}; |
145 |
my $freq_to_delete = $subscriptioninformation->{periodicity}; |
124 |
$subscriptioninformation->{periodicity} = $old_frequency; |
146 |
$subscriptioninformation->{periodicity} = $old_frequency; |
125 |
|
147 |
|
126 |
ModSubscription( @$subscriptioninformation{qw( |
148 |
ModSubscription( |
127 |
librarian branchcode aqbooksellerid cost aqbudgetid startdate |
149 |
@$subscriptioninformation{ |
128 |
periodicity firstacquidate irregularity numberpattern locale |
150 |
qw( |
129 |
numberlength weeklength monthlength lastvalue1 innerloop1 lastvalue2 |
151 |
librarian branchcode aqbooksellerid cost aqbudgetid startdate |
130 |
innerloop2 lastvalue3 innerloop3 status biblionumber callnumber notes |
152 |
periodicity firstacquidate irregularity numberpattern locale |
131 |
letter manualhistory internalnotes serialsadditems staffdisplaycount |
153 |
numberlength weeklength monthlength lastvalue1 innerloop1 lastvalue2 |
132 |
opacdisplaycount graceperiod location enddate subscriptionid |
154 |
innerloop2 lastvalue3 innerloop3 status biblionumber callnumber notes |
133 |
skip_serialseq |
155 |
letter manualhistory internalnotes serialsadditems staffdisplaycount |
134 |
)} ); |
156 |
opacdisplaycount graceperiod location enddate subscriptionid |
135 |
|
157 |
skip_serialseq |
136 |
DelSubscriptionFrequency($freq_to_delete); |
158 |
) |
|
|
159 |
} |
160 |
); |
161 |
|
162 |
DelSubscriptionFrequency($freq_to_delete); |
137 |
} |
163 |
} |
138 |
|
164 |
|
139 |
|
|
|
140 |
# Test calling subs without parameters |
165 |
# Test calling subs without parameters |
141 |
is(C4::Serials::AddItem2Serial(), undef, 'test adding item to serial'); |
166 |
is( C4::Serials::AddItem2Serial(), undef, 'test adding item to serial' ); |
142 |
is(C4::Serials::UpdateClaimdateIssues(), undef, 'test updating claim date'); |
167 |
is( C4::Serials::UpdateClaimdateIssues(), undef, 'test updating claim date' ); |
143 |
is(C4::Serials::GetFullSubscription(), undef, 'test getting full subscription'); |
168 |
is( C4::Serials::GetFullSubscription(), |
144 |
is(C4::Serials::PrepareSerialsData(), undef, 'test preparing serial data'); |
169 |
undef, 'test getting full subscription' ); |
145 |
is(C4::Serials::GetSubscriptionsFromBiblionumber(), undef, 'test getting subscriptions form biblio number'); |
170 |
is( C4::Serials::PrepareSerialsData(), undef, 'test preparing serial data' ); |
146 |
|
171 |
is( C4::Serials::GetSubscriptionsFromBiblionumber(), |
147 |
is(C4::Serials::GetSerials(), undef, 'test getting serials when you enter nothing'); |
172 |
undef, 'test getting subscriptions form biblio number' ); |
148 |
is(C4::Serials::GetSerials2(), undef, 'test getting serials when you enter nothing'); |
173 |
|
149 |
|
174 |
is( C4::Serials::GetSerials(), undef, |
150 |
is(C4::Serials::GetLatestSerials(), undef, 'test getting lastest serials'); |
175 |
'test getting serials when you enter nothing' ); |
151 |
|
176 |
is( C4::Serials::GetSerials2(), |
152 |
is(C4::Serials::GetDistributedTo(), undef, 'test getting distributed when nothing is entered'); |
177 |
undef, 'test getting serials when you enter nothing' ); |
153 |
|
178 |
|
154 |
is(C4::Serials::GetNextSeq(), undef, 'test getting next seq when you enter nothing'); |
179 |
is( C4::Serials::GetLatestSerials(), undef, 'test getting lastest serials' ); |
155 |
|
180 |
|
156 |
is(C4::Serials::GetSeq(), undef, 'test getting seq when you enter nothing'); |
181 |
is( C4::Serials::GetDistributedTo(), |
157 |
|
182 |
undef, 'test getting distributed when nothing is entered' ); |
158 |
is(C4::Serials::CountSubscriptionFromBiblionumber(), undef, 'test counting subscription when nothing is entered'); |
183 |
|
159 |
|
184 |
is( C4::Serials::GetNextSeq(), undef, |
160 |
is(C4::Serials::ModSubscriptionHistory(), undef, 'test modding subscription history'); |
185 |
'test getting next seq when you enter nothing' ); |
161 |
|
186 |
|
162 |
is(C4::Serials::ModSerialStatus(),undef, 'test modding serials'); |
187 |
is( C4::Serials::GetSeq(), undef, 'test getting seq when you enter nothing' ); |
163 |
|
188 |
|
164 |
is(C4::Serials::NewIssue(), undef, 'test getting 0 when nothing is entered'); |
189 |
is( C4::Serials::CountSubscriptionFromBiblionumber(), |
165 |
|
190 |
undef, 'test counting subscription when nothing is entered' ); |
166 |
is(C4::Serials::ItemizeSerials(),undef, 'test getting nothing when nothing is entered'); |
191 |
|
167 |
|
192 |
is( C4::Serials::ModSubscriptionHistory(), |
168 |
is(C4::Serials::HasSubscriptionStrictlyExpired(), undef, 'test if the subscriptions has expired'); |
193 |
undef, 'test modding subscription history' ); |
169 |
is(C4::Serials::HasSubscriptionExpired(), undef, 'test if the subscriptions has expired'); |
194 |
|
170 |
|
195 |
is( C4::Serials::ModSerialStatus(), undef, 'test modding serials' ); |
171 |
is(C4::Serials::GetLateOrMissingIssues(), undef, 'test getting last or missing issues'); |
196 |
|
172 |
|
197 |
is( C4::Serials::NewIssue(), undef, 'test getting 0 when nothing is entered' ); |
173 |
is(C4::Serials::removeMissingIssue(), undef, 'test removing a missing issue'); |
198 |
|
174 |
|
199 |
is( C4::Serials::ItemizeSerials(), |
175 |
is(C4::Serials::updateClaim(),undef, 'test updating claim'); |
200 |
undef, 'test getting nothing when nothing is entered' ); |
176 |
|
201 |
|
177 |
is(C4::Serials::getsupplierbyserialid(),undef, 'test getting supplier idea'); |
202 |
is( C4::Serials::HasSubscriptionStrictlyExpired(), |
178 |
|
203 |
undef, 'test if the subscriptions has expired' ); |
179 |
is(C4::Serials::check_routing(), undef, 'test checking route'); |
204 |
is( C4::Serials::HasSubscriptionExpired(), |
180 |
|
205 |
undef, 'test if the subscriptions has expired' ); |
181 |
is(C4::Serials::addroutingmember(),undef, 'test adding route member'); |
206 |
|
|
|
207 |
is( C4::Serials::GetLateOrMissingIssues(), |
208 |
undef, 'test getting last or missing issues' ); |
209 |
|
210 |
is( C4::Serials::removeMissingIssue(), undef, 'test removing a missing issue' ); |
211 |
|
212 |
is( C4::Serials::updateClaim(), undef, 'test updating claim' ); |
213 |
|
214 |
is( C4::Serials::getsupplierbyserialid(), undef, 'test getting supplier idea' ); |
215 |
|
216 |
is( C4::Serials::check_routing(), undef, 'test checking route' ); |
217 |
|
218 |
is( C4::Serials::addroutingmember(), undef, 'test adding route member' ); |
219 |
|
220 |
subtest 'Filter items tests' => sub { |
221 |
|
222 |
plan tests => 4; |
223 |
|
224 |
# Start transaction |
225 |
$dbh->{AutoCommit} = 0; |
226 |
$dbh->{RaiseError} = 1; |
227 |
|
228 |
# Create a new biblio |
229 |
my ( $biblionumber, $biblioitemnumber ) = get_biblio(); |
230 |
|
231 |
# Add items |
232 |
my ( $item0_bibnum, $item0_bibitemnum, $item0_itemnumber ) = AddItem( |
233 |
{ |
234 |
homebranch => 'CPL', |
235 |
holdingbranch => 'CPL', |
236 |
enumchron => 'Vol 2012 : No 1, Issuezz 1' |
237 |
}, |
238 |
$biblionumber |
239 |
); |
240 |
my ( $item1_bibnum, $item1_bibitemnum, $item1_itemnumber ) = AddItem( |
241 |
{ |
242 |
homebranch => 'CPL', |
243 |
holdingbranch => 'CPL', |
244 |
enumchron => 'Vol 2013 : No 11, Issuezz 1' |
245 |
}, |
246 |
$biblionumber |
247 |
); |
248 |
my ( $item2_bibnum, $item2_bibitemnum, $item2_itemnumber ) = AddItem( |
249 |
{ |
250 |
homebranch => 'MPL', |
251 |
holdingbranch => 'MPL', |
252 |
enumchron => 'Vol 2013 : No 11, Issuezz 2' |
253 |
}, |
254 |
$biblionumber |
255 |
); |
256 |
my ( $item3_bibnum, $item3_bibitemnum, $item3_itemnumber ) = AddItem( |
257 |
{ |
258 |
homebranch => 'CPL', |
259 |
holdingbranch => 'CPL', |
260 |
enumchron => 'Vol 2013 : No 12, Issuezz 1' |
261 |
}, |
262 |
$biblionumber |
263 |
); |
264 |
my ( $item4_bibnum, $item4_bibitemnum, $item4_itemnumber ) = AddItem( |
265 |
{ |
266 |
homebranch => 'MPL', |
267 |
holdingbranch => 'MPL', |
268 |
enumchron => 'Vol 2013 : No 12, Issuezz 2' |
269 |
}, |
270 |
$biblionumber |
271 |
); |
272 |
my ( $item5_bibnum, $item5_bibitemnum, $item5_itemnumber ) = AddItem( |
273 |
{ |
274 |
homebranch => 'MPL', |
275 |
holdingbranch => 'MPL', |
276 |
enumchron => 'Vol 2014 : No 12, Issuezz 3' |
277 |
}, |
278 |
$biblionumber |
279 |
); |
280 |
|
281 |
C4::Context->set_preference( 'NumberingFormulaParsingRegexp', |
282 |
'^[^0-9]*volume[^0-9]*number[^0-9]*issue[^0-9]*$' ); |
283 |
|
284 |
# Testing the volume filter |
285 |
my @shouldBe4Items = |
286 |
C4::Items::GetItemsInfo( $biblionumber, { volume => '2013' } ); |
287 |
is( scalar(@shouldBe4Items), 4, "Filtering by volume" ); |
288 |
|
289 |
# Testing the number filter |
290 |
my @shouldBe3Items = |
291 |
C4::Items::GetItemsInfo( $biblionumber, { number => '12' } ); |
292 |
is( scalar(@shouldBe3Items), 3, "Filtering by number" ); |
293 |
|
294 |
# Testing the issue filter |
295 |
my @shouldBe2Items = |
296 |
C4::Items::GetItemsInfo( $biblionumber, { issue => '2' } ); |
297 |
is( scalar(@shouldBe2Items), 2, "Filtering by issue" ); |
298 |
|
299 |
# Testing the volume + number + issue filter |
300 |
my @shouldBeItem4 = C4::Items::GetItemsInfo( $biblionumber, |
301 |
{ volume => 2013, number => 12, issue => '2' } ); |
302 |
is( $shouldBeItem4[0]->{itemnumber}, |
303 |
$item4_itemnumber, "Filtering by volume + number + issue" ); |
304 |
}; |
305 |
|
306 |
# Helper method to set up a Biblio. |
307 |
sub get_biblio { |
308 |
my $bib = MARC::Record->new(); |
309 |
$bib->append_fields( |
310 |
MARC::Field->new( '100', ' ', ' ', a => 'Moffat, Steven' ), |
311 |
MARC::Field->new( '245', ' ', ' ', a => 'Silence in the library' ), |
312 |
); |
313 |
my ( $bibnum, $bibitemnum ) = C4::Biblio::AddBiblio( $bib, '' ); |
314 |
return ( $bibnum, $bibitemnum ); |
315 |
} |
182 |
|
316 |
|
183 |
$dbh->rollback; |
317 |
$dbh->rollback; |
184 |
- |
|
|