743b1aa80ee5c1c14bedffd04f3e48537c195b54
[koha.git] / t / db_dependent / lib / KohaTest / ImportBatch.pm
1 package KohaTest::ImportBatch;
2 use base qw(KohaTest);
3
4 use strict;
5 use warnings;
6
7 use Test::More;
8
9 use C4::ImportBatch;
10 use C4::Matcher;
11 sub testing_class { 'C4::ImportBatch' };
12
13
14 sub routines : Test( 1 ) {
15     my $self = shift;
16     my @routines = qw(
17                         GetZ3950BatchId
18                         GetImportRecordMarc
19                         AddImportBatch
20                         GetImportBatch
21                         AddBiblioToBatch
22                         ModBiblioInBatch
23                         BatchStageMarcRecords
24                         AddItemsToImportBiblio
25                         BatchFindBibDuplicates
26                         BatchCommitBibRecords
27                         BatchCommitItems
28                         BatchRevertBibRecords
29                         BatchRevertItems
30                         CleanBatch
31                         GetAllImportBatches
32                         GetImportBatchRangeDesc
33                         GetItemNumbersFromImportBatch
34                         GetNumberOfNonZ3950ImportBatches
35                         GetImportBibliosRange
36                         GetBestRecordMatch
37                         GetImportBatchStatus
38                         SetImportBatchStatus
39                         GetImportBatchOverlayAction
40                         SetImportBatchOverlayAction
41                         GetImportBatchNoMatchAction
42                         SetImportBatchNoMatchAction
43                         GetImportBatchItemAction
44                         SetImportBatchItemAction
45                         GetImportBatchItemAction
46                         SetImportBatchItemAction
47                         GetImportBatchMatcher
48                         SetImportBatchMatcher
49                         GetImportRecordOverlayStatus
50                         SetImportRecordOverlayStatus
51                         GetImportRecordStatus
52                         SetImportRecordStatus
53                         GetImportRecordMatches
54                         SetImportRecordMatches
55                         _create_import_record
56                         _update_import_record_marc
57                         _add_biblio_fields
58                         _update_biblio_fields
59                         _parse_biblio_fields
60                         _update_batch_record_counts
61                         _get_commit_action
62                         _get_revert_action
63                 );
64     
65     can_ok($self->testing_class, @routines);
66 }
67
68 sub startup_50_add_matcher : Test( startup => 1 ) {
69     my $self = shift;
70     # create test MARC21 ISBN matcher
71     my $matcher = C4::Matcher->new('biblio');
72     $matcher->threshold(1000);
73     $matcher->code('TESTISBN');
74     $matcher->description('test MARC21 ISBN matcher');
75     $matcher->add_simple_matchpoint('isbn', 1000, '020', 'a', -1, 0, '');
76     my $matcher_id = $matcher->store();
77     like($matcher_id, qr/^\d+$/, "store new matcher and get back ID");
78
79     $self->{'matcher_id'} = $matcher_id;
80 }
81
82 sub shutdown_50_remove_matcher : Test( shutdown => 6) {
83     my $self = shift;
84     my @matchers = C4::Matcher::GetMatcherList();
85     cmp_ok(scalar(@matchers), ">=", 1, "at least one matcher present");
86     my $matcher_id;
87     my $testisbn_count = 0;
88     # look for TESTISBN
89     foreach my $matcher (@matchers) {
90         if ($matcher->{'code'} eq 'TESTISBN') {
91             $testisbn_count++;
92             $matcher_id = $matcher->{'matcher_id'};
93         }
94     }
95     ok($testisbn_count == 1, "only one TESTISBN matcher");
96     like($matcher_id, qr/^\d+$/, "matcher ID is valid");
97     my $matcher = C4::Matcher->fetch($matcher_id);
98     ok(defined($matcher), "got back a matcher");
99     ok($matcher_id == $matcher->{'id'}, "got back the correct matcher");
100     C4::Matcher->delete($matcher_id);
101     my $matcher2 = C4::Matcher->fetch($matcher_id);
102     ok(not(defined($matcher2)), "matcher removed");
103
104     delete $self->{'matcher_id'};
105 }
106
107 =head2 UTILITY METHODS
108
109 =cut
110
111 sub add_import_batch {
112     my $self       = shift;
113     my $test_batch = shift
114       || {
115         overlay_action => 'create_new',
116         import_status  => 'staging',
117         batch_type     => 'batch',
118         file_name      => 'foo',
119         comments       => 'inserted during automated testing',
120       };
121     my $batch_id = AddImportBatch( $test_batch );
122     return $batch_id;
123 }
124
125
126 1;