Skip to content

Commit

Permalink
Tests/Build Tools: Introduce tests for links_add_base_url().
Browse files Browse the repository at this point in the history
Props pbearne, rajinsharwar, jorbin, mukesh27, aristath, desrosj, ironprogrammer.
Fixes #60389.




git-svn-id: https://develop.svn.wordpress.org/trunk@59162 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
peterwilsoncc committed Oct 3, 2024
1 parent 278d1d5 commit 636d748
Showing 1 changed file with 94 additions and 0 deletions.
94 changes: 94 additions & 0 deletions tests/phpunit/tests/formatting/linksAddBaseUrl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

/**
* Tests for the links_add_base_url function.
*
* @group formatting
*
* @covers ::links_add_base_url
*/
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 {
$this->assertSame( $expected, links_add_base_url( $content, $base ) );
}
}

/**
* Data provider for test_links_add_base_url().
*
* @return array[]
*/
public function data_links_add_base_url() {
return array(
'https' => array(
'content' => '<a href="url" />',
'base' => 'https://localhost',
'attrs' => null,
'expected' => '<a href="https://localhost/url" />',
),
'http' => array(
'content' => '<a href="url" />',
'base' => 'http://localhost',
'attrs' => null,
'expected' => '<a href="http://localhost/url" />',
),
'relative_scheme' => array(
'content' => '<a href="//localhost/url" />',
'base' => 'http://localhost',
'attrs' => null,
'expected' => '<a href="http://localhost/url" />',
),
'empty_array' => array(
'content' => '<a href="url" target="_blank" />',
'base' => 'https://localhost',
'attrs' => array(),
'expected' => '<a href="https://localhost/url" target="_blank" />',
),
'data_url' => array(
'content' => '<a href="url" data-url="url" />',
'base' => 'https://localhost',
'attrs' => array( 'data-url', 'href' ),
'expected' => '<a href="https://localhost/url" data-url="https://localhost/url" />',
),
'not relative' => array(
'content' => '<a href="https://localhost/url" />',
'base' => 'https://localbase',
'attrs' => null,
'expected' => '<a href="https://localhost/url" />',
),
'no_href' => array(
'content' => '<a data-url="/url" />',
'base' => 'https://localhost',
'attrs' => null,
'expected' => '<a data-url="/url" />',
),
'img' => array(
'content' => '<img src="/url" />',
'base' => 'https://localhost',
'attrs' => null,
'expected' => '<img src="https://localhost/url" />',
),
'ftp' => array(
'content' => '<a href="/url" >sss</a>',
'base' => 'ftp://localhost',
'attrs' => null,
'expected' => '<a href="ftp://localhost/url" >sss</a>',
),
'ftps' => array(
'content' => '<a href="/url" >sss</a>',
'base' => 'ftps://localhost',
'attrs' => null,
'expected' => '<a href="ftps://localhost/url" >sss</a>',
),
);
}
}

0 comments on commit 636d748

Please sign in to comment.