From d7cdd76939fb58baf17d2aebb9a1a693710871ab Mon Sep 17 00:00:00 2001 From: Renato Alves <19148962+renatonascalves@users.noreply.github.com> Date: Thu, 16 Nov 2023 10:53:56 -0300 Subject: [PATCH 1/5] Adding tests for the `get_the_author_display_name` functionality --- tests/feature/test-core-filters.php | 39 +++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tests/feature/test-core-filters.php b/tests/feature/test-core-filters.php index 5640bc25..013a237e 100644 --- a/tests/feature/test-core-filters.php +++ b/tests/feature/test-core-filters.php @@ -240,4 +240,43 @@ public function test_author_link() { get_author_posts_url( $post->post_author ) ); } + + public function test_get_author_display_name_from_global_post(): void { + $author_name = 'Dumas Davy de la Pailleterie'; + + $user = static::factory()->user->create_and_get( + [ 'display_name' => $author_name ] + ); + + remove_filter( 'get_the_author_display_name', 'Byline_Manager\auto_integrate_byline', 10, 2 ); + + $display_name = get_the_author_meta( 'display_name', $user->ID ); + + add_filter( 'get_the_author_display_name', 'Byline_Manager\auto_integrate_byline', 10, 2 ); + + $this->assertSame( $author_name, $display_name ); + $this->assertNotSame( 'Byline 1', $display_name ); + $this->assertNotSame( 'Byline 2', $display_name ); + $this->assertNotSame( 'Byline 1 and Byline 2', $display_name ); + } + + public function test_get_author_display_name_from_user(): void { + $author_name = 'Dumas Davy de la Pailleterie'; + $user = static::factory()->user->create_and_get( + [ + 'display_name' => $author_name, + 'first_name' => 'Dumas', + 'last_name' => 'Davy de la Pailleterie', + ] + ); + + static::factory()->post->create_and_get( + [ 'post_author' => $user->ID ] + ); + + $display_name = get_the_author_meta( 'display_name', $user->ID ); + + $this->assertNotSame( '', $display_name ); + $this->assertSame( $display_name, $display_name ); + } } From cb7a45115613c36280e85a9301fc99626ecb0bf4 Mon Sep 17 00:00:00 2001 From: Renato Alves <19148962+renatonascalves@users.noreply.github.com> Date: Thu, 16 Nov 2023 10:56:14 -0300 Subject: [PATCH 2/5] Minor tweaks --- tests/feature/test-core-filters.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/tests/feature/test-core-filters.php b/tests/feature/test-core-filters.php index 013a237e..9b89e3eb 100644 --- a/tests/feature/test-core-filters.php +++ b/tests/feature/test-core-filters.php @@ -243,14 +243,13 @@ public function test_author_link() { public function test_get_author_display_name_from_global_post(): void { $author_name = 'Dumas Davy de la Pailleterie'; - - $user = static::factory()->user->create_and_get( + $user = static::factory()->user->create_and_get( [ 'display_name' => $author_name ] ); remove_filter( 'get_the_author_display_name', 'Byline_Manager\auto_integrate_byline', 10, 2 ); - $display_name = get_the_author_meta( 'display_name', $user->ID ); + $display_name = get_the_author_meta( 'display_name', $user->ID ); add_filter( 'get_the_author_display_name', 'Byline_Manager\auto_integrate_byline', 10, 2 ); @@ -270,13 +269,11 @@ public function test_get_author_display_name_from_user(): void { ] ); - static::factory()->post->create_and_get( - [ 'post_author' => $user->ID ] - ); + static::factory()->post->create_and_get( [ 'post_author' => $user->ID ] ); $display_name = get_the_author_meta( 'display_name', $user->ID ); $this->assertNotSame( '', $display_name ); - $this->assertSame( $display_name, $display_name ); + $this->assertSame( $author_name, $display_name ); } } From ed9908d063c5c20f7e8bf40f00525eaef5893574 Mon Sep 17 00:00:00 2001 From: Renato Alves <19148962+renatonascalves@users.noreply.github.com> Date: Thu, 16 Nov 2023 14:33:43 -0300 Subject: [PATCH 3/5] Revert "Auto integrate into filter used by Post Author Name block" This reverts commit bc0352137afda774fe47cc52149b89b867677c86. --- inc/core-filters.php | 1 - 1 file changed, 1 deletion(-) diff --git a/inc/core-filters.php b/inc/core-filters.php index d9cd723e..75bb31e0 100644 --- a/inc/core-filters.php +++ b/inc/core-filters.php @@ -30,7 +30,6 @@ function auto_integrate_byline( $author_name ): string { return get_the_byline(); } add_filter( 'the_author', __NAMESPACE__ . '\auto_integrate_byline' ); -add_filter( 'get_the_author_display_name', __NAMESPACE__ . '\auto_integrate_byline' ); /** * Automatically integrate the byline into the `the_author_posts_link` filter. From 0e276468ec1803ca0c26643dd97a533302c77c28 Mon Sep 17 00:00:00 2001 From: Renato Alves <19148962+renatonascalves@users.noreply.github.com> Date: Thu, 16 Nov 2023 14:35:20 -0300 Subject: [PATCH 4/5] Adjusting unit test --- tests/feature/test-core-filters.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/feature/test-core-filters.php b/tests/feature/test-core-filters.php index 9b89e3eb..f2f11f63 100644 --- a/tests/feature/test-core-filters.php +++ b/tests/feature/test-core-filters.php @@ -247,12 +247,8 @@ public function test_get_author_display_name_from_global_post(): void { [ 'display_name' => $author_name ] ); - remove_filter( 'get_the_author_display_name', 'Byline_Manager\auto_integrate_byline', 10, 2 ); - $display_name = get_the_author_meta( 'display_name', $user->ID ); - add_filter( 'get_the_author_display_name', 'Byline_Manager\auto_integrate_byline', 10, 2 ); - $this->assertSame( $author_name, $display_name ); $this->assertNotSame( 'Byline 1', $display_name ); $this->assertNotSame( 'Byline 2', $display_name ); From 6bd4cd530e49bd204de301e9b929716bc83d03f1 Mon Sep 17 00:00:00 2001 From: Renato Alves <19148962+renatonascalves@users.noreply.github.com> Date: Thu, 16 Nov 2023 14:37:54 -0300 Subject: [PATCH 5/5] Remove outdated duplicate test --- tests/feature/test-core-filters.php | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/tests/feature/test-core-filters.php b/tests/feature/test-core-filters.php index f2f11f63..680c7cd2 100644 --- a/tests/feature/test-core-filters.php +++ b/tests/feature/test-core-filters.php @@ -241,20 +241,6 @@ public function test_author_link() { ); } - public function test_get_author_display_name_from_global_post(): void { - $author_name = 'Dumas Davy de la Pailleterie'; - $user = static::factory()->user->create_and_get( - [ 'display_name' => $author_name ] - ); - - $display_name = get_the_author_meta( 'display_name', $user->ID ); - - $this->assertSame( $author_name, $display_name ); - $this->assertNotSame( 'Byline 1', $display_name ); - $this->assertNotSame( 'Byline 2', $display_name ); - $this->assertNotSame( 'Byline 1 and Byline 2', $display_name ); - } - public function test_get_author_display_name_from_user(): void { $author_name = 'Dumas Davy de la Pailleterie'; $user = static::factory()->user->create_and_get(