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

(-)a/installer/data/mysql/updatedatabase.pl (-2 / +1 lines)
Lines 11478-11486 if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { Link Here
11478
11478
11479
    foreach my $subscription ( $sth->fetchrow_hashref() ) {
11479
    foreach my $subscription ( $sth->fetchrow_hashref() ) {
11480
        next if !defined($subscription);
11480
        next if !defined($subscription);
11481
        my $number_pattern = $subscription->numberpattern();
11482
        $sth2->execute( $subscription->{numberpattern} );
11481
        $sth2->execute( $subscription->{numberpattern} );
11483
        $number_pattern = $sth2->fetchrow_hashref();
11482
        my $number_pattern = $sth2->fetchrow_hashref();
11484
11483
11485
        my $numbering_method = $number_pattern->{numberingmethod};
11484
        my $numbering_method = $number_pattern->{numberingmethod};
11486
        # Get all the data between the enumeration values, we need
11485
        # Get all the data between the enumeration values, we need
(-)a/t/db_dependent/OAI/Server.t (-50 / +201 lines)
Lines 1-6 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
# Copyright Tamil s.a.r.l. 2015
3
# Copyright Tamil s.a.r.l. 2016
4
#
4
#
5
# This file is part of Koha.
5
# This file is part of Koha.
6
#
6
#
Lines 21-32 Link Here
21
use Modern::Perl;
21
use Modern::Perl;
22
use C4::Context;
22
use C4::Context;
23
use C4::Biblio;
23
use C4::Biblio;
24
use Test::More tests => 13;
24
use Test::More tests => 23;
25
use Test::MockModule;
25
use Test::MockModule;
26
use Test::Warn;
26
use Test::Warn;
27
use DateTime;
27
use DateTime;
28
use XML::Simple;
28
use XML::Simple;
29
use t::lib::Mocks;
29
use t::lib::Mocks;
30
use t::lib::TestBuilder;
31
32
use YAML;
33
use Data::Dump qw/dump/;
34
30
35
31
36
32
BEGIN {
37
BEGIN {
Lines 47-94 BEGIN { Link Here
47
# Mocked CGI module in order to be able to send CGI parameters to OAI Server
52
# Mocked CGI module in order to be able to send CGI parameters to OAI Server
48
my %param;
53
my %param;
49
my $module = Test::MockModule->new('CGI');
54
my $module = Test::MockModule->new('CGI');
50
$module->mock('Vars', sub { %param; });
55
    $module->mock('Vars', sub { %param; });
51
56
57
my $schema = Koha::Database->schema;
58
$schema->storage->txn_begin;
52
my $dbh = C4::Context->dbh;
59
my $dbh = C4::Context->dbh;
53
$dbh->{AutoCommit} = 0;
60
54
$dbh->{RaiseError} = 1;
61
my $builder = t::lib::TestBuilder->new;
55
$dbh->do('DELETE FROM issues');
62
56
$dbh->do('DELETE FROM biblio');
63
$dbh->do('SET FOREIGN_KEY_CHECKS = 0');
57
$dbh->do('DELETE FROM biblioitems');
64
$dbh->do('TRUNCATE biblio');
58
$dbh->do('DELETE FROM items');
65
$dbh->do('TRUNCATE biblioitems');
66
$dbh->do('TRUNCATE issues');
59
67
60
# Add 10 biblio records
68
# Add 10 biblio records
61
my @bibs = map {
69
our $tz = DateTime::TimeZone->new( name => 'local' );
70
my $date_added = DateTime->now(time_zone =>$tz) . 'Z';
71
my $date_to = substr($date_added, 0, 10) . 'T23:59:59Z';
72
73
my (@header, @metadata, @record);
74
map {
62
    my $record = MARC::Record->new();
75
    my $record = MARC::Record->new();
63
    $record->append_fields( MARC::Field->new('245', '', '', 'a' => "Title $_" ) );
76
    $record->append_fields( MARC::Field->new('245', '', '', 'a' => "Title $_" ) );
64
    my ($biblionumber) = AddBiblio($record, '');
77
    my ($biblionumber) = AddBiblio($record, '');
65
    $biblionumber;
78
    $record = GetMarcBiblio($biblionumber);
79
    $record = XMLin($record->as_xml_record);
80
    $header[$biblionumber] = { datestamp => $date_added, identifier => "TEST:$biblionumber" };
81
    delete $record->{$_} for (('xmlns','xmlns:xsi','xsi:schemaLocation'));
82
    $metadata[$biblionumber] = { collection => {
83
        record => $record,
84
        "xmlns" => "http://www.loc.gov/MARC21/slim",
85
        "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
86
        "xsi:schemaLocation" => "http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd",
87
    } };
88
    $record[$biblionumber] = {
89
        header => $header[$biblionumber],
90
        metadata => $metadata[$biblionumber],
91
    };
92
    $biblionumber => undef;
66
} (1..10);
93
} (1..10);
67
94
68
t::lib::Mocks::mock_preference('LibraryName', 'My Library');
95
69
t::lib::Mocks::mock_preference('OAI::PMH', 1);
96
my $syspref = {
70
t::lib::Mocks::mock_preference('OAI-PMH:archiveID', 'TEST');
97
    'LibraryName'           => 'My Library',
71
t::lib::Mocks::mock_preference('OAI-PMH:ConfFile', '' );
98
    'OAI::PMH'              => 1,
72
t::lib::Mocks::mock_preference('OAI-PMH:MaxCount', 3);
99
    'OAI-PMH:archiveID'     => 'TEST',
73
t::lib::Mocks::mock_preference('OAI-PMH:DeletedRecord', 'persistent');
100
    'OAI-PMH:ConfFile'      => '',
74
101
    'OAI-PMH:MaxCount'      => 3,
75
%param = ( verb => 'ListMetadataFormats' );
102
    'OAI-PMH:DeletedRecord' => 'persistent',
76
my $response;
77
my $get_response = sub {
78
    my $stdout;
79
    local *STDOUT;
80
    open STDOUT, '>', \$stdout;
81
    Koha::OAI::Server::Repository->new();
82
    $response = XMLin($stdout);
83
};
103
};
84
$get_response->();
104
while ( my ($name, $value) = each %$syspref ) {
85
my $now = DateTime->now . 'Z';
105
    t::lib::Mocks::mock_preference( $name => $value );
86
my $expected = {
106
}
87
    request => 'http://localhost',
107
88
    responseDate => $now,
108
89
    xmlns => 'http://www.openarchives.org/OAI/2.0/',
109
sub test_query {
90
    'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
110
    my ($test, $param, $expected) = @_;
91
    'xsi:schemaLocation' => 'http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd',
111
112
    %param = %$param;
113
    my %full_expected = (
114
        %$expected,
115
        (
116
            request => 'http://localhost',
117
            responseDate => DateTime->now . 'Z',
118
            xmlns => 'http://www.openarchives.org/OAI/2.0/',
119
            'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
120
            'xsi:schemaLocation' => 'http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd',
121
        )
122
    );
123
124
    my $response;
125
    {
126
        my $stdout;
127
        local *STDOUT;
128
        open STDOUT, '>', \$stdout;
129
        Koha::OAI::Server::Repository->new();
130
        $response = XMLin($stdout);
131
    }
132
    if ($test eq 'ListRecords with resumptionToken 3') {
133
        say "expected: ", Dump(\%full_expected);
134
        say "response: ", Dump($response);
135
    }
136
137
    is_deeply($response, \%full_expected, $test);
138
}
139
140
141
test_query('ListMetadataFormats', {verb => 'ListMetadataFormats'}, {
92
    ListMetadataFormats => {
142
    ListMetadataFormats => {
93
        metadataFormat => [
143
        metadataFormat => [
94
            {
144
            {
Lines 103-125 my $expected = { Link Here
103
            },
153
            },
104
        ],
154
        ],
105
    },
155
    },
106
};
156
} );
107
is_deeply($response, $expected, "ListMetadataFormats");
157
108
158
test_query('ListIdentifiers without metadataPrefix', {verb => 'ListIdentifiers'}, {
109
%param = ( verb => 'ListIdentifiers' );
110
$get_response->();
111
$now = DateTime->now . 'Z';
112
$expected = {
113
    request => 'http://localhost',
114
    responseDate => $now,
115
    xmlns => 'http://www.openarchives.org/OAI/2.0/',
116
    'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
117
    'xsi:schemaLocation' => 'http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd',
118
    error => {
159
    error => {
119
        code => 'badArgument',
160
        code => 'badArgument',
120
        content => "Required argument 'metadataPrefix' was undefined",
161
        content => "Required argument 'metadataPrefix' was undefined",
121
    },
162
    },
122
};
163
});
123
is_deeply($response, $expected, "ListIdentifiers without metadaPrefix argument");
164
165
166
test_query('ListIdentifiers', {verb => 'ListIdentifiers', metadataPrefix => 'marcxml'}, {
167
    ListIdentifiers => {
168
        header => [ @header[1..3] ],
169
        resumptionToken => {
170
            content => "marcxml/3/1970-01-01T00:00:00Z/$date_to/",
171
            cursor  => 3,
172
        },
173
    },
174
});
175
176
test_query('ListIdentifiers', {verb => 'ListIdentifiers', metadataPrefix => 'marcxml'}, {
177
    ListIdentifiers => {
178
        header => [ @header[1..3] ],
179
        resumptionToken => {
180
            content => "marcxml/3/1970-01-01T00:00:00Z/$date_to/",
181
            cursor  => 3,
182
        },
183
    },
184
});
185
186
test_query(
187
    'ListIdentifiers with resumptionToken 1',
188
    { verb => 'ListIdentifiers', resumptionToken => "marcxml/3/1970-01-01T00:00:00Z/$date_to/" },
189
    {
190
        ListIdentifiers => {
191
            header => [ @header[4..6] ],
192
            resumptionToken => {
193
              content => "marcxml/6/1970-01-01T00:00:00Z/$date_to/",
194
              cursor  => 6,
195
            },
196
          },
197
198
    },
199
);
200
201
test_query(
202
    'ListIdentifiers with resumptionToken 2',
203
    { verb => 'ListIdentifiers', resumptionToken => "marcxml/6/1970-01-01T00:00:00Z/$date_to/" },
204
    {
205
        ListIdentifiers => {
206
            header => [ @header[7..9] ],
207
            resumptionToken => {
208
              content => "marcxml/9/1970-01-01T00:00:00Z/$date_to/",
209
              cursor  => 9,
210
            },
211
          },
212
213
    },
214
);
215
216
test_query(
217
    'ListIdentifiers with resumptionToken 3, response without resumption',
218
    { verb => 'ListIdentifiers', resumptionToken => "marcxml/9/1970-01-01T00:00:00Z/$date_to/" },
219
    {
220
        ListIdentifiers => {
221
            header => $header[10],
222
          },
223
224
    },
225
);
226
227
test_query('ListRecords without metadataPrefix', {verb => 'ListRecords'}, {
228
    error => {
229
        code => 'badArgument',
230
        content => "Required argument 'metadataPrefix' was undefined",
231
    },
232
});
233
234
test_query('ListRecords', {verb => 'ListRecords', metadataPrefix => 'marcxml'}, {
235
    ListRecords => {
236
        record => [ @record[1..3] ],
237
        resumptionToken => {
238
          content => "marcxml/3/1970-01-01T00:00:00Z/$date_to/",
239
          cursor  => 3,
240
        },
241
    },
242
});
243
244
test_query(
245
    'ListRecords with resumptionToken 1',
246
    { verb => 'ListRecords', resumptionToken => "marcxml/3/1970-01-01T00:00:00Z/$date_to/" },
247
    { ListRecords => {
248
        record => [ @record[4..6] ],
249
        resumptionToken => {
250
          content => "marcxml/6/1970-01-01T00:00:00Z/$date_to/",
251
          cursor  => 6,
252
        },
253
    },
254
});
255
256
test_query(
257
    'ListRecords with resumptionToken 2',
258
    { verb => 'ListRecords', resumptionToken => "marcxml/6/1970-01-01T00:00:00Z/$date_to/" },
259
    { ListRecords => {
260
        record => [ @record[7..9] ],
261
        resumptionToken => {
262
          content => "marcxml/9/1970-01-01T00:00:00Z/$date_to/",
263
          cursor  => 9,
264
        },
265
    },
266
});
267
268
# Last record, so no resumption token
269
test_query(
270
    'ListRecords with resumptionToken 3, response without resumption',
271
    { verb => 'ListRecords', resumptionToken => "marcxml/9/1970-01-01T00:00:00Z/$date_to/" },
272
    { ListRecords => {
273
        record => $record[10],
274
    },
275
});
124
276
125
$dbh->rollback;
277
$schema->storage->txn_rollback;
126
- 

Return to bug 17493