retype_to_medical_webpage( [ 'WebPage' ] ); pr_assert_equals( [ 'WebPage' ], $result, 'non-peptide singular: array returned unchanged' ); // Peptide singular: Yoast passes ['WebPage']; must return 'MedicalWebPage' (string). $GLOBALS['pr_test_is_singular'] = true; $GLOBALS['pr_test_singular_type'] = 'peptide'; $result = $enricher->retype_to_medical_webpage( [ 'WebPage' ] ); pr_assert_equals( 'MedicalWebPage', $result, 'peptide singular: returns MedicalWebPage (string)' ); // String input still works (non-singular special types like CollectionPage). $GLOBALS['pr_test_is_singular'] = false; $GLOBALS['pr_test_singular_type'] = ''; $result = $enricher->retype_to_medical_webpage( 'CollectionPage' ); pr_assert_equals( 'CollectionPage', $result, 'non-singular string: passes through unchanged' ); // ── enrich_webpage_piece: @type as array injects enrichments ─────────────. echo "\nenrich_webpage_piece — @type as array:\n"; $GLOBALS['pr_test_is_singular'] = true; $GLOBALS['pr_test_singular_type'] = 'peptide'; $GLOBALS['pr_test_the_id'] = 42; $GLOBALS['pr_test_postmeta'][42] = [ '_pr_last_reviewed' => '2026-06-01', ]; // Graph piece with @type as an array (real Yoast shape on singulars). $graph = [ [ '@type' => [ 'WebPage' ], '@id' => 'https://peptiderepo.com/peptides/bpc-157/#webpage', 'name' => 'BPC-157', ], ]; $result_graph = $enricher->enrich_webpage_piece( $graph, new stdClass() ); $piece = $result_graph[0] ?? []; pr_assert( isset( $piece['lastReviewed'] ), '@type=array: lastReviewed injected' ); pr_assert_equals( '2026-06-01', $piece['lastReviewed'], '@type=array: lastReviewed value correct' ); pr_assert( isset( $piece['reviewedBy'] ), '@type=array: reviewedBy injected' ); pr_assert( isset( $piece['audience'] ), '@type=array: audience injected' ); // Also works when @type is 'MedicalWebPage' (string — after our retype fires first). $graph_retyed = [ [ '@type' => 'MedicalWebPage', '@id' => 'https://peptiderepo.com/peptides/bpc-157/#webpage', 'name' => 'BPC-157', ], ]; $result_retyped = $enricher->enrich_webpage_piece( $graph_retyed, new stdClass() ); pr_assert( isset( $result_retyped[0]['lastReviewed'] ), 'MedicalWebPage string @type: enrichment injects' ); // Non-peptide page: enrichment must NOT fire even with array @type. $GLOBALS['pr_test_is_singular'] = true; $GLOBALS['pr_test_singular_type'] = 'page'; $graph_non_peptide = [ [ '@type' => [ 'WebPage' ], '@id' => 'https://peptiderepo.com/about/#webpage', ], ]; $result_non_peptide = $enricher->enrich_webpage_piece( $graph_non_peptide, new stdClass() ); pr_assert( ! isset( $result_non_peptide[0]['lastReviewed'] ), 'non-peptide: lastReviewed NOT injected' ); // ── Summary ──────────────────────────────────────────────────────────────. exit( pr_test_summary() );