From 6f418f1a5119c6e741f14212545961120e44dcf4 Mon Sep 17 00:00:00 2001 From: Diego Resendez Date: Sat, 15 Aug 2026 15:34:37 -0500 Subject: [PATCH] fix: fall back to placeholder art when a cover attachment is gone Co-Authored-By: Claude Opus 5 (1M context) --- blocks/project-detail/render.php | 11 +++--- blocks/project-list/render.php | 7 +++- blocks/release-detail/render.php | 17 +++++---- blocks/release-list/render.php | 7 +++- patterns/home-projects.php | 2 +- tests/e2e/music-podcast-stages.spec.mjs | 4 +- tests/e2e/visual-states.spec.mjs | 2 +- tests/php/PatternsTest.php | 4 +- tests/php/ProjectBlocksTest.php | 49 +++++++++++++++++++++++++ 9 files changed, 80 insertions(+), 23 deletions(-) diff --git a/blocks/project-detail/render.php b/blocks/project-detail/render.php index ebfc64b..ffa5c44 100644 --- a/blocks/project-detail/render.php +++ b/blocks/project-detail/render.php @@ -10,9 +10,10 @@ if ( ! $chrnx_term instanceof WP_Term || 'chrnx_project' !== $chrnx_term->taxono return; } -$chrnx_status = (string) get_term_meta( $chrnx_term->term_id, 'chrnx_project_status', true ); -$chrnx_cover = absint( get_term_meta( $chrnx_term->term_id, 'chrnx_project_cover', true ) ); -$chrnx_links = chrnx_get_project_links( $chrnx_term->term_id ); +$chrnx_status = (string) get_term_meta( $chrnx_term->term_id, 'chrnx_project_status', true ); +$chrnx_cover = absint( get_term_meta( $chrnx_term->term_id, 'chrnx_project_cover', true ) ); +$chrnx_links = chrnx_get_project_links( $chrnx_term->term_id ); +$chrnx_cover_markup = $chrnx_cover > 0 ? wp_get_attachment_image( $chrnx_cover, 'large', false, array( 'class' => 'chrnx-project-detail__cover' ) ) : ''; // Without status, description or links there is no second column to fill. $chrnx_has_intro = '' !== $chrnx_status || '' !== $chrnx_term->description || ! empty( $chrnx_links ); $chrnx_head_class = 'chrnx-project-detail__head' . ( $chrnx_has_intro ? '' : ' is-bare' ); @@ -20,8 +21,8 @@ $chrnx_head_class = 'chrnx-project-detail__head' . ( $chrnx_has_intro ? '' : ' i
'chrnx-project-detail' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
- 0 ) : ?> - 'chrnx-project-detail__cover' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> + + diff --git a/blocks/project-list/render.php b/blocks/project-list/render.php index 19709b7..40c8699 100644 --- a/blocks/project-list/render.php +++ b/blocks/project-list/render.php @@ -29,8 +29,11 @@ if ( is_wp_error( $chrnx_terms ) || empty( $chrnx_terms ) ) { - 0 ) : ?> - 'chrnx-project-card__cover' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> + 0 ? wp_get_attachment_image( $chrnx_cover, 'chrnx-card', false, array( 'class' => 'chrnx-project-card__cover' ) ) : ''; + ?> + + diff --git a/blocks/release-detail/render.php b/blocks/release-detail/render.php index d3f60e7..98e19c4 100644 --- a/blocks/release-detail/render.php +++ b/blocks/release-detail/render.php @@ -10,12 +10,13 @@ if ( ! $chrnx_term instanceof WP_Term || 'chrnx_release' !== $chrnx_term->taxono return; } -$chrnx_heading = chrnx_get_heading_level( $attributes['headingLevel'] ?? 2, 2 ); -$chrnx_status = (string) get_term_meta( $chrnx_term->term_id, 'chrnx_release_status', true ); -$chrnx_cover = absint( get_term_meta( $chrnx_term->term_id, 'chrnx_release_cover', true ) ); -$chrnx_links = chrnx_get_release_links( $chrnx_term->term_id ); -$chrnx_tracks = chrnx_get_release_track_ids( $chrnx_term->slug ); -$chrnx_track_h = min( 6, $chrnx_heading + 1 ); +$chrnx_heading = chrnx_get_heading_level( $attributes['headingLevel'] ?? 2, 2 ); +$chrnx_status = (string) get_term_meta( $chrnx_term->term_id, 'chrnx_release_status', true ); +$chrnx_cover = absint( get_term_meta( $chrnx_term->term_id, 'chrnx_release_cover', true ) ); +$chrnx_links = chrnx_get_release_links( $chrnx_term->term_id ); +$chrnx_cover_markup = $chrnx_cover > 0 ? wp_get_attachment_image( $chrnx_cover, 'large', false, array( 'class' => 'chrnx-release-detail__cover' ) ) : ''; +$chrnx_tracks = chrnx_get_release_track_ids( $chrnx_term->slug ); +$chrnx_track_h = min( 6, $chrnx_heading + 1 ); // Without status, description or links there is no second column to fill. $chrnx_has_intro = '' !== $chrnx_status || '' !== $chrnx_term->description || ! empty( $chrnx_links ); $chrnx_head_class = 'chrnx-release-detail__head' . ( $chrnx_has_intro ? '' : ' is-bare' ); @@ -23,8 +24,8 @@ $chrnx_head_class = 'chrnx-release-detail__head' . ( $chrnx_has_intro ? '' : ' i
'chrnx-release-detail' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
- 0 ) : ?> - 'chrnx-release-detail__cover' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> + + diff --git a/blocks/release-list/render.php b/blocks/release-list/render.php index cc9f9d9..0349737 100644 --- a/blocks/release-list/render.php +++ b/blocks/release-list/render.php @@ -29,8 +29,11 @@ if ( is_wp_error( $chrnx_terms ) || empty( $chrnx_terms ) ) { - 0 ) : ?> - 'chrnx-release-card__cover' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> + 0 ? wp_get_attachment_image( $chrnx_cover, 'chrnx-card', false, array( 'class' => 'chrnx-release-card__cover' ) ) : ''; + ?> + + diff --git a/patterns/home-projects.php b/patterns/home-projects.php index 16884b6..60be292 100644 --- a/patterns/home-projects.php +++ b/patterns/home-projects.php @@ -16,7 +16,7 @@
-

