- Replace hand-rolled ci.yml jobs with thin caller to reusable estate workflow
(peptiderepo/peptide-e2e/.github/workflows/ci.yml@main); tests: stubs; has_js: false.
workflow_call + permissions: contents: write added per estate standard so deploy.yml
can gate on it and phpcbf auto-commit step has required token scope.
- Convert 7 hand-rolled test-*.php scripts to PHPUnit TestCase classes:
PeptideCptTest <- test-peptide-cpt.php
VerificationScannerTest <- test-verification-scanner.php
VerificationSettingsTest <- test-verification-settings.php
Migration0004Test <- test-migration-0004.php
JsonldTest <- test-jsonld.php
JsonldWebpageTest <- test-jsonld-webpage.php
JsonldPeptidePieceTest <- test-jsonld-peptide-piece.php
All assertions preserved; old scripts remain in tests/unit/ but CI no longer
runs them (PHPUnit discovery matches *Test.php only).
- Rewrite tests/bootstrap.php: full WP stub library for PHPUnit (WP_Post, WP_Error,
all option/cron/CPT/taxonomy/permalink stubs); registers PR_Core_Autoloader.
- Add phpunit.xml.dist (bootstrap, unit suite, includes/ coverage).
- Add phpunit/phpunit ^9.6 + yoast/phpunit-polyfills ^2.0 to require-dev.
- Add composer test script (vendor/bin/phpunit --configuration phpunit.xml.dist).
- deploy.yml: add permissions: contents: write.
- Version bump 0.6.2 -> 0.7.0.
Agent-Session: claude-adopt-ci-20260616
113 lines
5.0 KiB
PHP
113 lines
5.0 KiB
PHP
<?php
|
|
/**
|
|
* Regression tests for v0.6.1: Yoast wpseo_schema_webpage_type array contract.
|
|
*
|
|
* Ported from tests/unit/test-jsonld-webpage.php.
|
|
*
|
|
* Root cause: v0.6.0 retype_to_medical_webpage() was strict-typed string, but
|
|
* Yoast passes ['WebPage'] (array) on every singular page.
|
|
* strict_types=1 → TypeError → HTTP 500 on all monographs + plain Pages.
|
|
*
|
|
* These tests fail against v0.6.0 and pass after the v0.6.1 fix.
|
|
*
|
|
* @package PeptideRepoCore\Tests
|
|
*/
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
/**
|
|
* Regression tests for PR_Core_Jsonld_Webpage v0.6.1 array-type contract.
|
|
*/
|
|
class JsonldWebpageTest extends TestCase {
|
|
|
|
protected function setUp(): void {
|
|
$GLOBALS['pr_test_postmeta'] = [];
|
|
$GLOBALS['pr_test_is_singular'] = false;
|
|
$GLOBALS['pr_test_singular_type'] = '';
|
|
$GLOBALS['pr_test_the_id'] = 0;
|
|
require_once PR_CORE_PLUGIN_DIR . 'includes/frontend/class-pr-core-jsonld-webpage.php';
|
|
}
|
|
|
|
// ── retype_to_medical_webpage: array input ────────────────────────
|
|
|
|
public function test_retype_non_peptide_singular_array_unchanged(): void {
|
|
$GLOBALS['pr_test_is_singular'] = true;
|
|
$GLOBALS['pr_test_singular_type'] = 'page';
|
|
$result = ( new PR_Core_Jsonld_Webpage() )->retype_to_medical_webpage( [ 'WebPage' ] );
|
|
$this->assertSame( [ 'WebPage' ], $result );
|
|
}
|
|
|
|
public function test_retype_peptide_singular_array_returns_medical_webpage_string(): void {
|
|
$GLOBALS['pr_test_is_singular'] = true;
|
|
$GLOBALS['pr_test_singular_type'] = 'peptide';
|
|
$result = ( new PR_Core_Jsonld_Webpage() )->retype_to_medical_webpage( [ 'WebPage' ] );
|
|
$this->assertSame( 'MedicalWebPage', $result );
|
|
}
|
|
|
|
public function test_retype_string_input_non_singular_passthrough(): void {
|
|
$GLOBALS['pr_test_is_singular'] = false;
|
|
$GLOBALS['pr_test_singular_type'] = '';
|
|
$result = ( new PR_Core_Jsonld_Webpage() )->retype_to_medical_webpage( 'CollectionPage' );
|
|
$this->assertSame( 'CollectionPage', $result );
|
|
}
|
|
|
|
// ── enrich_webpage_piece: @type as array injects enrichments ──────
|
|
|
|
public function test_enrich_webpage_piece_array_type_injects_last_reviewed(): void {
|
|
$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 = [ [ '@type' => [ 'WebPage' ], '@id' => 'https://peptiderepo.com/peptides/bpc-157/#webpage', 'name' => 'BPC-157' ] ];
|
|
$result_graph = ( new PR_Core_Jsonld_Webpage() )->enrich_webpage_piece( $graph, new stdClass() );
|
|
$piece = $result_graph[0] ?? [];
|
|
$this->assertArrayHasKey( 'lastReviewed', $piece );
|
|
$this->assertSame( '2026-06-01', $piece['lastReviewed'] );
|
|
}
|
|
|
|
public function test_enrich_webpage_piece_array_type_injects_reviewed_by(): void {
|
|
$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 = [ [ '@type' => [ 'WebPage' ], '@id' => 'https://peptiderepo.com/peptides/bpc-157/#webpage' ] ];
|
|
$result_graph = ( new PR_Core_Jsonld_Webpage() )->enrich_webpage_piece( $graph, new stdClass() );
|
|
$this->assertArrayHasKey( 'reviewedBy', $result_graph[0] ?? [] );
|
|
}
|
|
|
|
public function test_enrich_webpage_piece_array_type_injects_audience(): void {
|
|
$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 = [ [ '@type' => [ 'WebPage' ], '@id' => 'https://peptiderepo.com/peptides/bpc-157/#webpage' ] ];
|
|
$result_graph = ( new PR_Core_Jsonld_Webpage() )->enrich_webpage_piece( $graph, new stdClass() );
|
|
$this->assertArrayHasKey( 'audience', $result_graph[0] ?? [] );
|
|
}
|
|
|
|
public function test_enrich_webpage_piece_string_medical_webpage_also_enriches(): void {
|
|
$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 = [ [ '@type' => 'MedicalWebPage', '@id' => 'https://peptiderepo.com/peptides/bpc-157/#webpage' ] ];
|
|
$result_graph = ( new PR_Core_Jsonld_Webpage() )->enrich_webpage_piece( $graph, new stdClass() );
|
|
$this->assertArrayHasKey( 'lastReviewed', $result_graph[0] ?? [] );
|
|
}
|
|
|
|
public function test_enrich_webpage_piece_non_peptide_does_not_inject(): void {
|
|
$GLOBALS['pr_test_is_singular'] = true;
|
|
$GLOBALS['pr_test_singular_type'] = 'page';
|
|
$GLOBALS['pr_test_the_id'] = 50;
|
|
$GLOBALS['pr_test_postmeta'][50] = [];
|
|
|
|
$graph = [ [ '@type' => [ 'WebPage' ], '@id' => 'https://peptiderepo.com/about/#webpage' ] ];
|
|
$result_graph = ( new PR_Core_Jsonld_Webpage() )->enrich_webpage_piece( $graph, new stdClass() );
|
|
$this->assertArrayNotHasKey( 'lastReviewed', $result_graph[0] ?? [] );
|
|
}
|
|
}
|