test suite: C4::ImportBatch
Here are some tests for functions in C4::ImportBatch. Signed-off-by: Galen Charlton <galen.charlton@liblime.com>
This commit is contained in:
parent
1fc155e4b3
commit
69a2b414ae
|
|
@ -103,4 +103,27 @@ sub shutdown_50_remove_matcher : Test( shutdown => 6) {
|
|||
delete $self->{'matcher_id'};
|
||||
}
|
||||
|
||||
=head2 UTILITY METHODS
|
||||
|
||||
=cut
|
||||
|
||||
sub add_import_batch {
|
||||
my $self = shift;
|
||||
my $test_batch = shift
|
||||
|| {
|
||||
overlay_action => 'create_new',
|
||||
import_status => 'staging',
|
||||
batch_type => 'batch',
|
||||
file_name => 'foo',
|
||||
comments => 'inserted during automated testing',
|
||||
};
|
||||
my $batch_id = AddImportBatch( $test_batch->{'overlay_action'},
|
||||
$test_batch->{'import_status'},
|
||||
$test_batch->{'batch_type'},
|
||||
$test_batch->{'file_name'},
|
||||
$test_batch->{'comments'}, );
|
||||
return $batch_id;
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
package KohaTest::ImportBatch::AddImportBatch;
|
||||
use base qw( KohaTest::ImportBatch );
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Test::More;
|
||||
|
||||
use C4::ImportBatch;
|
||||
use C4::Matcher;
|
||||
use C4::Biblio;
|
||||
|
||||
|
||||
=head3 add_one
|
||||
|
||||
=cut
|
||||
|
||||
sub add_one : Test( 1 ) {
|
||||
my $self = shift;
|
||||
|
||||
my $batch_id = AddImportBatch(
|
||||
'create_new', #overlay_action
|
||||
'staging', # import_status
|
||||
'batch', # batc_type
|
||||
'foo', # file_name
|
||||
'inserted during automated testing', # comments
|
||||
);
|
||||
ok( $batch_id, "successfully inserted batch: $batch_id" );
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package KohaTest::ImportBatch::getImportBatch;
|
||||
use base qw( KohaTest::ImportBatch );
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Test::More;
|
||||
|
||||
use C4::ImportBatch;
|
||||
use C4::Matcher;
|
||||
use C4::Biblio;
|
||||
|
||||
|
||||
sub something : Test( 2 ) {
|
||||
my $self = shift;
|
||||
|
||||
my $batch_id = $self->add_import_batch();
|
||||
ok( $batch_id, 'we have a batch_id' );
|
||||
|
||||
my $import_record_id = 0;
|
||||
|
||||
my $marc_record = MARC::Record->new();
|
||||
|
||||
my @import_item_ids = C4::ImportBatch::AddItemsToImportBiblio( $batch_id, $import_record_id, $marc_record );
|
||||
is( scalar( @import_item_ids ), 0, 'none inserted' );
|
||||
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
package KohaTest::ImportBatch::getImportBatch;
|
||||
use base qw( KohaTest::ImportBatch );
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Test::More;
|
||||
|
||||
use C4::ImportBatch;
|
||||
use C4::Matcher;
|
||||
use C4::Biblio;
|
||||
|
||||
|
||||
=head3 add_one_and_find_it
|
||||
|
||||
=cut
|
||||
|
||||
sub add_one_and_find_it : Test( 7 ) {
|
||||
my $self = shift;
|
||||
|
||||
my $batch = {
|
||||
overlay_action => 'create_new',
|
||||
import_status => 'staging',
|
||||
batch_type => 'batch',
|
||||
file_name => 'foo',
|
||||
comments => 'inserted during automated testing',
|
||||
};
|
||||
my $batch_id = AddImportBatch(
|
||||
$batch->{'overlay_action'},
|
||||
$batch->{'import_status'},
|
||||
$batch->{'batch_type'},
|
||||
$batch->{'file_name'},
|
||||
$batch->{'comments'},
|
||||
);
|
||||
ok( $batch_id, "successfully inserted batch: $batch_id" );
|
||||
|
||||
my $retrieved = GetImportBatch( $batch_id );
|
||||
|
||||
foreach my $key ( keys %$batch ) {
|
||||
is( $retrieved->{$key}, $batch->{$key}, "both objects agree on $key" );
|
||||
}
|
||||
is( $retrieved->{'import_batch_id'}, $batch_id, 'batch_id' );
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
package KohaTest::ImportBatch::GetImportRecordMarc;
|
||||
use base qw( KohaTest::ImportBatch );
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Test::More;
|
||||
|
||||
use C4::ImportBatch;
|
||||
use C4::Matcher;
|
||||
use C4::Biblio;
|
||||
|
||||
|
||||
=head3 record_does_not_exist
|
||||
|
||||
=cut
|
||||
|
||||
sub record_does_not_exist : Test( 1 ) {
|
||||
my $self = shift;
|
||||
|
||||
my $id = '999999999999';
|
||||
my $marc = GetImportRecordMarc( $id );
|
||||
ok( ! defined( $marc ), 'this marc is undefined' );
|
||||
|
||||
}
|
||||
|
||||
sub record_does_exist : Test( 4 ) {
|
||||
my $self = shift;
|
||||
|
||||
# we need an import_batch, so let GetZ3950BatchId create one:
|
||||
my $new_batch_id = GetZ3950BatchId('foo');
|
||||
ok( $new_batch_id, "got a new batch ID: $new_batch_id" );
|
||||
|
||||
my $sth = C4::Context->dbh->prepare(
|
||||
"INSERT INTO import_records (import_batch_id, marc, marcxml)
|
||||
VALUES (?, ?, ?)"
|
||||
);
|
||||
my $execute = $sth->execute(
|
||||
$new_batch_id, # batch_id
|
||||
'marc', # marc
|
||||
'marcxml', # marcxml
|
||||
);
|
||||
ok( $execute, 'succesfully executed' );
|
||||
my $import_record_id = C4::Context->dbh->{'mysql_insertid'};
|
||||
ok( $import_record_id, 'we got an import_record_id' );
|
||||
|
||||
my $marc = GetImportRecordMarc($import_record_id);
|
||||
ok( defined($marc), 'this marc is defined' );
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
package KohaTest::ImportBatch::GetZ3950BatchId;
|
||||
use base qw( KohaTest::ImportBatch );
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Test::More;
|
||||
|
||||
use C4::ImportBatch;
|
||||
use C4::Matcher;
|
||||
use C4::Biblio;
|
||||
|
||||
|
||||
=head3 batch_does_not_exist
|
||||
|
||||
=cut
|
||||
|
||||
sub batch_does_not_exist : Test( 5 ) {
|
||||
my $self = shift;
|
||||
|
||||
my $file_name = 'testing batch';
|
||||
|
||||
# lets make sure it doesn't exist first
|
||||
my $sth = C4::Context->dbh->prepare('SELECT import_batch_id FROM import_batches
|
||||
WHERE batch_type = ?
|
||||
AND file_name = ?');
|
||||
ok( $sth->execute( 'z3950', $file_name, ), 'execute' );
|
||||
my $rowref = $sth->fetchrow_arrayref();
|
||||
ok( !defined( $rowref ), 'this batch does not exist' );
|
||||
|
||||
# now let GetZ3950BatchId create one
|
||||
my $new_batch_id = GetZ3950BatchId( $file_name );
|
||||
ok( $new_batch_id, "got a new batch ID: $new_batch_id" );
|
||||
|
||||
# now search for the one that was just created
|
||||
my $second_batch_id = GetZ3950BatchId( $file_name );
|
||||
ok( $second_batch_id, "got a second batch ID: $second_batch_id" );
|
||||
is( $second_batch_id, $new_batch_id, 'we got the same batch both times.' );
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
Loading…
Reference in New Issue