Skip to content

Commit

Permalink
test: added test for Pagination class
Browse files Browse the repository at this point in the history
  • Loading branch information
thorsten committed Mar 28, 2024
1 parent 5f9e238 commit 4c385a5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion phpmyfaq/src/phpMyFAQ/Pagination.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public function __construct(array $options = null)
$this->rewriteUrl = $options['rewriteUrl'];
}

// Let this call to be last cuz it needs some options to be set before
// Let this call to be last cuz it needs some options to be set before
$this->currentPage = $this->getCurrentPageFromUrl($this->baseUrl);
}

Expand Down
33 changes: 33 additions & 0 deletions tests/phpMyFAQ/PaginationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace phpMyFAQ;

use PHPUnit\Framework\TestCase;

class PaginationTest extends TestCase
{
public function testRender(): void
{
$pagination = new Pagination([
'total' => 30,
'perPage' => 10,
'baseUrl' => 'http://example.com?action=foo'
]);

$expectedOutput =
'<ul class="pagination justify-content-center">' .
'<li class="page-item active">' .
'<a class="page-link" href="http://example.com?action=foo&amp;page=1">1</a>' .
'</li>&nbsp;&nbsp;<li class="page-item">' .
'<a class="page-link" href="http://example.com?action=foo&amp;page=2">2</a>' .
'</li>&nbsp;&nbsp;<li class="page-item">' .
'<a class="page-link" href="http://example.com?action=foo&amp;page=3">3</a>' .
'</li>&nbsp;&nbsp;<li class="page-item">' .
'<a class="page-link" href="http://example.com?action=foo&amp;page=2">&rarr;</a>' .
'</li>&nbsp;&nbsp;<li class="page-item">' .
'<a class="page-link" href="http://example.com?action=foo&amp;page=3">&#8677;</a>' .
'</li></ul>';

$this->assertEquals($expectedOutput, $pagination->render());
}
}

0 comments on commit 4c385a5

Please sign in to comment.