|
Lines 36-45
my $dbh = C4::Context->dbh;
Link Here
|
| 36 |
$dbh->{AutoCommit} = 0; |
36 |
$dbh->{AutoCommit} = 0; |
| 37 |
$dbh->{RaiseError} = 1; |
37 |
$dbh->{RaiseError} = 1; |
| 38 |
|
38 |
|
| 39 |
my $sth = C4::Context->dbh->prepare('SELECT branchcode FROM branches b LIMIT 0,1'); |
39 |
my $sth = $dbh->prepare('SELECT branchcode FROM branches b LIMIT 0,1'); |
| 40 |
$sth->execute(); |
40 |
$sth->execute(); |
| 41 |
my $branch_code = $sth->fetchrow_hashref()->{'branchcode'}; |
41 |
my $branch_code = $sth->fetchrow_hashref()->{'branchcode'}; |
| 42 |
diag sprintf('Database returned the following error: %s', $sth->errstr) if $sth->errstr; |
42 |
diag sprintf('Database returned the following error: %s', $sth->errstr) if $sth->errstr; |
|
|
43 |
|
| 43 |
my $expected_batch = { |
44 |
my $expected_batch = { |
| 44 |
creator => 'Labels', |
45 |
creator => 'Labels', |
| 45 |
items => [], |
46 |
items => [], |
|
Lines 50-72
my $expected_batch = {
Link Here
|
| 50 |
my $batch = 0; |
51 |
my $batch = 0; |
| 51 |
my $item_number = 0; |
52 |
my $item_number = 0; |
| 52 |
|
53 |
|
| 53 |
diag "Testing Batch->new() method."; |
54 |
# Testing Batch->new() method. |
| 54 |
ok($batch = C4::Labels::Batch->new(branch_code => $branch_code)) || diag "Batch->new() FAILED."; |
55 |
ok($batch = C4::Labels::Batch->new(branch_code => $branch_code), "C4::Labels::Batch-->new() succeeds"); |
| 55 |
my $batch_id = $batch->get_attr('batch_id'); |
56 |
my $batch_id = $batch->get_attr('batch_id'); |
| 56 |
$expected_batch->{'batch_id'} = $batch_id; |
57 |
$expected_batch->{'batch_id'} = $batch_id; |
| 57 |
is_deeply($batch, $expected_batch) || diag "New batch object FAILED to verify."; |
58 |
is_deeply($batch, $expected_batch, "New batch object is correct."); |
| 58 |
|
59 |
|
| 59 |
diag "Testing Batch->get_attr() method."; |
60 |
# Testing Batch->get_attr() method. |
| 60 |
foreach my $key (keys %{$expected_batch}) { |
61 |
foreach my $key (keys %{$expected_batch}) { |
| 61 |
if (ref($expected_batch->{$key}) eq 'ARRAY') { |
62 |
if (ref($expected_batch->{$key}) eq 'ARRAY') { |
| 62 |
ok(ref($expected_batch->{$key}) eq ref($batch->get_attr($key))) || diag "Batch->get_attr() FAILED on attribute $key."; |
63 |
ok(ref($expected_batch->{$key}) eq ref($batch->get_attr($key)), "Batch->get_attr() SUCCESS on attribute $key."); |
| 63 |
} |
64 |
} |
| 64 |
else { |
65 |
else { |
| 65 |
ok($expected_batch->{$key} eq $batch->get_attr($key)) || diag "Batch->get_attr() FAILED on attribute $key."; |
66 |
ok($expected_batch->{$key} eq $batch->get_attr($key), "Batch->get_attr() SUCCESS on attribute $key."); |
| 66 |
} |
67 |
} |
| 67 |
} |
68 |
} |
| 68 |
|
69 |
|
| 69 |
diag "Testing Batch->add_item() method."; |
70 |
# Testing Batch->add_item() method. |
| 70 |
# Create the item |
71 |
# Create the item |
| 71 |
my ( $f_holdingbranch, $sf_holdingbranch ) = GetMarcFromKohaField( 'items.holdingbranch' ); |
72 |
my ( $f_holdingbranch, $sf_holdingbranch ) = GetMarcFromKohaField( 'items.holdingbranch' ); |
| 72 |
my ( $f_homebranch, $sf_homebranch ) = GetMarcFromKohaField( 'items.homebranch' ); |
73 |
my ( $f_homebranch, $sf_homebranch ) = GetMarcFromKohaField( 'items.homebranch' ); |
|
Lines 92-116
my @iteminfo = C4::Items::AddItemBatchFromMarc( $record, $biblionumber, $biblioi
Link Here
|
| 92 |
my $itemnumbers = $iteminfo[0]; |
93 |
my $itemnumbers = $iteminfo[0]; |
| 93 |
|
94 |
|
| 94 |
for my $itemnumber ( @$itemnumbers ) { |
95 |
for my $itemnumber ( @$itemnumbers ) { |
| 95 |
ok($batch->add_item($itemnumber) eq 0 ) || diag "Batch->add_item() FAILED."; |
96 |
ok($batch->add_item($itemnumber) eq 0 , "Batch->add_item() success."); |
| 96 |
} |
97 |
} |
| 97 |
$batch_id=$batch->get_attr('batch_id'); |
98 |
$batch_id = $batch->get_attr('batch_id'); |
| 98 |
|
|
|
| 99 |
diag "Testing Batch->retrieve() method."; |
| 100 |
ok(my $saved_batch = C4::Labels::Batch->retrieve(batch_id => $batch_id)) || diag "Batch->retrieve() FAILED."; |
| 101 |
is_deeply($saved_batch, $batch) || diag "Retrieved batch object FAILED to verify."; |
| 102 |
|
99 |
|
| 103 |
diag "Testing Batch->remove_item() method."; |
100 |
# Testing Batch->retrieve() method. |
|
|
101 |
ok(my $saved_batch = C4::Labels::Batch->retrieve(batch_id => $batch_id), "Batch->retrieve() success."); |
| 102 |
is_deeply($saved_batch, $batch, "Batch object retrieved correctly" ); |
| 104 |
|
103 |
|
|
|
104 |
# Testing Batch->remove_item() method. |
| 105 |
my $itemnumber = @$itemnumbers[0]; |
105 |
my $itemnumber = @$itemnumbers[0]; |
| 106 |
ok($batch->remove_item($itemnumber) eq 0) || diag "Batch->remove_item() FAILED."; |
106 |
ok($batch->remove_item($itemnumber) eq 0, "Batch->remove_item() success."); |
| 107 |
|
107 |
|
| 108 |
my $updated_batch = C4::Labels::Batch->retrieve(batch_id => $batch_id); |
108 |
my $updated_batch = C4::Labels::Batch->retrieve(batch_id => $batch_id); |
| 109 |
is_deeply($updated_batch, $batch) || diag "Updated batch object FAILED to verify."; |
109 |
is_deeply($updated_batch, $batch, "Updated batch object is correct."); |
| 110 |
|
|
|
| 111 |
diag "Testing Batch->delete() method."; |
| 112 |
|
110 |
|
|
|
111 |
# Testing Batch->delete() method. |
| 113 |
my $del_results = $batch->delete(); |
112 |
my $del_results = $batch->delete(); |
| 114 |
ok($del_results eq 0) || diag "Batch->delete() FAILED."; |
113 |
ok($del_results eq 0, "Batch->delete() success."); |
| 115 |
|
114 |
|
| 116 |
$dbh->rollback; |
115 |
$dbh->rollback; |
| 117 |
- |
|
|