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 |
|
39 |
#test without items in auth_header |
40 |
|
41 |
my $records = Koha::MetadataRecord::Authority->get_all_authorities_iterator($offset, $length); |
42 |
|
43 |
is(ref($records),'Koha::MetadataIterator',"the package name isn't Koha::MetadataIterator"); |
44 |
|
45 |
my $count = 0; |
46 |
|
47 |
while ($records->next()) { |
48 |
$count++; |
49 |
} |
50 |
|
51 |
is($count,0,"There is not the right number of notices"); |
52 |
|
53 |
my $builder = t::lib::TestBuilder->new(); |
54 |
|
55 |
# create three auth types |
56 |
|
57 |
my $authtype1 = $builder->build({ |
58 |
source => 'AuthType', |
59 |
value => { |
60 |
auth_tag_to_report => '1', |
61 |
}, |
62 |
}); |
63 |
my $authtype2 = $builder->build({ |
64 |
source => 'AuthType', |
65 |
value => { |
66 |
auth_tag_to_report => '2', |
67 |
}, |
68 |
}); |
69 |
my $authtype3 = $builder->build({ |
70 |
source => 'AuthType', |
71 |
value => { |
72 |
auth_tag_to_report => '3', |
73 |
}, |
74 |
}); |
75 |
|
76 |
# Add three authority records |
77 |
|
78 |
my $auth1 = MARC::Record->new; |
79 |
$auth1->append_fields( MARC::Field->new( '109', '0', '0', 'a' => 'Auth1' )); |
80 |
my $authid1 = AddAuthority( $auth1, undef, $authtype1->{'authtypecode'} ); |
81 |
|
82 |
my $auth2 = MARC::Record->new; |
83 |
$auth2->append_fields( MARC::Field->new( '110', '0', '0', 'a' => 'Auth2' )); |
84 |
my $authid2 = AddAuthority( $auth2, undef, $authtype2->{'authtypecode'} ); |
85 |
|
86 |
my $auth3 = MARC::Record->new; |
87 |
$auth3->append_fields( MARC::Field->new( '111', '0', '0', 'a' => 'Auth3' )); |
88 |
my $authid3 = AddAuthority( $auth3, undef, $authtype3->{'authtypecode'} ); |
89 |
|
90 |
#test with items in auth_header |
91 |
|
92 |
$records = Koha::MetadataRecord::Authority->get_all_authorities_iterator($offset, $length); |
93 |
|
94 |
is(ref($records),'Koha::MetadataIterator',"the package name is Koha::MetadataIterator"); |
95 |
|
96 |
$count = 0; |
97 |
|
98 |
while ($records->next()) { |
99 |
$count++; |
100 |
} |
101 |
|
102 |
is($count,2,"There is the right number of notices"); |
103 |
|
104 |
}; |
105 |
|
106 |
$schema->storage->txn_rollback; |