Skip to content

Commit 16f874b

Browse files
committed
Tests: Cover comment feed GUID generation.
Verify `get_comment_guid()` combines the post GUID with the comment anchor, accepts a comment object, and returns `false` for a nonexistent comment. Developed in: #15339 Props shailu25. See #65819. git-svn-id: https://develop.svn.wordpress.org/trunk@65199 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 426cf9c commit 16f874b

1 file changed

Lines changed: 73 additions & 0 deletions

File tree

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
/**
3+
* Tests for get_comment_guid().
4+
*
5+
* @group feed
6+
* @group comment
7+
*
8+
* @covers ::get_comment_guid
9+
*/
10+
class Tests_Feed_GetCommentGuid extends WP_UnitTestCase {
11+
12+
/**
13+
* Post ID.
14+
*
15+
* @var int
16+
*/
17+
private static $post_id;
18+
19+
/**
20+
* Comment ID.
21+
*
22+
* @var int
23+
*/
24+
private static $comment_id;
25+
26+
/**
27+
* Create shared fixtures.
28+
*
29+
* @param WP_UnitTest_Factory $factory Factory.
30+
*/
31+
public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
32+
self::$post_id = $factory->post->create(
33+
array(
34+
'guid' => 'https://example.org/?p=123',
35+
)
36+
);
37+
38+
self::$comment_id = $factory->comment->create(
39+
array(
40+
'comment_post_ID' => self::$post_id,
41+
)
42+
);
43+
}
44+
45+
/**
46+
* @ticket 65819
47+
*/
48+
public function test_returns_false_for_invalid_comment() {
49+
$this->assertFalse( get_comment_guid( PHP_INT_MAX ) );
50+
}
51+
52+
/**
53+
* @ticket 65819
54+
*/
55+
public function test_returns_post_guid_with_comment_anchor() {
56+
$this->assertSame(
57+
'https://example.org/?p=123#comment-' . self::$comment_id,
58+
get_comment_guid( self::$comment_id )
59+
);
60+
}
61+
62+
/**
63+
* @ticket 65819
64+
*/
65+
public function test_accepts_comment_object() {
66+
$comment = get_comment( self::$comment_id );
67+
68+
$this->assertSame(
69+
'https://example.org/?p=123#comment-' . self::$comment_id,
70+
get_comment_guid( $comment )
71+
);
72+
}
73+
}

0 commit comments

Comments
 (0)