Lines 1-9
Link Here
|
1 |
#!/usr/bin/perl |
1 |
#!/usr/bin/perl |
2 |
# |
2 |
# |
3 |
# Copyright 2007 Foundations Bible College. |
3 |
# Copyright 2007 Foundations Bible College. |
|
|
4 |
# Copyright 2013 BibLibre |
4 |
# |
5 |
# |
5 |
# This file is part of Koha. |
6 |
# This file is part of Koha. |
6 |
# |
7 |
# |
7 |
# Koha is free software; you can redistribute it and/or modify it under the |
8 |
# 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 |
9 |
# 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 |
10 |
# Foundation; either version 2 of the License, or (at your option) any later |
Lines 17-33
Link Here
|
17 |
# with Koha; if not, write to the Free Software Foundation, Inc., |
18 |
# with Koha; if not, write to the Free Software Foundation, Inc., |
18 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
19 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
19 |
|
20 |
|
20 |
use strict; |
21 |
use Modern::Perl; |
21 |
use warnings; |
|
|
22 |
|
22 |
|
23 |
use Test::More tests => 23; |
23 |
use Test::More tests => 33; |
24 |
use C4::Context; |
24 |
use C4::Context; |
25 |
use Data::Dumper; |
25 |
use MARC::Record; |
|
|
26 |
use MARC::Field; |
27 |
use C4::Biblio; |
28 |
use C4::Items; |
26 |
|
29 |
|
27 |
BEGIN { |
30 |
BEGIN { |
28 |
use_ok('C4::Labels::Batch'); |
31 |
use_ok('C4::Labels::Batch'); |
29 |
} |
32 |
} |
30 |
|
33 |
|
|
|
34 |
# Start transaction |
35 |
my $dbh = C4::Context->dbh; |
36 |
$dbh->{AutoCommit} = 0; |
37 |
$dbh->{RaiseError} = 1; |
38 |
|
31 |
my $sth = C4::Context->dbh->prepare('SELECT branchcode FROM branches b LIMIT 0,1'); |
39 |
my $sth = C4::Context->dbh->prepare('SELECT branchcode FROM branches b LIMIT 0,1'); |
32 |
$sth->execute(); |
40 |
$sth->execute(); |
33 |
my $branch_code = $sth->fetchrow_hashref()->{'branchcode'}; |
41 |
my $branch_code = $sth->fetchrow_hashref()->{'branchcode'}; |
Lines 59-70
foreach my $key (keys %{$expected_batch}) {
Link Here
|
59 |
} |
67 |
} |
60 |
|
68 |
|
61 |
diag "Testing Batch->add_item() method."; |
69 |
diag "Testing Batch->add_item() method."; |
62 |
my $sth1 = C4::Context->dbh->prepare('SELECT itemnumber FROM items LIMIT 0,10'); |
70 |
# Create the item |
63 |
$sth1->execute(); |
71 |
my ( $f_holdingbranch, $sf_holdingbranch ) = GetMarcFromKohaField( 'items.holdingbranch' ); |
64 |
while (my $row = $sth1->fetchrow_hashref()) { |
72 |
my ( $f_homebranch, $sf_homebranch ) = GetMarcFromKohaField( 'items.homebranch' ); |
65 |
diag sprintf('Database returned the following error: %s', $sth1->errstr) if $sth1->errstr; |
73 |
is( $f_holdingbranch, $f_homebranch, "items information should be in the same field" ); |
66 |
ok($batch->add_item($row->{'itemnumber'}) eq 0 ) || diag "Batch->add_item() FAILED."; |
74 |
my $field = $f_holdingbranch; |
67 |
$item_number = $row->{'itemnumber'}; |
75 |
|
|
|
76 |
my $record = MARC::Record->new(); |
77 |
$record->append_fields( |
78 |
MARC::Field->new( $field, '', '', $sf_homebranch => 'CPL', $sf_holdingbranch => 'CPL' ), |
79 |
MARC::Field->new( $field, '', '', $sf_homebranch => 'CPL', $sf_holdingbranch => 'CPL' ), |
80 |
MARC::Field->new( $field, '', '', $sf_homebranch => 'CPL', $sf_holdingbranch => 'CPL' ), |
81 |
MARC::Field->new( $field, '', '', $sf_homebranch => 'CPL', $sf_holdingbranch => 'CPL' ), |
82 |
MARC::Field->new( $field, '', '', $sf_homebranch => 'CPL', $sf_holdingbranch => 'CPL' ), |
83 |
MARC::Field->new( $field, '', '', $sf_homebranch => 'CPL', $sf_holdingbranch => 'CPL' ), |
84 |
MARC::Field->new( $field, '', '', $sf_homebranch => 'CPL', $sf_holdingbranch => 'CPL' ), |
85 |
MARC::Field->new( $field, '', '', $sf_homebranch => 'CPL', $sf_holdingbranch => 'CPL' ), |
86 |
MARC::Field->new( $field, '', '', $sf_homebranch => 'CPL', $sf_holdingbranch => 'CPL' ), |
87 |
MARC::Field->new( $field, '', '', $sf_homebranch => 'CPL', $sf_holdingbranch => 'CPL' ), |
88 |
); |
89 |
my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio($record, ''); |
90 |
my @iteminfo = C4::Items::AddItemBatchFromMarc( $record, $biblionumber, $biblioitemnumber, '' ); |
91 |
|
92 |
my $itemnumbers = $iteminfo[0]; |
93 |
|
94 |
for my $itemnumber ( @$itemnumbers ) { |
95 |
ok($batch->add_item($itemnumber) eq 0 ) || diag "Batch->add_item() FAILED."; |
68 |
} |
96 |
} |
69 |
|
97 |
|
70 |
diag "Testing Batch->retrieve() method."; |
98 |
diag "Testing Batch->retrieve() method."; |
Lines 73-79
is_deeply($saved_batch, $batch) || diag "Retrieved batch object FAILED to verify
Link Here
|
73 |
|
101 |
|
74 |
diag "Testing Batch->remove_item() method."; |
102 |
diag "Testing Batch->remove_item() method."; |
75 |
|
103 |
|
76 |
ok($batch->remove_item($item_number) eq 0) || diag "Batch->remove_item() FAILED."; |
104 |
for my $itemnumber ( @$itemnumbers ) { |
|
|
105 |
ok($batch->remove_item($itemnumber) eq 0) || diag "Batch->remove_item() FAILED."; |
106 |
} |
107 |
|
77 |
my $updated_batch = C4::Labels::Batch->retrieve(batch_id => $batch_id); |
108 |
my $updated_batch = C4::Labels::Batch->retrieve(batch_id => $batch_id); |
78 |
is_deeply($updated_batch, $batch) || diag "Updated batch object FAILED to verify."; |
109 |
is_deeply($updated_batch, $batch) || diag "Updated batch object FAILED to verify."; |
79 |
|
110 |
|
Lines 81-83
diag "Testing Batch->delete() method.";
Link Here
|
81 |
|
112 |
|
82 |
my $del_results = $batch->delete(); |
113 |
my $del_results = $batch->delete(); |
83 |
ok($del_results eq 0) || diag "Batch->delete() FAILED."; |
114 |
ok($del_results eq 0) || diag "Batch->delete() FAILED."; |
84 |
- |
115 |
|
|
|
116 |
$dbh->rollback; |