Lines 1-19
Link Here
|
1 |
#!/usr/bin/perl |
1 |
#!/usr/bin/perl |
2 |
|
2 |
|
3 |
use Modern::Perl; |
3 |
use Modern::Perl; |
|
|
4 |
use Test::More tests => 13; |
4 |
|
5 |
|
5 |
use C4::Context; |
6 |
use Koha::Database; |
6 |
|
7 |
use t::lib::TestBuilder; |
7 |
use Test::More tests => 9; |
|
|
8 |
|
8 |
|
9 |
BEGIN { |
9 |
BEGIN { |
10 |
use_ok('C4::ImportBatch'); |
10 |
use_ok('C4::ImportBatch'); |
11 |
} |
11 |
} |
12 |
|
12 |
|
13 |
# Start transaction |
13 |
# Start transaction |
|
|
14 |
my $schema = Koha::Database->new->schema; |
15 |
$schema->storage->txn_begin; |
16 |
my $builder = t::lib::TestBuilder->new; |
14 |
my $dbh = C4::Context->dbh; |
17 |
my $dbh = C4::Context->dbh; |
15 |
$dbh->{AutoCommit} = 0; |
|
|
16 |
$dbh->{RaiseError} = 1; |
17 |
|
18 |
|
18 |
# clear |
19 |
# clear |
19 |
$dbh->do('DELETE FROM import_batches'); |
20 |
$dbh->do('DELETE FROM import_batches'); |
Lines 118-123
my $record_from_import_biblio_without_items = C4::ImportBatch::GetRecordFromImpo
Link Here
|
118 |
$original_record->leader($record_from_import_biblio_without_items->leader()); |
119 |
$original_record->leader($record_from_import_biblio_without_items->leader()); |
119 |
is_deeply( $record_from_import_biblio_without_items, $original_record, 'GetRecordFromImportBiblio should return the record without items by default' ); |
120 |
is_deeply( $record_from_import_biblio_without_items, $original_record, 'GetRecordFromImportBiblio should return the record without items by default' ); |
120 |
|
121 |
|
|
|
122 |
# Add a few tests for GetItemNumbersFromImportBatch |
123 |
my @a = GetItemNumbersFromImportBatch( $id_import_batch1 ); |
124 |
is( @a, 0, 'No item numbers expected since we did not commit' ); |
125 |
my $itemno = $builder->build({ source => 'Item' })->{itemnumber}; |
126 |
# Link this item to the import item to fool GetItemNumbersFromImportBatch |
127 |
my $sql = "UPDATE import_items SET itemnumber=? WHERE import_record_id=?"; |
128 |
$dbh->do( $sql, undef, $itemno, $import_record_id ); |
129 |
@a = GetItemNumbersFromImportBatch( $id_import_batch1 ); |
130 |
is( @a, 2, 'Expecting two items now' ); |
131 |
is( $a[0], $itemno, 'Check the first returned itemnumber' ); |
132 |
# Now delete the item and check again |
133 |
$dbh->do( "DELETE FROM items WHERE itemnumber=?", undef, $itemno ); |
134 |
@a = GetItemNumbersFromImportBatch( $id_import_batch1 ); |
135 |
is( @a, 0, 'No item numbers expected since we deleted the item' ); |
136 |
$dbh->do( $sql, undef, undef, $import_record_id ); # remove link again |
137 |
|
121 |
# fresh data |
138 |
# fresh data |
122 |
my $sample_import_batch3 = { |
139 |
my $sample_import_batch3 = { |
123 |
matcher_id => 3, |
140 |
matcher_id => 3, |
Lines 144-146
is( $batch3_clean, "0E0", "Batch 3 has been cleaned" );
Link Here
|
144 |
C4::ImportBatch::DeleteBatch( $id_import_batch3 ); |
161 |
C4::ImportBatch::DeleteBatch( $id_import_batch3 ); |
145 |
my $batch3_results = $dbh->do('SELECT * FROM import_batches WHERE import_batch_id = "$id_import_batch3"'); |
162 |
my $batch3_results = $dbh->do('SELECT * FROM import_batches WHERE import_batch_id = "$id_import_batch3"'); |
146 |
is( $batch3_results, "0E0", "Batch 3 has been deleted"); |
163 |
is( $batch3_results, "0E0", "Batch 3 has been deleted"); |
147 |
- |
164 |
|
|
|
165 |
$schema->storage->txn_rollback; |