From 4f04e9af5eeb7ab42860defbbdd1716398d8de76 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Fri, 8 Sep 2017 12:18:35 -0300 Subject: [PATCH] Bug 19278: Unit tests This patch introduces tests for a behaviour change in Koha::REST::Plugin::Pagination. To test: - Run: $ sudo koha-shell kohadev k$ cd kohaclone k$ prove t/Koha/REST/Plugin/Pagination.t => FAIL: Tests should fail without the followup patch applied Sponsored-by: Camden County Sponsored-by: Bywater Solutions --- t/Koha/REST/Plugin/Pagination.t | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/t/Koha/REST/Plugin/Pagination.t b/t/Koha/REST/Plugin/Pagination.t index 04d51e1f44..b4a8c8e73e 100644 --- a/t/Koha/REST/Plugin/Pagination.t +++ b/t/Koha/REST/Plugin/Pagination.t @@ -48,14 +48,28 @@ get '/pagination_headers_last_page' => sub { $c->render( json => { ok => 1 }, status => 200 ); }; +get '/pagination_headers_without_page_size' => sub { + my $c = shift; + $c->add_pagination_headers({ total => 10, params => { page => 2, firstname => 'Jonathan' } }); + $c->render( json => { ok => 1 }, status => 200 ); +}; + +get '/pagination_headers_without_page' => sub { + my $c = shift; + $c->add_pagination_headers({ total => 10, params => { per_page => 4, firstname => 'Jonathan' } }); + $c->render( json => { ok => 1 }, status => 200 ); +}; + # The tests use Test::More tests => 1; use Test::Mojo; +use t::lib::Mocks; + subtest 'add_pagination_headers() tests' => sub { - plan tests => 45; + plan tests => 64; my $t = Test::Mojo->new; @@ -107,4 +121,28 @@ subtest 'add_pagination_headers() tests' => sub { ->header_like( 'Link' => qr/; rel="last"/ ) ->header_like( 'Link' => qr/; rel="last"/ ) ->header_like( 'Link' => qr/; rel="last"/ ); + + t::lib::Mocks::mock_preference('RESTdefaultPageSize', 3); + $t->get_ok('/pagination_headers_without_page_size') + ->status_is( 200 ) + ->header_is( 'X-Total-Count' => 10, 'X-Total-Count contains the passed value' ) + ->header_like( 'Link' => qr/; rel="prev",/ ) + ->header_like( 'Link' => qr/; rel="prev",/ ) + ->header_like( 'Link' => qr/; rel="prev",/ ) + ->header_like( 'Link' => qr/; rel="next",/ ) + ->header_like( 'Link' => qr/; rel="next",/ ) + ->header_like( 'Link' => qr/; rel="next",/ ) + ->header_like( 'Link' => qr/; rel="first",/ ) + ->header_like( 'Link' => qr/; rel="first",/ ) + ->header_like( 'Link' => qr/; rel="first",/ ) + ->header_like( 'Link' => qr/; rel="last"/ ) + ->header_like( 'Link' => qr/; rel="last"/ ) + ->header_like( 'Link' => qr/; rel="last"/ ); + + $t->get_ok('/pagination_headers_without_page') + ->status_is( 200 ) + ->header_is( 'X-Total-Count' => undef, 'X-Total-Count header absent' ) + ->header_is( 'Link' => undef, 'Link header absent' ); + + }; -- 2.14.1