summaryrefslogtreecommitdiffstatshomepage
path: root/tests
diff options
context:
space:
mode:
authorPeter Wilson <peterwilsoncc@git.wordpress.org>2025-03-26 23:31:51 +0000
committerPeter Wilson <peterwilsoncc@git.wordpress.org>2025-03-26 23:31:51 +0000
commita1b24c9716a4145e118d913ea4434eb2933ce6b2 (patch)
treedc9f21c3f50a240c613bd860c92c270e3e128491 /tests
parenta7d9869bd2cac31b4b6db676b00a754c11385260 (diff)
downloadwordpress-a1b24c9716a4145e118d913ea4434eb2933ce6b2.tar.gz
wordpress-a1b24c9716a4145e118d913ea4434eb2933ce6b2.zip
Build/Test Tools: Expand tests of `paginate_links`' `format` parameter.
Introduces additional tests for custom formatted pagination links to include: - plain permalinks - html file extensions - hyphen separated links - URL fragments See #63167. git-svn-id: https://develop.svn.wordpress.org/trunk@60100 602fd350-edb4-49c9-b593-d223f7449a82
Diffstat (limited to 'tests')
-rw-r--r--tests/phpunit/tests/general/paginateLinks.php33
1 files changed, 27 insertions, 6 deletions
diff --git a/tests/phpunit/tests/general/paginateLinks.php b/tests/phpunit/tests/general/paginateLinks.php
index 516afa25b9..d9833c6245 100644
--- a/tests/phpunit/tests/general/paginateLinks.php
+++ b/tests/phpunit/tests/general/paginateLinks.php
@@ -33,11 +33,17 @@ EXPECTED;
$this->assertSameIgnoreEOL( $expected, $links );
}
- public function test_format() {
- $page2 = home_url( '/page/2/' );
- $page3 = home_url( '/page/3/' );
- $page50 = home_url( '/page/50/' );
-
+ /**
+ * Test the format parameter behaves as expected.
+ *
+ * @dataProvider data_format
+ *
+ * @param string $format Format to test.
+ * @param string $page2 Expected URL for page 2.
+ * @param string $page3 Expected URL for page 3.
+ * @param string $page50 Expected URL for page 50.
+ */
+ public function test_format( $format, $page2, $page3, $page50 ) {
$expected = <<<EXPECTED
<span aria-current="page" class="page-numbers current">1</span>
<a class="page-numbers" href="$page2">2</a>
@@ -50,12 +56,27 @@ EXPECTED;
$links = paginate_links(
array(
'total' => 50,
- 'format' => 'page/%#%/',
+ 'format' => $format,
)
);
$this->assertSameIgnoreEOL( $expected, $links );
}
+ /**
+ * Data provider for test_format.
+ *
+ * @return array[] Data provider.
+ */
+ public function data_format() {
+ return array(
+ 'pretty permalinks' => array( 'page/%#%/', home_url( '/page/2/' ), home_url( '/page/3/' ), home_url( '/page/50/' ) ),
+ 'plain permalinks' => array( '?page=%#%', home_url( '/?page=2' ), home_url( '/?page=3' ), home_url( '/?page=50' ) ),
+ 'custom format - html extension' => array( 'page/%#%.html', home_url( '/page/2.html' ), home_url( '/page/3.html' ), home_url( '/page/50.html' ) ),
+ 'custom format - hyphen separated' => array( 'page-%#%', home_url( '/page-2' ), home_url( '/page-3' ), home_url( '/page-50' ) ),
+ 'custom format - fragment' => array( '#%#%', home_url( '/#2' ), home_url( '/#3' ), home_url( '/#50' ) ),
+ );
+ }
+
public function test_prev_next_false() {
$home = home_url( '/' );
$page3 = get_pagenum_link( 3 );