Bugzilla – Attachment 115784 Details for
Bug 27353
Return the number of total records
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 27353: Add tests
Bug-27353-Add-tests.patch (text/plain), 9.25 KB, created by
Tomás Cohen Arazi (tcohen)
on 2021-01-25 17:52:44 UTC
(
hide
)
Description:
Bug 27353: Add tests
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2021-01-25 17:52:44 UTC
Size:
9.25 KB
patch
obsolete
>From 4da2a132d0f001d24960336e303ff764eefba5d7 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Wed, 6 Jan 2021 17:11:30 +0100 >Subject: [PATCH] Bug 27353: Add tests > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > t/Koha/REST/Plugin/Pagination.t | 22 ++++++++++---- > t/db_dependent/Koha/REST/Plugin/Objects.t | 35 +++++++++++++++++++++++ > 2 files changed, 51 insertions(+), 6 deletions(-) > >diff --git a/t/Koha/REST/Plugin/Pagination.t b/t/Koha/REST/Plugin/Pagination.t >index dff13fb770f..e8d25e73601 100755 >--- a/t/Koha/REST/Plugin/Pagination.t >+++ b/t/Koha/REST/Plugin/Pagination.t >@@ -33,19 +33,19 @@ get '/empty' => sub { > > get '/pagination_headers' => sub { > my $c = shift; >- $c->add_pagination_headers({ total => 10, params => { _page => 2, _per_page => 3, firstname => 'Jonathan' } }); >+ $c->add_pagination_headers({ total => 10, base_total => 12, params => { _page => 2, _per_page => 3, firstname => 'Jonathan' } }); > $c->render( json => { ok => 1 }, status => 200 ); > }; > > get '/pagination_headers_first_page' => sub { > my $c = shift; >- $c->add_pagination_headers({ total => 10, params => { _page => 1, _per_page => 3, firstname => 'Jonathan' } }); >+ $c->add_pagination_headers({ total => 10, base_total => 12, params => { _page => 1, _per_page => 3, firstname => 'Jonathan' } }); > $c->render( json => { ok => 1 }, status => 200 ); > }; > > get '/pagination_headers_last_page' => sub { > my $c = shift; >- $c->add_pagination_headers({ total => 10, params => { _page => 4, _per_page => 3, firstname => 'Jonathan' } }); >+ $c->add_pagination_headers({ total => 10, base_total => 12, params => { _page => 4, _per_page => 3, firstname => 'Jonathan' } }); > $c->render( json => { ok => 1 }, status => 200 ); > }; > >@@ -60,13 +60,13 @@ get '/dbic_merge_pagination' => sub { > > get '/pagination_headers_without_page_size' => sub { > my $c = shift; >- $c->add_pagination_headers({ total => 10, params => { _page => 2, firstname => 'Jonathan' } }); >+ $c->add_pagination_headers({ total => 10, base_total => 12, 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 => 3, firstname => 'Jonathan' } }); >+ $c->add_pagination_headers({ total => 10, base_total => 12, params => { _per_page => 3, firstname => 'Jonathan' } }); > $c->render( json => { ok => 1 }, status => 200 ); > }; > >@@ -75,6 +75,7 @@ get '/pagination_headers_with_minus_one' => sub { > $c->add_pagination_headers( > { > total => 10, >+ base_total => 12, > params => { _per_page => -1, firstname => 'Jonathan' } > } > ); >@@ -86,6 +87,7 @@ get '/pagination_headers_with_minus_one_and_invalid_page' => sub { > $c->add_pagination_headers( > { > total => 10, >+ base_total => 12, > params => { page => 100, _per_page => -1, firstname => 'Jonathan' } > } > ); >@@ -101,18 +103,20 @@ use t::lib::Mocks; > > subtest 'add_pagination_headers() tests' => sub { > >- plan tests => 101; >+ plan tests => 109; > > my $t = Test::Mojo->new; > > $t->get_ok('/empty') > ->status_is( 200 ) > ->header_is( 'X-Total-Count' => undef, 'X-Total-Count is undefined' ) >+ ->header_is( 'X-Base-Total-Count' => undef, 'X-Base-Total-Count is undefined' ) > ->header_is( 'Link' => undef, 'Link is undefined' ); > > $t->get_ok('/pagination_headers') > ->status_is( 200 ) > ->header_is( 'X-Total-Count' => 10, 'X-Total-Count contains the passed value' ) >+ ->header_is( 'X-Base-Total-Count' => 12, 'X-Base-Total-Count contains the passed value' ) > ->header_like( 'Link' => qr/<http:\/\/.*\?.*_per_page=3.*>; rel="prev",/ ) > ->header_like( 'Link' => qr/<http:\/\/.*\?.*_page=1.*>; rel="prev",/ ) > ->header_like( 'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="prev",/ ) >@@ -129,6 +133,7 @@ subtest 'add_pagination_headers() tests' => sub { > $t->get_ok('/pagination_headers_first_page') > ->status_is( 200 ) > ->header_is( 'X-Total-Count' => 10, 'X-Total-Count contains the passed value' ) >+ ->header_is( 'X-Base-Total-Count' => 12, 'X-Base-Total-Count contains the passed value' ) > ->header_unlike( 'Link' => qr/<http:\/\/.*\?.*>; rel="prev",/ ) > ->header_like( 'Link' => qr/<http:\/\/.*\?.*_per_page=3.*>; rel="next",/ ) > ->header_like( 'Link' => qr/<http:\/\/.*\?.*_page=2.*>; rel="next",/ ) >@@ -143,6 +148,7 @@ subtest 'add_pagination_headers() tests' => sub { > $t->get_ok('/pagination_headers_last_page') > ->status_is( 200 ) > ->header_is( 'X-Total-Count' => 10, 'X-Total-Count contains the passed value' ) >+ ->header_is( 'X-Base-Total-Count' => 12, 'X-Base-Total-Count contains the passed value' ) > ->header_like( 'Link' => qr/<http:\/\/.*\?.*_per_page=3.*>; rel="prev",/ ) > ->header_like( 'Link' => qr/<http:\/\/.*\?.*_page=3.*>; rel="prev",/ ) > ->header_like( 'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="prev",/ ) >@@ -158,6 +164,7 @@ subtest 'add_pagination_headers() tests' => sub { > $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_is( 'X-Base-Total-Count' => 12, 'X-Base-Total-Count contains the passed value' ) > ->header_like( 'Link' => qr/<http:\/\/.*\?.*per_page=3.*>; rel="prev",/ ) > ->header_like( 'Link' => qr/<http:\/\/.*\?.*page=1.*>; rel="prev",/ ) > ->header_like( 'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="prev",/ ) >@@ -174,6 +181,7 @@ subtest 'add_pagination_headers() tests' => sub { > $t->get_ok('/pagination_headers_without_page') > ->status_is( 200 ) > ->header_is( 'X-Total-Count' => 10, 'X-Total-Count header present, even without page param' ) >+ ->header_is( 'X-Base-Total-Count' => 12, 'X-Base-Total-Count contains the passed value' ) > ->header_unlike( 'Link' => qr/<http:\/\/.*\?.*per_page=3.*>; rel="prev",/, 'First page, no previous' ) > ->header_unlike( 'Link' => qr/<http:\/\/.*\?.*page=1.*>; rel="prev",/, 'First page, no previous' ) > ->header_unlike( 'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="prev",/, 'First page, no previous' ) >@@ -190,6 +198,7 @@ subtest 'add_pagination_headers() tests' => sub { > $t->get_ok('/pagination_headers_with_minus_one') > ->status_is( 200 ) > ->header_is( 'X-Total-Count' => 10, 'X-Total-Count header present, with per_page=-1' ) >+ ->header_is( 'X-Base-Total-Count' => 12, 'X-Base-Total-Count contains the passed value' ) > ->header_unlike( 'Link' => qr/<http:\/\/.*\?.*per_page=-1.*>; rel="prev",/, 'First page, no previous' ) > ->header_unlike( 'Link' => qr/<http:\/\/.*\?.*page=1.*>; rel="prev",/, 'First page, no previous' ) > ->header_unlike( 'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="prev",/, 'First page, no previous' ) >@@ -204,6 +213,7 @@ subtest 'add_pagination_headers() tests' => sub { > $t->get_ok('/pagination_headers_with_minus_one_and_invalid_page') > ->status_is( 200 ) > ->header_is( 'X-Total-Count' => 10, 'X-Total-Count header present, with per_page=-1' ) >+ ->header_is( 'X-Base-Total-Count' => 12, 'X-Base-Total-Count contains the passed value' ) > ->header_unlike( 'Link' => qr/<http:\/\/.*\?.*per_page=-1.*>; rel="prev",/, 'First page, no previous' ) > ->header_unlike( 'Link' => qr/<http:\/\/.*\?.*page=1.*>; rel="prev",/, 'First page, no previous' ) > ->header_unlike( 'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="prev",/, 'First page, no previous' ) >diff --git a/t/db_dependent/Koha/REST/Plugin/Objects.t b/t/db_dependent/Koha/REST/Plugin/Objects.t >index cbec228ce92..4b86ad5aff1 100755 >--- a/t/db_dependent/Koha/REST/Plugin/Objects.t >+++ b/t/db_dependent/Koha/REST/Plugin/Objects.t >@@ -259,6 +259,41 @@ subtest 'objects.search helper, encoding' => sub { > $schema->storage->txn_rollback; > }; > >+subtest 'objects.search helper, X-Total-Count and X-Base-Total-Count' => sub { >+ >+ plan tests => 8; >+ >+ $schema->storage->txn_begin; >+ >+ Koha::Cities->delete; >+ >+ my $long_city_name = 'Llanfairpwllgwyngyll'; >+ for my $i ( 1 .. length($long_city_name) ) { >+ $builder->build_object( >+ { >+ class => 'Koha::Cities', >+ value => { >+ city_name => substr( $long_city_name, 0, $i ), >+ city_country => 'Wales' >+ } >+ } >+ ); >+ } >+ >+ my $t = Test::Mojo->new; >+ $t->get_ok('/cities?name=L&_per_page=10&_page=1&_match=starts_with') >+ ->status_is(200) >+ ->header_is( 'X-Total-Count' => 20, 'X-Total-Count header present' ) >+ ->header_is( 'X-Base-Total-Count' => 20, 'X-Base-Total-Count header present' ); >+ >+ $t->get_ok('/cities?name=Llan&_per_page=10&_page=1&_match=starts_with') >+ ->status_is(200) >+ ->header_is( 'X-Total-Count' => 17, 'X-Total-Count header present' ) >+ ->header_is('X-Base-Total-Count' => 20, 'X-Base-Total-Count header present' ); >+ >+ $schema->storage->txn_rollback; >+}; >+ > subtest 'objects.search helper, embed' => sub { > > plan tests => 2; >-- >2.30.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 27353
:
114893
|
114896
|
114897
|
115039
|
115058
|
115059
|
115769
|
115771
|
115784
|
115785
|
115786
|
115807
|
115808
|
115809