forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests/Build Tools: Introduce tests for
links_add_base_url()
.
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
1 parent
278d1d5
commit 636d748
Showing
1 changed file
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>', | ||
), | ||
); | ||
} | ||
} |