Files
2meet-data-optimizer/tests/unit/EntityHealthBackfillTest.php
T
wpdev 90877b81e0 fix(2meet-data-optimizer): entity health sees a running backfill
- Backfill batches are scheduled with (entity, group) args; the health
  panel looked for (entity) alone, never saw one and kept offering to start
  a backfill, which resets the group's checkpoint
- is_backfill_active() checks every group of the entity
- Unit bootstrap: wp_next_scheduled() stub honours hook + args
- Verify: EntityHealthBackfillTest (2 new); unit 711, phpcs 0, stan OK
- PR: PR-137 (manual F-11)
2026-09-28 18:18:56 +08:00

45 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
use PHPUnit\Framework\TestCase;
/**
* Backfill batches are scheduled per (entity, group) — REST backfill and
* TMDO_Core re-chain `wpdo_entity_backfill_batch` with both args. The health
* panel looked for (entity) alone, never found a running backfill and kept
* offering to start one; starting one resets the group's checkpoint
* (2.4.2 PR-137, manual F-11).
*/
class EntityHealthBackfillTest extends TestCase {
protected function setUp(): void {
$GLOBALS['_wp_next_scheduled'] = array();
TMDO_Entity_Registry::init();
TMDO_Entity_Registry::register_adapter( 'user', new TMDO_Adapter_User() );
TMDO_Entity_Registry::register_group( 'user', 'eh_one', array( array( 'key' => 'eh_a', 'type' => 'text' ) ) );
TMDO_Entity_Registry::register_group( 'user', 'eh_two', array( array( 'key' => 'eh_b', 'type' => 'text' ) ) );
}
protected function tearDown(): void {
$GLOBALS['_wp_next_scheduled'] = array();
TMDO_Entity_Registry::init();
}
private function backfill_active( string $entity_type ): bool {
$m = new ReflectionMethod( TMDO_Entity_Health::class, 'is_backfill_active' );
$m->setAccessible( true );
return (bool) $m->invoke( null, $entity_type );
}
public function test_a_backfill_scheduled_for_one_group_is_seen(): void {
$GLOBALS['_wp_next_scheduled']['wpdo_entity_backfill_batch'][ md5( serialize( array( 'user', 'eh_two' ) ) ) ] = time() + 5;
$this->assertTrue( $this->backfill_active( 'user' ) );
$this->assertFalse( $this->backfill_active( 'post' ), 'other entities are not affected' );
}
public function test_no_scheduled_batch_means_no_backfill(): void {
$this->assertFalse( $this->backfill_active( 'user' ) );
}
}