0603537f0a
- TMDO_Post_Fields::post_type_for_group() / groups_for_post_type() derive HivePress-style groups from their registry post_type scope (core keeps its own attachment / wc_product / nav_menu_item map); the three copy-pasted switches and the query router's POST_TYPE_GROUP_MAP use them - Term/comment backfill, shadow verifier and CLI take their groups from the registry (TMDO_Term_Comment_Backfill::registered_groups()); installer drops the hp_* entries already covered by its table patterns; REST listings default post type is filterable (tmdo_rest_default_post_type, default 'post') - Verify: NoHpMappingsTest guard + mapping/default tests; core unit 640 / integration 449, HP 146/49, WC 10/22 OK - PR: PR-020e
65 lines
2.8 KiB
PHP
65 lines
2.8 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
/**
|
|
* Core routing code resolves group ↔ post_type / table from the registry.
|
|
*
|
|
* HivePress groups are registered by the HivePress AddOn with their post
|
|
* types; core must not hardcode their names. The HivePress-only legacy
|
|
* cutover tooling (wpdo_hot_hp_listing → hp_listing_core) and the stress
|
|
* testers are out of scope and not checked here.
|
|
*/
|
|
class NoHpMappingsTest extends TestCase {
|
|
|
|
private const FILES = array(
|
|
'includes/class-tmdo-post-shadow-verifier.php',
|
|
'includes/migration/class-tmdo-post-migration.php',
|
|
'includes/query/class-tmdo-post-query-router.php',
|
|
'includes/class-tmdo-term-comment-backfill.php',
|
|
'includes/class-tmdo-term-comment-shadow-verifier.php',
|
|
'cli/class-tmdo-cli-term-comment.php',
|
|
'includes/class-tmdo-installer.php',
|
|
'includes/class-tmdo-rest-api.php',
|
|
);
|
|
|
|
/** Stress-test tooling inside the REST API class keeps its sample post types. */
|
|
private const ALLOWED = array(
|
|
'includes/class-tmdo-rest-api.php' => array( "array( 'product', 'hp_listing', 'hp_request', 'hp_vendor', 'attachment', 'nav_menu_item', 'post' )" ),
|
|
);
|
|
|
|
public function test_routing_code_has_no_hivepress_names(): void {
|
|
$root = dirname( __DIR__, 2 );
|
|
$offences = array();
|
|
foreach ( self::FILES as $rel ) {
|
|
$code = '';
|
|
foreach ( token_get_all( (string) file_get_contents( $root . '/' . $rel ) ) as $token ) {
|
|
if ( is_array( $token ) && in_array( $token[0], array( T_COMMENT, T_DOC_COMMENT ), true ) ) {
|
|
continue;
|
|
}
|
|
$code .= is_array( $token ) ? $token[1] : $token;
|
|
}
|
|
$code = str_replace( self::ALLOWED[ $rel ] ?? array(), '', $code );
|
|
if ( preg_match_all( '/hp_(listing|request|vendor|taxonomy|review|user)\w*/', $code, $m ) ) {
|
|
$offences[] = $rel . ': ' . implode( ', ', array_unique( $m[0] ) );
|
|
}
|
|
}
|
|
|
|
$this->assertSame( array(), $offences, "Hardcoded HivePress names in core routing:\n" . implode( "\n", $offences ) );
|
|
}
|
|
|
|
public function test_term_comment_groups_come_from_the_registry(): void {
|
|
TMDO_Entity_Registry::init();
|
|
TMDO_Entity_Registry::register_adapter( 'term', $this->createMock( TMDO_Entity_Adapter_Interface::class ) );
|
|
TMDO_Entity_Registry::register_adapter( 'comment', $this->createMock( TMDO_Entity_Adapter_Interface::class ) );
|
|
TMDO_Entity_Registry::register_group( 'term', 'x_tax', array( array( 'key' => 'x_order', 'type' => 'integer' ) ) );
|
|
TMDO_Entity_Registry::register_group( 'comment', 'x_review', array( array( 'key' => 'x_rating', 'type' => 'integer' ) ) );
|
|
|
|
$this->assertSame( array( 'x_tax' => 'term', 'x_review' => 'comment' ), TMDO_Term_Comment_Backfill::registered_groups() );
|
|
|
|
$result = TMDO_Term_Comment_Backfill::backfill_group( 'term', 'hp_taxonomy', true );
|
|
$this->assertSame( 'Unknown group: hp_taxonomy', $result['error'] ?? '', 'unregistered groups are unknown' );
|
|
}
|
|
}
|