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

(-)a/t/Koha/REST/Plugin/Pagination.t (-2 / +39 lines)
Lines 48-61 get '/pagination_headers_last_page' => sub { Link Here
48
    $c->render( json => { ok => 1 }, status => 200 );
48
    $c->render( json => { ok => 1 }, status => 200 );
49
};
49
};
50
50
51
get '/pagination_headers_without_page_size' => sub {
52
    my $c = shift;
53
    $c->add_pagination_headers({ total => 10, params => { page => 2, firstname => 'Jonathan' } });
54
    $c->render( json => { ok => 1 }, status => 200 );
55
};
56
57
get '/pagination_headers_without_page' => sub {
58
    my $c = shift;
59
    $c->add_pagination_headers({ total => 10, params => { per_page => 4, firstname => 'Jonathan' } });
60
    $c->render( json => { ok => 1 }, status => 200 );
61
};
62
51
# The tests
63
# The tests
52
64
53
use Test::More tests => 1;
65
use Test::More tests => 1;
54
use Test::Mojo;
66
use Test::Mojo;
55
67
68
use t::lib::Mocks;
69
56
subtest 'add_pagination_headers() tests' => sub {
70
subtest 'add_pagination_headers() tests' => sub {
57
71
58
    plan tests => 45;
72
    plan tests => 64;
59
73
60
    my $t = Test::Mojo->new;
74
    my $t = Test::Mojo->new;
61
75
Lines 107-110 subtest 'add_pagination_headers() tests' => sub { Link Here
107
      ->header_like(   'Link' => qr/<http:\/\/.*\?.*per_page=3.*>; rel="last"/ )
121
      ->header_like(   'Link' => qr/<http:\/\/.*\?.*per_page=3.*>; rel="last"/ )
108
      ->header_like(   'Link' => qr/<http:\/\/.*\?.*page=4.*>; rel="last"/ )
122
      ->header_like(   'Link' => qr/<http:\/\/.*\?.*page=4.*>; rel="last"/ )
109
      ->header_like(   'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="last"/ );
123
      ->header_like(   'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="last"/ );
124
125
    t::lib::Mocks::mock_preference('RESTdefaultPageSize', 3);
126
    $t->get_ok('/pagination_headers_without_page_size')
127
      ->status_is( 200 )
128
      ->header_is( 'X-Total-Count' => 10, 'X-Total-Count contains the passed value' )
129
      ->header_like( 'Link' => qr/<http:\/\/.*\?.*per_page=3.*>; rel="prev",/ )
130
      ->header_like( 'Link' => qr/<http:\/\/.*\?.*page=1.*>; rel="prev",/ )
131
      ->header_like( 'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="prev",/ )
132
      ->header_like( 'Link' => qr/<http:\/\/.*\?.*per_page=3.*>; rel="next",/ )
133
      ->header_like( 'Link' => qr/<http:\/\/.*\?.*page=3.*>; rel="next",/ )
134
      ->header_like( 'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="next",/ )
135
      ->header_like( 'Link' => qr/<http:\/\/.*\?.*per_page=3.*>; rel="first",/ )
136
      ->header_like( 'Link' => qr/<http:\/\/.*\?.*page=1.*>; rel="first",/ )
137
      ->header_like( 'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="first",/ )
138
      ->header_like( 'Link' => qr/<http:\/\/.*\?.*per_page=3.*>; rel="last"/ )
139
      ->header_like( 'Link' => qr/<http:\/\/.*\?.*page=4.*>; rel="last"/ )
140
      ->header_like( 'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="last"/ );
141
142
    $t->get_ok('/pagination_headers_without_page')
143
      ->status_is( 200 )
144
      ->header_is( 'X-Total-Count' => undef, 'X-Total-Count header absent' )
145
      ->header_is( 'Link'          => undef, 'Link header absent' );
146
147
110
};
148
};
111
- 

Return to bug 19278