Skip to content

Commit

Permalink
test: fix unit test for pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
sectsect committed Nov 30, 2024
1 parent fd84df6 commit c07de62
Showing 1 changed file with 34 additions and 5 deletions.
39 changes: 34 additions & 5 deletions tests/FunctionTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,49 @@ public function testPaginationOutput() {
$current_page = 1;
$total_pages = 5;
$range = 2;
$nonce = wp_create_nonce( 'google_ss2db_pagination' );

// Expected output.
$expected_output = '<ul class="pagination">';
$expected_output .= '<li class="current"><span>1</span></li>';
$expected_output .= '<li><a href="' . get_pagenum_link( $current_page + 1 ) . '">2</a></li>';
$expected_output .= '<li><a href="' . get_pagenum_link( $current_page + 2 ) . '">3</a></li>';
$expected_output .= '<li><a href="' . get_pagenum_link( $current_page + 3 ) . '">4</a></li>';
$expected_output .= '<li><a href="' . get_pagenum_link( $current_page + 4 ) . '">5</a></li>';
$expected_output .= '<li><a href="' . esc_url(
add_query_arg(
array(
'paged' => 2,
'nonce' => $nonce,
)
)
) . '">2</a></li>';
$expected_output .= '<li><a href="' . esc_url(
add_query_arg(
array(
'paged' => 3,
'nonce' => $nonce,
)
)
) . '">3</a></li>';
$expected_output .= '<li><a href="' . esc_url(
add_query_arg(
array(
'paged' => 4,
'nonce' => $nonce,
)
)
) . '">4</a></li>';
$expected_output .= '<li><a href="' . esc_url(
add_query_arg(
array(
'paged' => 5,
'nonce' => $nonce,
)
)
) . '">5</a></li>';
$expected_output .= '</ul>';

// Capture the output.
$this->expectOutputString( $expected_output );

// Execute the pagination function.
google_ss2db_options_pagination( $current_page, $total_pages, $range );
google_ss2db_options_pagination( $current_page, $total_pages, $range, $nonce );
}
}

0 comments on commit c07de62

Please sign in to comment.