Skip to content

Commit

Permalink
Tests: Bring some consistency to links_add_base_url() and `links_ad…
Browse files Browse the repository at this point in the history
…d_target()` tests.

Includes:
* Correcting the test class name as per the naming conventions.
* Documenting data provider values using hash notation.
* Passing the `$attrs` parameter to the function if not `null`.

Follow-up to [26328], [55563], [59162].

See #61530.

git-svn-id: https://develop.svn.wordpress.org/trunk@59163 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
SergeyBiryukov committed Oct 3, 2024
1 parent 636d748 commit 0e69bc9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
31 changes: 19 additions & 12 deletions tests/phpunit/tests/formatting/linksAddBaseUrl.php
Original file line number Diff line number Diff line change
@@ -1,31 +1,38 @@
<?php

/**
* Tests for the links_add_base_url function.
* Tests for the links_add_base_url() function.
*
* @group formatting
*
* @covers ::links_add_base_url
*/
class Tests_formatting_linksAddBaseUrl extends WP_UnitTestCase {
class Tests_Formatting_LinksAddBaseUrl extends WP_UnitTestCase {

/**
* @ticket 60389
*
* @dataProvider data_links_add_base_url
*/
public function test_links_add_base_url( $content, $base, $attrs, $expected ) {
if ( $attrs ) {
$this->assertSame( $expected, links_add_base_url( $content, $base, $attrs ) );
} else {
if ( is_null( $attrs ) ) {
$this->assertSame( $expected, links_add_base_url( $content, $base ) );
} else {
$this->assertSame( $expected, links_add_base_url( $content, $base, $attrs ) );
}
}

/**
* Data provider for test_links_add_base_url().
* Data provider.
*
* @return array[]
* @return array {
* @type array {
* @type string $content String to search for links in.
* @type string $base The base URL to prefix to links.
* @type array|null $attrs The attributes which should be processed.
* @type string $expected Expected output.
* }
* }
*/
public function data_links_add_base_url() {
return array(
Expand All @@ -41,19 +48,19 @@ public function data_links_add_base_url() {
'attrs' => null,
'expected' => '<a href="http://localhost/url" />',
),
'relative_scheme' => array(
'relative scheme' => array(
'content' => '<a href="//localhost/url" />',
'base' => 'http://localhost',
'attrs' => null,
'expected' => '<a href="http://localhost/url" />',
),
'empty_array' => array(
'empty array' => array(
'content' => '<a href="url" target="_blank" />',
'base' => 'https://localhost',
'attrs' => array(),
'expected' => '<a href="https://localhost/url" target="_blank" />',
'expected' => '<a href="https://localhost/url" target="https://localhost/_blank" />',
),
'data_url' => array(
'data-url' => array(
'content' => '<a href="url" data-url="url" />',
'base' => 'https://localhost',
'attrs' => array( 'data-url', 'href' ),
Expand All @@ -65,7 +72,7 @@ public function data_links_add_base_url() {
'attrs' => null,
'expected' => '<a href="https://localhost/url" />',
),
'no_href' => array(
'no href' => array(
'content' => '<a data-url="/url" />',
'base' => 'https://localhost',
'attrs' => null,
Expand Down
12 changes: 7 additions & 5 deletions tests/phpunit/tests/formatting/linksAddTarget.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<?php
/**
* Tests for the links_add_target() function.
*
* @group formatting
*
* @covers ::links_add_target
*/
class Tests_Formatting_LinksAddTarget extends WP_UnitTestCase {

/**
* Tests the links_add_target() function.
* @ticket 26164
*
* @dataProvider data_links_add_target
*/
Expand All @@ -26,10 +28,10 @@ public function test_links_add_target( $content, $target, $tags, $expected ) {
*
* @return array {
* @type array {
* @type string $content String to search for links in.
* @type string $target The target to add to the links.
* @type string $tags An array of tags to apply to.
* @type string $expected Expected output.
* @type string $content String to search for links in.
* @type string $target The target to add to the links.
* @type array|null $tags An array of tags to apply to.
* @type string $expected Expected output.
* }
* }
*/
Expand Down

0 comments on commit 0e69bc9

Please sign in to comment.