Make WordPress Core

Changeset 59163


Ignore:
Timestamp:
10/03/2024 11:42:43 PM (2 months ago)
Author:
SergeyBiryukov
Message:

Tests: Bring some consistency to links_add_base_url() and links_add_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.

Location:
trunk/tests/phpunit/tests/formatting
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/formatting/linksAddBaseUrl.php

    r59162 r59163  
    22
    33/**
    4  * Tests for the links_add_base_url function.
     4 * Tests for the links_add_base_url() function.
    55 *
    66 * @group formatting
     
    88 * @covers ::links_add_base_url
    99 */
    10 class Tests_formatting_linksAddBaseUrl extends WP_UnitTestCase {
     10class Tests_Formatting_LinksAddBaseUrl extends WP_UnitTestCase {
    1111
    1212    /**
     
    1616     */
    1717    public function test_links_add_base_url( $content, $base, $attrs, $expected ) {
    18         if ( $attrs ) {
     18        if ( is_null( $attrs ) ) {
     19            $this->assertSame( $expected, links_add_base_url( $content, $base ) );
     20        } else {
    1921            $this->assertSame( $expected, links_add_base_url( $content, $base, $attrs ) );
    20         } else {
    21             $this->assertSame( $expected, links_add_base_url( $content, $base ) );
    2222        }
    2323    }
    2424
    2525    /**
    26      * Data provider for test_links_add_base_url().
     26     * Data provider.
    2727     *
    28      * @return array[]
     28     * @return array {
     29     *     @type array {
     30     *         @type string     $content  String to search for links in.
     31     *         @type string     $base     The base URL to prefix to links.
     32     *         @type array|null $attrs    The attributes which should be processed.
     33     *         @type string     $expected Expected output.
     34     *     }
     35     * }
    2936     */
    3037    public function data_links_add_base_url() {
     
    4249                'expected' => '<a href="http://localhost/url" />',
    4350            ),
    44             'relative_scheme' => array(
     51            'relative scheme' => array(
    4552                'content'  => '<a href="//localhost/url" />',
    4653                'base'     => 'http://localhost',
     
    4855                'expected' => '<a href="http://localhost/url" />',
    4956            ),
    50             'empty_array'     => array(
     57            'empty array'     => array(
    5158                'content'  => '<a href="url" target="_blank" />',
    5259                'base'     => 'https://localhost',
    5360                'attrs'    => array(),
    54                 'expected' => '<a href="https://localhost/url" target="_blank" />',
     61                'expected' => '<a href="https://localhost/url" target="https://localhost/_blank" />',
    5562            ),
    56             'data_url'        => array(
     63            'data-url'        => array(
    5764                'content'  => '<a href="url" data-url="url" />',
    5865                'base'     => 'https://localhost',
     
    6673                'expected' => '<a href="https://localhost/url" />',
    6774            ),
    68             'no_href'         => array(
     75            'no href'         => array(
    6976                'content'  => '<a data-url="/url" />',
    7077                'base'     => 'https://localhost',
  • trunk/tests/phpunit/tests/formatting/linksAddTarget.php

    r55563 r59163  
    11<?php
    22/**
     3 * Tests for the links_add_target() function.
     4 *
    35 * @group formatting
    46 *
     
    810
    911    /**
    10      * Tests the links_add_target() function.
     12     * @ticket 26164
    1113     *
    1214     * @dataProvider data_links_add_target
     
    2729     * @return array {
    2830     *     @type array {
    29      *         @type string $content  String to search for links in.
    30      *         @type string $target   The target to add to the links.
    31      *         @type string $tags     An array of tags to apply to.
    32      *         @type string $expected Expected output.
     31     *         @type string     $content  String to search for links in.
     32     *         @type string     $target   The target to add to the links.
     33     *         @type array|null $tags     An array of tags to apply to.
     34     *         @type string     $expected Expected output.
    3335     *     }
    3436     * }
Note: See TracChangeset for help on using the changeset viewer.