Skip to content

Commit d5602a9

Browse files
committed
Add test cases
1 parent 29d53ad commit d5602a9

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/wp-includes/author-template.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ function the_author( $deprecated = '', $deprecated_echo = true ) {
8989
* @since 6.9.0 Added the `$post` parameter. Unknown return value is now explicitly null instead of void.
9090
*
9191
* @param int|WP_Post|null $post Optional. Post ID or post object. Default is global `$post` object.
92-
* @return string|null The author's display name, or null if unknown.
92+
* @return string|null The author's display name. Empty string if unknown, or null if no valid post.
9393
*/
9494
function get_the_modified_author( $post = null ) {
9595
$post = get_post( $post );

tests/phpunit/tests/user/getTheModifiedAuthor.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,36 @@ public function test_get_the_modified_author_when_post_global_does_not_exist() {
6464
$GLOBALS['post'] = null;
6565
$this->assertNull( get_the_modified_author() );
6666
}
67+
68+
/**
69+
* @ticket 64104
70+
*/
71+
public function test_get_the_modified_author_when_invalid_post() {
72+
$this->assertNull( get_the_modified_author( -1 ) );
73+
}
74+
75+
/**
76+
* @ticket 64104
77+
*/
78+
public function test_get_the_modified_author_for_another_post() {
79+
$expected_display_name = 'Test Editor';
80+
81+
$editor_id = self::factory()->user->create(
82+
array(
83+
'role' => 'editor',
84+
'user_login' => 'test_editor',
85+
'display_name' => $expected_display_name,
86+
'description' => 'test_editor',
87+
)
88+
);
89+
90+
$another_post_id = self::factory()->post->create();
91+
92+
$this->assertSame( '', get_the_modified_author( $another_post_id ) );
93+
$this->assertSame( '', get_the_modified_author( get_post( $another_post_id ) ) );
94+
95+
add_post_meta( $another_post_id, '_edit_last', $editor_id );
96+
$this->assertSame( $expected_display_name, get_the_modified_author( $another_post_id ) );
97+
$this->assertSame( $expected_display_name, get_the_modified_author( get_post( $another_post_id ) ) );
98+
}
6799
}

0 commit comments

Comments
 (0)