Lines 3-9
Link Here
|
3 |
# Copyright 2007 Foundations Bible College. |
3 |
# Copyright 2007 Foundations Bible College. |
4 |
# |
4 |
# |
5 |
# This file is part of Koha. |
5 |
# This file is part of Koha. |
6 |
# |
6 |
# |
7 |
# Koha is free software; you can redistribute it and/or modify it under the |
7 |
# Koha is free software; you can redistribute it and/or modify it under the |
8 |
# terms of the GNU General Public License as published by the Free Software |
8 |
# terms of the GNU General Public License as published by the Free Software |
9 |
# Foundation; either version 2 of the License, or (at your option) any later |
9 |
# Foundation; either version 2 of the License, or (at your option) any later |
Lines 17-28
Link Here
|
17 |
# with Koha; if not, write to the Free Software Foundation, Inc., |
17 |
# with Koha; if not, write to the Free Software Foundation, Inc., |
18 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
18 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
19 |
|
19 |
|
20 |
use strict; |
20 |
use Modern::Perl; |
21 |
use warnings; |
|
|
22 |
|
21 |
|
23 |
use Test::More tests => 23; |
22 |
use Test::More tests => 32; |
24 |
use C4::Context; |
23 |
use C4::Context; |
25 |
use Data::Dumper; |
24 |
use MARC::Record; |
|
|
25 |
use MARC::Field; |
26 |
use C4::Biblio; |
27 |
use C4::Items; |
26 |
|
28 |
|
27 |
BEGIN { |
29 |
BEGIN { |
28 |
use_ok('C4::Labels::Batch'); |
30 |
use_ok('C4::Labels::Batch'); |
Lines 58-70
foreach my $key (keys %{$expected_batch}) {
Link Here
|
58 |
} |
60 |
} |
59 |
} |
61 |
} |
60 |
|
62 |
|
|
|
63 |
|
61 |
diag "Testing Batch->add_item() method."; |
64 |
diag "Testing Batch->add_item() method."; |
62 |
my $sth1 = C4::Context->dbh->prepare('SELECT itemnumber FROM items LIMIT 0,10'); |
65 |
# Create the item |
63 |
$sth1->execute(); |
66 |
my $record = MARC::Record->new(); |
64 |
while (my $row = $sth1->fetchrow_hashref()) { |
67 |
$record->append_fields( |
65 |
diag sprintf('Database returned the following error: %s', $sth1->errstr) if $sth1->errstr; |
68 |
MARC::Field->new( '952', '', '', a => 'CPL', b => 'CPL' ), |
66 |
ok($batch->add_item($row->{'itemnumber'}) eq 0 ) || diag "Batch->add_item() FAILED."; |
69 |
MARC::Field->new( '952', '', '', a => 'CPL', b => 'CPL' ), |
67 |
$item_number = $row->{'itemnumber'}; |
70 |
MARC::Field->new( '952', '', '', a => 'CPL', b => 'CPL' ), |
|
|
71 |
MARC::Field->new( '952', '', '', a => 'CPL', b => 'CPL' ), |
72 |
MARC::Field->new( '952', '', '', a => 'CPL', b => 'CPL' ), |
73 |
MARC::Field->new( '952', '', '', a => 'CPL', b => 'CPL' ), |
74 |
MARC::Field->new( '952', '', '', a => 'CPL', b => 'CPL' ), |
75 |
MARC::Field->new( '952', '', '', a => 'CPL', b => 'CPL' ), |
76 |
MARC::Field->new( '952', '', '', a => 'CPL', b => 'CPL' ), |
77 |
MARC::Field->new( '952', '', '', a => 'CPL', b => 'CPL' ), |
78 |
); |
79 |
my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio($record, ''); |
80 |
my @iteminfo = C4::Items::AddItemBatchFromMarc( $record, $biblionumber, $biblioitemnumber, '' ); |
81 |
|
82 |
my $itemnumbers = $iteminfo[0]; |
83 |
|
84 |
for my $itemnumber ( @$itemnumbers ) { |
85 |
ok($batch->add_item($itemnumber) eq 0 ) || diag "Batch->add_item() FAILED."; |
68 |
} |
86 |
} |
69 |
|
87 |
|
70 |
diag "Testing Batch->retrieve() method."; |
88 |
diag "Testing Batch->retrieve() method."; |
Lines 73-79
is_deeply($saved_batch, $batch) || diag "Retrieved batch object FAILED to verify
Link Here
|
73 |
|
91 |
|
74 |
diag "Testing Batch->remove_item() method."; |
92 |
diag "Testing Batch->remove_item() method."; |
75 |
|
93 |
|
76 |
ok($batch->remove_item($item_number) eq 0) || diag "Batch->remove_item() FAILED."; |
94 |
for my $itemnumber ( @$itemnumbers ) { |
|
|
95 |
ok($batch->remove_item($itemnumber) eq 0) || diag "Batch->remove_item() FAILED."; |
96 |
} |
97 |
|
77 |
my $updated_batch = C4::Labels::Batch->retrieve(batch_id => $batch_id); |
98 |
my $updated_batch = C4::Labels::Batch->retrieve(batch_id => $batch_id); |
78 |
is_deeply($updated_batch, $batch) || diag "Updated batch object FAILED to verify."; |
99 |
is_deeply($updated_batch, $batch) || diag "Updated batch object FAILED to verify."; |
79 |
|
100 |
|
Lines 81-83
diag "Testing Batch->delete() method.";
Link Here
|
81 |
|
102 |
|
82 |
my $del_results = $batch->delete(); |
103 |
my $del_results = $batch->delete(); |
83 |
ok($del_results eq 0) || diag "Batch->delete() FAILED."; |
104 |
ok($del_results eq 0) || diag "Batch->delete() FAILED."; |
84 |
- |
105 |
|
|
|
106 |
END { |
107 |
my $dbh = C4::Context->dbh; |
108 |
for my $itemnumber ( @$itemnumbers ) { |
109 |
C4::Items::DelItem( $dbh, $biblionumber, $itemnumber); |
110 |
} |
111 |
C4::Biblio::DelBiblio($biblionumber); |
112 |
}; |