mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-05-19 10:44:24 +00:00
Comments: Adjust comment_author_email_link() and get_comment_author_email_link() to each accept a new optional fourth parameter, $comment, which enables overriding the $comment global.
Adds tests. Props flixos90, boonebgorges, DrewAPicture. See #36571. git-svn-id: https://develop.svn.wordpress.org/trunk@37348 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
99
tests/phpunit/tests/comment/getCommentAuthorEmailLink.php
Normal file
99
tests/phpunit/tests/comment/getCommentAuthorEmailLink.php
Normal file
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
/**
|
||||
* @group comment
|
||||
*/
|
||||
class Tests_Comment_GetCommentAuthorEmailLink extends WP_UnitTestCase {
|
||||
public static $comment;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Fake the 'comment' global.
|
||||
$GLOBALS['comment'] = self::$comment;
|
||||
|
||||
// Remove obfuscation for testing purposes.
|
||||
remove_filter( 'comment_email', 'antispambot' );
|
||||
}
|
||||
|
||||
public function tearDown() {
|
||||
unset( $GLOBALS['comment'] );
|
||||
parent::tearDown();
|
||||
|
||||
add_filter( 'comment_email', 'antispambot' );
|
||||
}
|
||||
|
||||
public static function wpSetUpBeforeClass( $factory ) {
|
||||
self::$comment = $factory->comment->create_and_get( array(
|
||||
'comment_author_email' => 'foo@example.org'
|
||||
) );
|
||||
}
|
||||
|
||||
public static function wpTearDownAfterClass() {
|
||||
wp_delete_comment( self::$comment->comment_ID, true );
|
||||
}
|
||||
|
||||
public function test_global_comment_with_default_parameters() {
|
||||
$expected = '<a href="mailto:foo@example.org">foo@example.org</a>';
|
||||
|
||||
$this->assertEquals( $expected, get_comment_author_email_link() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 36571
|
||||
*/
|
||||
public function test_all_parameters() {
|
||||
unset( $GLOBALS['comment'] );
|
||||
|
||||
$linktext = rand_str( 10 );
|
||||
$before = rand_str( 5 );
|
||||
$after = rand_str( 6 );
|
||||
$comment = self::factory()->comment->create_and_get( array(
|
||||
'comment_author_email' => $email = 'baz@example.org'
|
||||
) );
|
||||
|
||||
$expected = sprintf( '%1$s<a href="mailto:%2$s">%3$s</a>%4$s', $before, $email, $linktext, $after );
|
||||
|
||||
$this->assertEquals( $expected, get_comment_author_email_link( $linktext, $before, $after, $comment ) );
|
||||
}
|
||||
|
||||
public function test_all_parameters_with_global_comment() {
|
||||
$linktext = rand_str( 10 );
|
||||
$before = rand_str( 5 );
|
||||
$after = rand_str( 6 );
|
||||
|
||||
$expected = sprintf( '%1$s<a href="mailto:foo@example.org">%2$s</a>%3$s', $before, $linktext, $after );
|
||||
|
||||
$this->assertEquals( $expected, get_comment_author_email_link( $linktext, $before, $after ) );
|
||||
}
|
||||
|
||||
public function test_linktext() {
|
||||
$expected = sprintf( '<a href="mailto:foo@example.org">%1$s</a>', $linktext = rand_str( 12 ) );
|
||||
|
||||
$this->assertEquals( $expected, get_comment_author_email_link( $linktext ) );
|
||||
}
|
||||
|
||||
public function test_before() {
|
||||
$expected = sprintf( '%1$s<a href="mailto:foo@example.org">foo@example.org</a>', $before = rand_str( 5 ) );
|
||||
|
||||
$this->assertEquals( $expected, get_comment_author_email_link( '', $before ) );
|
||||
}
|
||||
|
||||
public function test_after() {
|
||||
$expected = sprintf( '<a href="mailto:foo@example.org">foo@example.org</a>%1$s', $after = rand_str( 5 ) );
|
||||
|
||||
$this->assertEquals( $expected, get_comment_author_email_link( '', '', $after ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 36571
|
||||
*/
|
||||
public function test_comment_param_should_override_global() {
|
||||
$comment = self::factory()->comment->create_and_get( array(
|
||||
'comment_author_email' => $email = 'bar@example.org'
|
||||
) );
|
||||
|
||||
$expected = sprintf( '<a href="mailto:%1$s">%2$s</a>', $email, $email );
|
||||
|
||||
$this->assertEquals( $expected, get_comment_author_email_link( '', '', '', $comment ) );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user