wordpress-develop/tests/phpunit/tests/comment/getCommentAuthorUrlLink.php
Scott Taylor 02319efa71 Unit Tests:
* Automatically delete objects that we were created during `wpSetUpBeforeClass` - posts, comments, terms (except 1), and user (except 1)
* The amount of leftover data between tests was breathtaking - use the new function: `_delete_all_data()`
* Commit database transactions for all `TestCase`s, not just those that implement `wpSetUpBeforeClass` and `wpTearDownAfterClass`
* The tests run 10-20 seconds faster now

See #37699.


git-svn-id: https://develop.svn.wordpress.org/trunk@38398 602fd350-edb4-49c9-b593-d223f7449a82
2016-08-27 08:35:16 +00:00

81 lines
2.5 KiB
PHP

<?php
/**
* @group comment
*/
class Tests_Comment_GetCommentAuthorUrlLink extends WP_UnitTestCase {
protected static $comments = array();
public static function wpSetUpBeforeClass( $factory ) {
unset( $GLOBALS['comment'] );
$comment_ids = $factory->comment->create_post_comments( 0, 1 );
self::$comments = array_map( 'get_comment', $comment_ids );
}
protected function parseCommentAuthorUrl( $comment, $linktext = '' ) {
if ( empty( $linktext ) ) {
$linktext = rtrim( preg_replace( '#http://(www\.)?#', '', $comment->comment_author_url ), '/' );
}
return sprintf(
'<a href=\'%s\' rel=\'external\'>%s</a>',
$comment->comment_author_url,
$linktext
);
}
public function test_no_comment() {
$url_link = get_comment_author_url_link();
$this->assertEquals( "<a href='' rel='external'></a>", $url_link );
}
public function test_global_comment() {
$GLOBALS['comment'] = $comment = reset( self::$comments );
$url_link = get_comment_author_url_link();
$link = $this->parseCommentAuthorUrl( $comment );
$this->assertEquals( $link, $url_link );
}
public function test_comment_arg() {
$comment = reset( self::$comments );
$url_link = get_comment_author_url_link( '', '', '', $comment );
$link = $this->parseCommentAuthorUrl( $comment );
$this->assertEquals( $link, $url_link );
}
public function test_linktext() {
$comment = reset( self::$comments );
$url_link = get_comment_author_url_link( 'Burrito', '', '', $comment );
$link = $this->parseCommentAuthorUrl( $comment, 'Burrito' );
$this->assertEquals( $link, $url_link );
}
public function test_before() {
$comment = reset( self::$comments );
$url_link = get_comment_author_url_link( 'Burrito', 'I would love a ', '', $comment );
$link = 'I would love a ' . $this->parseCommentAuthorUrl( $comment, 'Burrito' );
$this->assertEquals( $link, $url_link );
}
public function test_after() {
$comment = reset( self::$comments );
$url_link = get_comment_author_url_link( 'Burrito', '', ' is my favorite word.', $comment );
$link = $this->parseCommentAuthorUrl( $comment, 'Burrito' ) . ' is my favorite word.';
$this->assertEquals( $link, $url_link );
}
public function test_before_after() {
$comment = reset( self::$comments );
$url_link = get_comment_author_url_link( 'Burrito', 'I would love a ', ' right now.', $comment );
$link = 'I would love a ' . $this->parseCommentAuthorUrl( $comment, 'Burrito' ) . ' right now.';
$this->assertEquals( $link, $url_link );
}
}