View | Details | Raw Unified | Return to bug 20384
Collapse All | Expand All

(-)a/t/db_dependent/Koha/BiblioUtils/get_all_biblios_iterator.t (+82 lines)
Line 0 Link Here
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::BiblioUtils;
18
use Koha::SearchEngine::Elasticsearch;
19
use t::lib::TestBuilder;
20
use C4::Biblio;
21
use C4::AuthoritiesMarc;
22
23
use Test::More tests => 4;
24
25
my $schema = Koha::Database->new()->schema();
26
$schema->storage->txn_begin();
27
28
my $dbh = C4::Context->dbh;
29
30
$dbh->do("DELETE FROM reserves");
31
$dbh->do("DELETE FROM issues");
32
$dbh->do("DELETE FROM biblio");
33
$dbh->do("DELETE FROM biblioitems");
34
35
my $offset = 1;
36
my $length = 2;
37
38
#test without items in biblioitems
39
40
my $records = Koha::BiblioUtils->get_all_biblios_iterator($offset, $length);
41
42
is(ref($records),'Koha::MetadataIterator',"the package name isn't Koha::MetadataIterator");
43
44
my $count = 0;
45
46
while ($records->next()) {
47
    $count++;
48
}
49
50
is($count,0,"There is not the right number of notices");
51
52
my $builder = t::lib::TestBuilder->new();
53
54
# Add three biblio records
55
56
my $biblio1 = MARC::Record->new;
57
$biblio1->append_fields( MARC::Field->new( '200', '0', '0', 'a' => 'Titre1' ));
58
my $biblionumber1 = AddBiblio($biblio1, '');
59
60
my $biblio2 = MARC::Record->new;
61
$biblio2->append_fields( MARC::Field->new( '201', '0', '0', 'a' => 'Titre2' ));
62
my $biblionumber2 = AddBiblio($biblio2, '');
63
64
my $biblio3 = MARC::Record->new;
65
$biblio3->append_fields( MARC::Field->new( '202', '0', '0', 'a' => 'Titre2' ));
66
my $biblionumber3 = AddBiblio($biblio3, '');
67
68
#test with items in biblioitems
69
70
$records = Koha::BiblioUtils->get_all_biblios_iterator($offset, $length);
71
72
is(ref($records),'Koha::MetadataIterator',"the package name is Koha::MetadataIterator");
73
74
$count = 0;
75
76
while ($records->next()) {
77
    $count++;
78
}
79
80
is($count,2,"There is the right number of notices");
81
82
$schema->storage->txn_rollback;
(-)a/t/db_dependent/Koha/MetadataRecord/Authority.t (-1 / +106 lines)
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;

Return to bug 20384