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

(-)a/t/db_dependent/Koha/BiblioUtils/get_all_biblios_iterator.t (+83 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
my %iterator_options;
38
39
#test without items in biblioitems
40
41
my $records = Koha::BiblioUtils->get_all_biblios_iterator(\%iterator_options,$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
# Add three biblio records
56
57
my $biblio1 = MARC::Record->new;
58
$biblio1->append_fields( MARC::Field->new( '200', '0', '0', 'a' => 'Titre1' ));
59
my $biblionumber1 = AddBiblio($biblio1, '');
60
61
my $biblio2 = MARC::Record->new;
62
$biblio2->append_fields( MARC::Field->new( '201', '0', '0', 'a' => 'Titre2' ));
63
my $biblionumber2 = AddBiblio($biblio2, '');
64
65
my $biblio3 = MARC::Record->new;
66
$biblio3->append_fields( MARC::Field->new( '202', '0', '0', 'a' => 'Titre2' ));
67
my $biblionumber3 = AddBiblio($biblio3, '');
68
69
#test with items in biblioitems
70
71
$records = Koha::BiblioUtils->get_all_biblios_iterator(\%iterator_options,$offset, $length);
72
73
is(ref($records),'Koha::MetadataIterator',"the package name is Koha::MetadataIterator");
74
75
$count = 0;
76
77
while ($records->next()) {
78
    $count++;
79
}
80
81
is($count,2,"There is the right number of notices");
82
83
$schema->storage->txn_rollback;
(-)a/t/db_dependent/Koha/MetadataRecord/Authority.t (-1 / +107 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
    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;

Return to bug 20384