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

(-)a/t/Koha/REST/Plugin/Pagination.t (-6 / +16 lines)
Lines 33-51 get '/empty' => sub { Link Here
33
33
34
get '/pagination_headers' => sub {
34
get '/pagination_headers' => sub {
35
    my $c = shift;
35
    my $c = shift;
36
    $c->add_pagination_headers({ total => 10, params => { _page => 2, _per_page => 3, firstname => 'Jonathan' } });
36
    $c->add_pagination_headers({ total => 10, base_total => 12, params => { _page => 2, _per_page => 3, firstname => 'Jonathan' } });
37
    $c->render( json => { ok => 1 }, status => 200 );
37
    $c->render( json => { ok => 1 }, status => 200 );
38
};
38
};
39
39
40
get '/pagination_headers_first_page' => sub {
40
get '/pagination_headers_first_page' => sub {
41
    my $c = shift;
41
    my $c = shift;
42
    $c->add_pagination_headers({ total => 10, params => { _page => 1, _per_page => 3, firstname => 'Jonathan' } });
42
    $c->add_pagination_headers({ total => 10, base_total => 12, params => { _page => 1, _per_page => 3, firstname => 'Jonathan' } });
43
    $c->render( json => { ok => 1 }, status => 200 );
43
    $c->render( json => { ok => 1 }, status => 200 );
44
};
44
};
45
45
46
get '/pagination_headers_last_page' => sub {
46
get '/pagination_headers_last_page' => sub {
47
    my $c = shift;
47
    my $c = shift;
48
    $c->add_pagination_headers({ total => 10, params => { _page => 4, _per_page => 3, firstname => 'Jonathan' } });
48
    $c->add_pagination_headers({ total => 10, base_total => 12, params => { _page => 4, _per_page => 3, firstname => 'Jonathan' } });
49
    $c->render( json => { ok => 1 }, status => 200 );
49
    $c->render( json => { ok => 1 }, status => 200 );
50
};
50
};
51
51
Lines 60-72 get '/dbic_merge_pagination' => sub { Link Here
60
60
61
get '/pagination_headers_without_page_size' => sub {
61
get '/pagination_headers_without_page_size' => sub {
62
    my $c = shift;
62
    my $c = shift;
63
    $c->add_pagination_headers({ total => 10, params => { _page => 2, firstname => 'Jonathan' } });
63
    $c->add_pagination_headers({ total => 10, base_total => 12, params => { _page => 2, firstname => 'Jonathan' } });
64
    $c->render( json => { ok => 1 }, status => 200 );
64
    $c->render( json => { ok => 1 }, status => 200 );
65
};
65
};
66
66
67
get '/pagination_headers_without_page' => sub {
67
get '/pagination_headers_without_page' => sub {
68
    my $c = shift;
68
    my $c = shift;
69
    $c->add_pagination_headers({ total => 10, params => { _per_page => 3, firstname => 'Jonathan' } });
69
    $c->add_pagination_headers({ total => 10, base_total => 12, params => { _per_page => 3, firstname => 'Jonathan' } });
70
    $c->render( json => { ok => 1 }, status => 200 );
70
    $c->render( json => { ok => 1 }, status => 200 );
71
};
71
};
72
72
Lines 75-80 get '/pagination_headers_with_minus_one' => sub { Link Here
75
    $c->add_pagination_headers(
75
    $c->add_pagination_headers(
76
        {
76
        {
77
            total => 10,
77
            total => 10,
78
            base_total => 12,
78
            params => { _per_page => -1, firstname => 'Jonathan' }
79
            params => { _per_page => -1, firstname => 'Jonathan' }
79
        }
80
        }
80
    );
81
    );
Lines 86-91 get '/pagination_headers_with_minus_one_and_invalid_page' => sub { Link Here
86
    $c->add_pagination_headers(
87
    $c->add_pagination_headers(
87
        {
88
        {
88
            total  => 10,
89
            total  => 10,
90
            base_total => 12,
89
            params => { page => 100, _per_page => -1, firstname => 'Jonathan' }
91
            params => { page => 100, _per_page => -1, firstname => 'Jonathan' }
90
        }
92
        }
91
    );
93
    );
Lines 101-118 use t::lib::Mocks; Link Here
101
103
102
subtest 'add_pagination_headers() tests' => sub {
104
subtest 'add_pagination_headers() tests' => sub {
103
105
104
    plan tests => 101;
106
    plan tests => 109;
105
107
106
    my $t = Test::Mojo->new;
108
    my $t = Test::Mojo->new;
107
109
108
    $t->get_ok('/empty')
110
    $t->get_ok('/empty')
109
      ->status_is( 200 )
111
      ->status_is( 200 )
110
      ->header_is( 'X-Total-Count' => undef, 'X-Total-Count is undefined' )
112
      ->header_is( 'X-Total-Count' => undef, 'X-Total-Count is undefined' )
113
      ->header_is( 'X-Base-Total-Count' => undef, 'X-Base-Total-Count is undefined' )
111
      ->header_is( 'Link'          => undef, 'Link is undefined' );
114
      ->header_is( 'Link'          => undef, 'Link is undefined' );
112
115
113
    $t->get_ok('/pagination_headers')
116
    $t->get_ok('/pagination_headers')
114
      ->status_is( 200 )
117
      ->status_is( 200 )
115
      ->header_is( 'X-Total-Count' => 10, 'X-Total-Count contains the passed value' )
118
      ->header_is( 'X-Total-Count' => 10, 'X-Total-Count contains the passed value' )
119
      ->header_is( 'X-Base-Total-Count' => 12, 'X-Base-Total-Count contains the passed value' )
116
      ->header_like( 'Link' => qr/<http:\/\/.*\?.*_per_page=3.*>; rel="prev",/ )
120
      ->header_like( 'Link' => qr/<http:\/\/.*\?.*_per_page=3.*>; rel="prev",/ )
117
      ->header_like( 'Link' => qr/<http:\/\/.*\?.*_page=1.*>; rel="prev",/ )
121
      ->header_like( 'Link' => qr/<http:\/\/.*\?.*_page=1.*>; rel="prev",/ )
118
      ->header_like( 'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="prev",/ )
122
      ->header_like( 'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="prev",/ )
Lines 129-134 subtest 'add_pagination_headers() tests' => sub { Link Here
129
    $t->get_ok('/pagination_headers_first_page')
133
    $t->get_ok('/pagination_headers_first_page')
130
      ->status_is( 200 )
134
      ->status_is( 200 )
131
      ->header_is( 'X-Total-Count' => 10, 'X-Total-Count contains the passed value' )
135
      ->header_is( 'X-Total-Count' => 10, 'X-Total-Count contains the passed value' )
136
      ->header_is( 'X-Base-Total-Count' => 12, 'X-Base-Total-Count contains the passed value' )
132
      ->header_unlike( 'Link' => qr/<http:\/\/.*\?.*>; rel="prev",/ )
137
      ->header_unlike( 'Link' => qr/<http:\/\/.*\?.*>; rel="prev",/ )
133
      ->header_like(   'Link' => qr/<http:\/\/.*\?.*_per_page=3.*>; rel="next",/ )
138
      ->header_like(   'Link' => qr/<http:\/\/.*\?.*_per_page=3.*>; rel="next",/ )
134
      ->header_like(   'Link' => qr/<http:\/\/.*\?.*_page=2.*>; rel="next",/ )
139
      ->header_like(   'Link' => qr/<http:\/\/.*\?.*_page=2.*>; rel="next",/ )
Lines 143-148 subtest 'add_pagination_headers() tests' => sub { Link Here
143
    $t->get_ok('/pagination_headers_last_page')
148
    $t->get_ok('/pagination_headers_last_page')
144
      ->status_is( 200 )
149
      ->status_is( 200 )
145
      ->header_is( 'X-Total-Count' => 10, 'X-Total-Count contains the passed value' )
150
      ->header_is( 'X-Total-Count' => 10, 'X-Total-Count contains the passed value' )
151
      ->header_is( 'X-Base-Total-Count' => 12, 'X-Base-Total-Count contains the passed value' )
146
      ->header_like(   'Link' => qr/<http:\/\/.*\?.*_per_page=3.*>; rel="prev",/ )
152
      ->header_like(   'Link' => qr/<http:\/\/.*\?.*_per_page=3.*>; rel="prev",/ )
147
      ->header_like(   'Link' => qr/<http:\/\/.*\?.*_page=3.*>; rel="prev",/ )
153
      ->header_like(   'Link' => qr/<http:\/\/.*\?.*_page=3.*>; rel="prev",/ )
148
      ->header_like(   'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="prev",/ )
154
      ->header_like(   'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="prev",/ )
Lines 158-163 subtest 'add_pagination_headers() tests' => sub { Link Here
158
    $t->get_ok('/pagination_headers_without_page_size')
164
    $t->get_ok('/pagination_headers_without_page_size')
159
      ->status_is( 200 )
165
      ->status_is( 200 )
160
      ->header_is( 'X-Total-Count' => 10, 'X-Total-Count contains the passed value' )
166
      ->header_is( 'X-Total-Count' => 10, 'X-Total-Count contains the passed value' )
167
      ->header_is( 'X-Base-Total-Count' => 12, 'X-Base-Total-Count contains the passed value' )
161
      ->header_like( 'Link' => qr/<http:\/\/.*\?.*per_page=3.*>; rel="prev",/ )
168
      ->header_like( 'Link' => qr/<http:\/\/.*\?.*per_page=3.*>; rel="prev",/ )
162
      ->header_like( 'Link' => qr/<http:\/\/.*\?.*page=1.*>; rel="prev",/ )
169
      ->header_like( 'Link' => qr/<http:\/\/.*\?.*page=1.*>; rel="prev",/ )
163
      ->header_like( 'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="prev",/ )
170
      ->header_like( 'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="prev",/ )
Lines 174-179 subtest 'add_pagination_headers() tests' => sub { Link Here
174
    $t->get_ok('/pagination_headers_without_page')
181
    $t->get_ok('/pagination_headers_without_page')
175
      ->status_is( 200 )
182
      ->status_is( 200 )
176
      ->header_is( 'X-Total-Count' => 10, 'X-Total-Count header present, even without page param' )
183
      ->header_is( 'X-Total-Count' => 10, 'X-Total-Count header present, even without page param' )
184
      ->header_is( 'X-Base-Total-Count' => 12, 'X-Base-Total-Count contains the passed value' )
177
      ->header_unlike( 'Link' => qr/<http:\/\/.*\?.*per_page=3.*>; rel="prev",/, 'First page, no previous' )
185
      ->header_unlike( 'Link' => qr/<http:\/\/.*\?.*per_page=3.*>; rel="prev",/, 'First page, no previous' )
178
      ->header_unlike( 'Link' => qr/<http:\/\/.*\?.*page=1.*>; rel="prev",/, 'First page, no previous' )
186
      ->header_unlike( 'Link' => qr/<http:\/\/.*\?.*page=1.*>; rel="prev",/, 'First page, no previous' )
179
      ->header_unlike( 'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="prev",/, 'First page, no previous' )
187
      ->header_unlike( 'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="prev",/, 'First page, no previous' )
Lines 190-195 subtest 'add_pagination_headers() tests' => sub { Link Here
190
    $t->get_ok('/pagination_headers_with_minus_one')
198
    $t->get_ok('/pagination_headers_with_minus_one')
191
      ->status_is( 200 )
199
      ->status_is( 200 )
192
      ->header_is( 'X-Total-Count' => 10, 'X-Total-Count header present, with per_page=-1' )
200
      ->header_is( 'X-Total-Count' => 10, 'X-Total-Count header present, with per_page=-1' )
201
      ->header_is( 'X-Base-Total-Count' => 12, 'X-Base-Total-Count contains the passed value' )
193
      ->header_unlike( 'Link' => qr/<http:\/\/.*\?.*per_page=-1.*>; rel="prev",/, 'First page, no previous' )
202
      ->header_unlike( 'Link' => qr/<http:\/\/.*\?.*per_page=-1.*>; rel="prev",/, 'First page, no previous' )
194
      ->header_unlike( 'Link' => qr/<http:\/\/.*\?.*page=1.*>; rel="prev",/, 'First page, no previous' )
203
      ->header_unlike( 'Link' => qr/<http:\/\/.*\?.*page=1.*>; rel="prev",/, 'First page, no previous' )
195
      ->header_unlike( 'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="prev",/, 'First page, no previous' )
204
      ->header_unlike( 'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="prev",/, 'First page, no previous' )
Lines 204-209 subtest 'add_pagination_headers() tests' => sub { Link Here
204
    $t->get_ok('/pagination_headers_with_minus_one_and_invalid_page')
213
    $t->get_ok('/pagination_headers_with_minus_one_and_invalid_page')
205
      ->status_is( 200 )
214
      ->status_is( 200 )
206
      ->header_is( 'X-Total-Count' => 10, 'X-Total-Count header present, with per_page=-1' )
215
      ->header_is( 'X-Total-Count' => 10, 'X-Total-Count header present, with per_page=-1' )
216
      ->header_is( 'X-Base-Total-Count' => 12, 'X-Base-Total-Count contains the passed value' )
207
      ->header_unlike( 'Link' => qr/<http:\/\/.*\?.*per_page=-1.*>; rel="prev",/, 'First page, no previous' )
217
      ->header_unlike( 'Link' => qr/<http:\/\/.*\?.*per_page=-1.*>; rel="prev",/, 'First page, no previous' )
208
      ->header_unlike( 'Link' => qr/<http:\/\/.*\?.*page=1.*>; rel="prev",/, 'First page, no previous' )
218
      ->header_unlike( 'Link' => qr/<http:\/\/.*\?.*page=1.*>; rel="prev",/, 'First page, no previous' )
209
      ->header_unlike( 'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="prev",/, 'First page, no previous' )
219
      ->header_unlike( 'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="prev",/, 'First page, no previous' )
(-)a/t/db_dependent/Koha/REST/Plugin/Objects.t (-2 / +36 lines)
Lines 65-71 get '/biblios' => sub { Link Here
65
};
65
};
66
66
67
# The tests
67
# The tests
68
use Test::More tests => 9;
68
use Test::More tests => 10;
69
use Test::Mojo;
69
use Test::Mojo;
70
70
71
use t::lib::Mocks;
71
use t::lib::Mocks;
Lines 247-252 subtest 'objects.search helper, encoding' => sub { Link Here
247
    $schema->storage->txn_rollback;
247
    $schema->storage->txn_rollback;
248
};
248
};
249
249
250
subtest 'objects.search helper, X-Total-Count and X-Base-Total-Count' => sub {
251
252
    plan tests => 8;
253
254
    $schema->storage->txn_begin;
255
256
    Koha::Cities->delete;
257
258
    my $long_city_name = 'Llanfairpwllgwyngyll';
259
    for my $i ( 1 .. length($long_city_name) ) {
260
        $builder->build_object(
261
            {
262
                class => 'Koha::Cities',
263
                value => {
264
                    city_name    => substr( $long_city_name, 0, $i ),
265
                    city_country => 'Wales'
266
                }
267
            }
268
        );
269
    }
270
271
    my $t = Test::Mojo->new;
272
    $t->get_ok('/cities?name=L&_per_page=10&_page=1&_match=starts_with')
273
      ->status_is(200)
274
      ->header_is( 'X-Total-Count' => 20, 'X-Total-Count header present' )
275
      ->header_is( 'X-Base-Total-Count' => 20, 'X-Base-Total-Count header present' );
276
277
    $t->get_ok('/cities?name=Llan&_per_page=10&_page=1&_match=starts_with')
278
      ->status_is(200)
279
      ->header_is( 'X-Total-Count' => 17, 'X-Total-Count header present' )
280
      ->header_is('X-Base-Total-Count' => 20, 'X-Base-Total-Count header present' );
281
282
    $schema->storage->txn_rollback;
283
};
284
250
subtest 'objects.search helper, embed' => sub {
285
subtest 'objects.search helper, embed' => sub {
251
286
252
    plan tests => 2;
287
    plan tests => 2;
253
- 

Return to bug 27353