| 1 | <?php |
| 2 | /** |
| 3 | * @group comment |
| 4 | */ |
| 5 | class Tests_Comment_GetCommentAuthorEmailLink extends WP_UnitTestCase { |
| 6 | |
| 7 | public function setUp() { |
| 8 | parent::setUp(); |
| 9 | |
| 10 | // Set up the comment global. |
| 11 | $GLOBALS['comment'] = $comment = self::factory()->comment->create_and_get( array( |
| 12 | 'comment_author_email' => 'foo@example.org' |
| 13 | ) ); |
| 14 | |
| 15 | // Remove obfuscation for testing purposes. |
| 16 | remove_filter( 'comment_email', 'antispambot' ); |
| 17 | } |
| 18 | |
| 19 | /** |
| 20 | * @ticket 36571 |
| 21 | */ |
| 22 | public function test_global_comment_with_default_parameters() { |
| 23 | $expected = '<a href="mailto:foo@example.org">foo@example.org</a>'; |
| 24 | |
| 25 | $this->assertEquals( $expected, get_comment_author_email_link() ); |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * @ticket 36571 |
| 30 | */ |
| 31 | public function test_all_parameters() { |
| 32 | unset( $GLOBALS['comment'] ); |
| 33 | |
| 34 | $linktext = rand_str( 10 ); |
| 35 | $before = rand_str( 5 ); |
| 36 | $after = rand_str( 6 ); |
| 37 | $comment = self::factory()->comment->create_and_get( array( |
| 38 | 'comment_author_email' => $email = 'baz@example.org' |
| 39 | ) ); |
| 40 | |
| 41 | $expected = sprintf( '%1$s<a href="mailto:%2$s">%3$s</a>%4$s', $before, $email, $linktext, $after ); |
| 42 | |
| 43 | $this->assertEquals( $expected, get_comment_author_email_link( $linktext, $before, $after, $comment ) ); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * @ticket 36571 |
| 48 | */ |
| 49 | public function test_all_parameters_with_global_comment() { |
| 50 | $linktext = rand_str( 10 ); |
| 51 | $before = rand_str( 5 ); |
| 52 | $after = rand_str( 6 ); |
| 53 | |
| 54 | $expected = sprintf( '%1$s<a href="mailto:foo@example.org">%2$s</a>%3$s', $before, $linktext, $after ); |
| 55 | |
| 56 | $this->assertEquals( $expected, get_comment_author_email_link( $linktext, $before, $after ) ); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * @ticket 36571 |
| 61 | */ |
| 62 | public function test_linktext() { |
| 63 | $expected = sprintf( '<a href="mailto:foo@example.org">%1$s</a>', $linktext = rand_str( 12 ) ); |
| 64 | |
| 65 | $this->assertEquals( $expected, get_comment_author_email_link( $linktext ) ); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * @ticket 36571 |
| 70 | */ |
| 71 | public function test_before() { |
| 72 | $expected = sprintf( '%1$s<a href="mailto:foo@example.org">foo@example.org</a>', $before = rand_str( 5 ) ); |
| 73 | |
| 74 | $this->assertEquals( $expected, get_comment_author_email_link( '', $before ) ); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * @ticket 36571 |
| 79 | */ |
| 80 | public function test_after() { |
| 81 | $expected = sprintf( '<a href="mailto:foo@example.org">foo@example.org</a>%1$s', $after = rand_str( 5 ) ); |
| 82 | |
| 83 | $this->assertEquals( $expected, get_comment_author_email_link( '', '', $after ) ); |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * @ticket 36571 |
| 88 | */ |
| 89 | public function test_comment() { |
| 90 | unset( $GLOBALS['comment'] ); |
| 91 | |
| 92 | $comment = self::factory()->comment->create_and_get( array( |
| 93 | 'comment_author_email' => $email = 'bar@example.org' |
| 94 | ) ); |
| 95 | |
| 96 | $expected = sprintf( '<a href="mailto:%1$s">%2$s</a>', $email, $email ); |
| 97 | |
| 98 | $this->assertEquals( $expected, get_comment_author_email_link( '', '', '', $comment ) ); |
| 99 | } |
| 100 | } |