bug 2295 [3/4]: moving C4::Items tests into t/lib/KohaTest
[koha.git] / t / 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                         GetAllImportBatches
31                         GetImportBatchRangeDesc
32                         GetItemNumbersFromImportBatch
33                         GetNumberOfNonZ3950ImportBatches
34                         GetImportBibliosRange
35                         GetBestRecordMatch
36                         GetImportBatchStatus
37                         SetImportBatchStatus
38                         GetImportBatchOverlayAction
39                         SetImportBatchOverlayAction
40                         GetImportBatchNoMatchAction
41                         SetImportBatchNoMatchAction
42                         GetImportBatchItemAction
43                         SetImportBatchItemAction
44                         GetImportBatchItemAction
45                         SetImportBatchItemAction
46                         GetImportBatchMatcher
47                         SetImportBatchMatcher
48                         GetImportRecordOverlayStatus
49                         SetImportRecordOverlayStatus
50                         GetImportRecordStatus
51                         SetImportRecordStatus
52                         GetImportRecordMatches
53                         SetImportRecordMatches
54                         _create_import_record
55                         _update_import_record_marc
56                         _add_biblio_fields
57                         _update_biblio_fields
58                         _parse_biblio_fields
59                         _update_batch_record_counts
60                         _get_commit_action
61                         _get_revert_action
62                 );
63     
64     can_ok($self->testing_class, @routines);
65 }
66
67 sub startup_50_add_matcher : Test( startup => 1 ) {
68     my $self = shift;
69     # create test MARC21 ISBN matcher
70     my $matcher = C4::Matcher->new('biblio');
71     $matcher->threshold(1000);
72     $matcher->code('TESTISBN');
73     $matcher->description('test MARC21 ISBN matcher');
74     $matcher->add_simple_matchpoint('isbn', 1000, '020', 'a', -1, 0, '');
75     my $matcher_id = $matcher->store();
76     like($matcher_id, qr/^\d+$/, "store new matcher and get back ID");
77
78     $self->{'matcher_id'} = $matcher_id;
79 }
80
81 sub shutdown_50_remove_matcher : Test( shutdown => 6) {
82     my $self = shift;
83     my @matchers = C4::Matcher::GetMatcherList();
84     cmp_ok(scalar(@matchers), ">=", 1, "at least one matcher present");
85     my $matcher_id;
86     my $testisbn_count = 0;
87     # look for TESTISBN
88     foreach my $matcher (@matchers) {
89         if ($matcher->{'code'} eq 'TESTISBN') {
90             $testisbn_count++;
91             $matcher_id = $matcher->{'matcher_id'};
92         }
93     }
94     ok($testisbn_count == 1, "only one TESTISBN matcher");
95     like($matcher_id, qr/^\d+$/, "matcher ID is valid");
96     my $matcher = C4::Matcher->fetch($matcher_id);
97     ok(defined($matcher), "got back a matcher");
98     ok($matcher_id == $matcher->{'id'}, "got back the correct matcher");
99     C4::Matcher->delete($matcher_id);
100     my $matcher2 = C4::Matcher->fetch($matcher_id);
101     ok(not(defined($matcher2)), "matcher removed");
102
103     delete $self->{'matcher_id'};
104 }
105
106 1;