From eeaadcf833d45b8bce0c1a9659de93edce1e036e 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 Signed-off-by: Lari Taskula Signed-off-by: Kyle M Hall --- 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 37cf0ca..43e9f07 100644 --- a/t/Koha/REST/Plugin/Pagination.t +++ b/t/Koha/REST/Plugin/Pagination.t @@ -58,14 +58,28 @@ get '/dbic_merge_pagination' => sub { $c->render( json => $filter, 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 => 2; use Test::Mojo; +use t::lib::Mocks; + subtest 'add_pagination_headers() tests' => sub { - plan tests => 45; + plan tests => 64; my $t = Test::Mojo->new; @@ -117,6 +131,30 @@ 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' ); + + }; subtest 'dbic_merge_pagination() tests' => sub { -- 2.10.2