3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use Test::More tests => 1;
30 use Koha::SearchEngine::Search;
32 subtest "pagination_bar tests" => sub {
35 my @sort_by = ('relevance_dsc');
37 my ( $PAGE_NUMBERS, $hits_to_paginate, $pages, $current_page_number,
38 $previous_page_offset, $next_page_offset, $last_page_offset )
39 = Koha::SearchEngine::Search->pagination_bar(
42 max_result_window => 1000,
43 results_per_page => 20,
48 is( $hits_to_paginate, 500,
49 "We paginate all hits if less than max_result_window" );
50 is( $pages, 25, "We have hits/hits_to_paginate pages" );
51 is( $current_page_number, 9,
52 "We calculate current page by offset/results_per_page plus 1" );
53 is( $previous_page_offset, 140,
54 "Previous page is current offset minus reults per page" );
55 is( $next_page_offset, 180,
56 "Next page is current offset plus reults per page" );
57 is( $last_page_offset, 480,
58 "Last page is pages minus 1 times reults per page" );
59 is( @$PAGE_NUMBERS, 10, "If on first ten pages we only show 10 pages" );
62 $PAGE_NUMBERS, $hits_to_paginate, $pages, $current_page_number,
63 $previous_page_offset, $next_page_offset, $last_page_offset
65 = Koha::SearchEngine::Search->pagination_bar(
68 max_result_window => 480,
69 results_per_page => 20,
74 is( $hits_to_paginate, 480,
75 "We paginate all hits if less than max_result_window" );
76 is( $pages, 24, "We have hits/hits_to_paginate pages" );
77 is( $current_page_number, 13,
78 "We calculate current page by offset/results_per_page plus 1" );
79 is( $previous_page_offset, 220,
80 "Previous page is current offset minus reults per page" );
81 is( $next_page_offset, 260,
82 "Next page is current offset plus reults per page" );
83 is( $last_page_offset, 460,
84 "Last page is pages minus 1 times reults per page" );
85 is( @$PAGE_NUMBERS, 20, "If past first ten pages we show 20 pages" );