Line 0
Link Here
|
0 |
- |
1 |
# This file is part of Koha. |
|
|
2 |
# |
3 |
# Koha is free software; you can redistribute it and/or modify it |
4 |
# under the terms of the GNU General Public License as published by |
5 |
# the Free Software Foundation; either version 3 of the License, or |
6 |
# (at your option) any later version. |
7 |
# |
8 |
# Koha is distributed in the hope that it will be useful, but |
9 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 |
# GNU General Public License for more details. |
12 |
# |
13 |
# You should have received a copy of the GNU General Public License |
14 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
15 |
|
16 |
use Modern::Perl; |
17 |
use Koha::MetadataIterator; |
18 |
use Koha::MetadataRecord::Authority; |
19 |
use Koha::SearchEngine::Elasticsearch; |
20 |
use t::lib::TestBuilder; |
21 |
use C4::Biblio; |
22 |
use C4::AuthoritiesMarc; |
23 |
|
24 |
use Test::More tests => 1; |
25 |
|
26 |
my $schema = Koha::Database->new()->schema(); |
27 |
$schema->storage->txn_begin(); |
28 |
|
29 |
subtest 'Test Koha::MetadataRecord::Authority' => sub { |
30 |
plan tests => 4; |
31 |
|
32 |
my $dbh = C4::Context->dbh; |
33 |
|
34 |
$dbh->do("DELETE FROM auth_header"); |
35 |
|
36 |
my $offset = 1; |
37 |
my $length = 2; |
38 |
my %iterator_options; |
39 |
|
40 |
#test without items in auth_header |
41 |
|
42 |
my $records = Koha::MetadataRecord::Authority->get_all_authorities_iterator(\%iterator_options, $offset, $length); |
43 |
|
44 |
is(ref($records),'Koha::MetadataIterator',"the package name isn't Koha::MetadataIterator"); |
45 |
|
46 |
my $count = 0; |
47 |
|
48 |
while ($records->next()) { |
49 |
$count++; |
50 |
} |
51 |
|
52 |
is($count,0,"There is not the right number of notices"); |
53 |
|
54 |
my $builder = t::lib::TestBuilder->new(); |
55 |
|
56 |
# create three auth types |
57 |
|
58 |
my $authtype1 = $builder->build({ |
59 |
source => 'AuthType', |
60 |
value => { |
61 |
auth_tag_to_report => '1', |
62 |
}, |
63 |
}); |
64 |
my $authtype2 = $builder->build({ |
65 |
source => 'AuthType', |
66 |
value => { |
67 |
auth_tag_to_report => '2', |
68 |
}, |
69 |
}); |
70 |
my $authtype3 = $builder->build({ |
71 |
source => 'AuthType', |
72 |
value => { |
73 |
auth_tag_to_report => '3', |
74 |
}, |
75 |
}); |
76 |
|
77 |
# Add three authority records |
78 |
|
79 |
my $auth1 = MARC::Record->new; |
80 |
$auth1->append_fields( MARC::Field->new( '109', '0', '0', 'a' => 'Auth1' )); |
81 |
my $authid1 = AddAuthority( $auth1, undef, $authtype1->{'authtypecode'} ); |
82 |
|
83 |
my $auth2 = MARC::Record->new; |
84 |
$auth2->append_fields( MARC::Field->new( '110', '0', '0', 'a' => 'Auth2' )); |
85 |
my $authid2 = AddAuthority( $auth2, undef, $authtype2->{'authtypecode'} ); |
86 |
|
87 |
my $auth3 = MARC::Record->new; |
88 |
$auth3->append_fields( MARC::Field->new( '111', '0', '0', 'a' => 'Auth3' )); |
89 |
my $authid3 = AddAuthority( $auth3, undef, $authtype3->{'authtypecode'} ); |
90 |
|
91 |
#test with items in auth_header |
92 |
|
93 |
$records = Koha::MetadataRecord::Authority->get_all_authorities_iterator(\%iterator_options, $offset, $length); |
94 |
|
95 |
is(ref($records),'Koha::MetadataIterator',"the package name is Koha::MetadataIterator"); |
96 |
|
97 |
$count = 0; |
98 |
|
99 |
while ($records->next()) { |
100 |
$count++; |
101 |
} |
102 |
|
103 |
is($count,2,"There is the right number of notices"); |
104 |
|
105 |
}; |
106 |
|
107 |
$schema->storage->txn_rollback; |