+

diff --git a/tests/e2e/music-podcast-stages.spec.mjs b/tests/e2e/music-podcast-stages.spec.mjs index 3b816ed..5d605b1 100644 --- a/tests/e2e/music-podcast-stages.spec.mjs +++ b/tests/e2e/music-podcast-stages.spec.mjs @@ -559,9 +559,9 @@ const immutableSurfaces = [ ], // Project names come from the project list query: picked projects newest-first, // then the most recent ones. This is the seeded order, not a frozen string. - headings: [ 'Selected work', 'Ailed', 'Expressive Tea', 'Published research' ], + headings: [ 'Proyectos', 'Ailed', 'Expressive Tea', 'Published research' ], paragraphs: [], - contentText: 'Selected work Ailed Expressive Tea Published research', + contentText: 'Proyectos Ailed Expressive Tea Published research', }, { name: 'About', diff --git a/tests/e2e/visual-states.spec.mjs b/tests/e2e/visual-states.spec.mjs index 2f33df4..a8ed135 100644 --- a/tests/e2e/visual-states.spec.mjs +++ b/tests/e2e/visual-states.spec.mjs @@ -193,7 +193,7 @@ test( 'home remains coherent at all approved review viewports', async ( { page } await expect( page.locator( 'main#chrnx-main' ) ).toBeVisible(); await expect( page.getByRole( 'contentinfo' ) ).toBeVisible(); await expect( page.getByRole( 'heading', { level: 1 } ) ).toHaveCount( 1 ); - await expect( page.getByText( 'Selected work', { exact: true } ) ).toBeVisible(); + await expect( page.getByText( 'Proyectos', { exact: true } ) ).toBeVisible(); await expect( page.getByText( 'The No Names', { exact: true } ).first() ).toBeVisible(); await expect( page.locator( 'picture source[type="image/avif"]' ).first() ).toHaveAttribute( 'srcset', diff --git a/tests/php/PatternsTest.php b/tests/php/PatternsTest.php index bcdc15f..db63f89 100644 --- a/tests/php/PatternsTest.php +++ b/tests/php/PatternsTest.php @@ -205,9 +205,9 @@ class PatternsTest extends WP_UnitTestCase { public function test_character_led_patterns_use_the_exact_shared_stage_api() { $contracts = array( 'home-projects' => array( - 'heading' => 'Selected work', + 'heading' => 'Proyectos', // The project names come from the project list query now, not the pattern. - 'order' => array( 'Selected work' ), + 'order' => array( 'Proyectos' ), 'art' => 'alter-ego-code-768.webp', 'art_alt' => '', 'atmosphere' => 'chrnx-character-stage__secondary-art', diff --git a/tests/php/ProjectBlocksTest.php b/tests/php/ProjectBlocksTest.php index 4df8510..8a995d3 100644 --- a/tests/php/ProjectBlocksTest.php +++ b/tests/php/ProjectBlocksTest.php @@ -107,6 +107,55 @@ class ProjectBlocksTest extends WP_UnitTestCase { $this->assertSame( '', trim( do_blocks( '' ) ) ); } + /** + * Ensure a list card falls back to placeholder art when the stored cover + * attachment no longer exists, instead of rendering a blank art column. + */ + public function test_project_list_with_deleted_cover_uses_placeholder_art() { + $term_id = self::factory()->term->create( + array( + 'taxonomy' => 'chrnx_project', + 'slug' => 'deleted-cover-list-test', + ) + ); + update_term_meta( $term_id, 'chrnx_project_cover', 999999 ); + + $markup = do_blocks( '' ); + + // Scope the assertion to this term's own card: the taxonomy query is + // unfiltered, so other projects' cards must not mask a broken one. + $needle = 'chrnx_project=deleted-cover-list-test'; + $link_offset = strpos( $markup, $needle ); + $this->assertNotFalse( $link_offset, 'Expected a card linking to the test project.' ); + $card_start = strrpos( substr( $markup, 0, $link_offset ), '', $link_offset ); + $card = substr( $markup, $card_start, $card_end - $card_start ); + + $this->assertStringContainsString( 'chrnx-project-card__fallback', $card ); + $this->assertStringNotContainsString( 'chrnx-project-card__cover', $card ); + } + + /** + * Ensure the detail block falls back to placeholder art when the stored + * cover attachment no longer exists, instead of rendering a blank art column. + */ + public function test_project_detail_with_deleted_cover_uses_placeholder_art() { + $term_id = self::factory()->term->create( + array( + 'taxonomy' => 'chrnx_project', + 'slug' => 'deleted-cover-detail-test', + ) + ); + update_term_meta( $term_id, 'chrnx_project_cover', 999999 ); + + $this->go_to( get_term_link( $term_id ) ); + + $markup = do_blocks( '' ); + + $this->assertStringContainsString( 'chrnx-project-detail__fallback', $markup ); + $this->assertStringNotContainsString( 'chrnx-project-detail__cover', $markup ); + } + /** * Ensure a project archive filters the journal to that project. */