f15473527c
- doctor: entity flat tables come from the registry (TMDO_CLI::check_entity_tables()) instead of a hard-coded user list naming the never-registered sso group, which failed doctor on every site; it also reports Promotion Guard violations and the recorded drift status per entity (report_guard_and_drift()). - term-comment-diagnose: filter status comes from each filter's is_enabled() (the garbage filter and misc bucket default to off but were shown enabled); a filter whose add-on is not active shows "not installed". - bridge-status: flat_rows counts rows holding a value (wp_core keeps an all-NULL row per post: 15306% on dev36) and eav_ids of a post-type group counts only its post types. - Tests: the WP_CLI stubs record their output in $GLOBALS['_wp_cli_output']. - Verify: DoctorTest, CliFilterStatusTest, CliBridgeStatusTest (RED before); dev36 doctor exit 1 → 0, wp_core 15306% → 100%. - PR: PR-076
82 lines
3.8 KiB
PHP
82 lines
3.8 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
/**
|
|
* `wp tmdo bridge-status` progress (2.2 PR-076): eav_ids of a post group that
|
|
* belongs to some post types counted every post holding one of its keys, so a
|
|
* fully backfilled group showed less than 100%.
|
|
*
|
|
* flat_rows counted rows without any value too (wp_core holds an all-NULL row
|
|
* for every post): dev36 showed wp_core at 15306%.
|
|
*
|
|
* Fixture: group bs_grp for hp_listing only; bs_price on post 1 (hp_listing)
|
|
* and post 2 (a plain post); flat rows for post 1 (a value) and post 3
|
|
* (hp_listing, all NULL).
|
|
*/
|
|
class CliBridgeStatusTest extends TestCase {
|
|
|
|
private const POSTS = 'wp_itest_posts';
|
|
private const POSTMETA = 'wp_itest_postmeta';
|
|
private const FLAT = 'wp_itest_wpdo_post_bs_grp';
|
|
|
|
public static function setUpBeforeClass(): void {
|
|
foreach ( array(
|
|
'includes/adapters/interface-entity-adapter.php',
|
|
'includes/adapters/class-tmdo-adapter-post.php',
|
|
'cli/class-tmdo-cli-v2.php',
|
|
) as $file ) {
|
|
require_once WPDO_PLUGIN_DIR . $file;
|
|
}
|
|
if ( ! function_exists( 'WP_CLI\Utils\format_items' ) ) {
|
|
eval( 'namespace WP_CLI\Utils; function format_items( $format, $items, $fields ) { $GLOBALS["_wp_cli_items"] = $items; }' ); // phpcs:ignore Squiz.PHP.Eval -- test-only WP-CLI stub.
|
|
}
|
|
}
|
|
|
|
protected function setUp(): void {
|
|
global $wpdb;
|
|
self::drop();
|
|
$wpdb->query( 'CREATE TABLE `' . self::POSTS . "` ( ID BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, post_type VARCHAR(20) NOT NULL DEFAULT 'post', PRIMARY KEY (ID) ) ENGINE=InnoDB" );
|
|
$wpdb->query( 'CREATE TABLE `' . self::POSTMETA . '` ( meta_id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, post_id BIGINT UNSIGNED NOT NULL DEFAULT 0, meta_key VARCHAR(255) DEFAULT NULL, meta_value LONGTEXT, PRIMARY KEY (meta_id) ) ENGINE=InnoDB' );
|
|
$wpdb->query( 'CREATE TABLE `' . self::FLAT . '` ( id BIGINT NOT NULL AUTO_INCREMENT, post_id BIGINT NOT NULL, bs_price DECIMAL(18,6) DEFAULT NULL, PRIMARY KEY (id), UNIQUE KEY uk_entity (post_id) ) ENGINE=InnoDB' );
|
|
$wpdb->insert( self::POSTS, array( 'ID' => 1, 'post_type' => 'hp_listing' ) );
|
|
$wpdb->insert( self::POSTS, array( 'ID' => 2, 'post_type' => 'post' ) );
|
|
$wpdb->insert( self::POSTMETA, array( 'post_id' => 1, 'meta_key' => 'bs_price', 'meta_value' => '10' ) );
|
|
$wpdb->insert( self::POSTMETA, array( 'post_id' => 2, 'meta_key' => 'bs_price', 'meta_value' => '20' ) );
|
|
$wpdb->insert( self::FLAT, array( 'post_id' => 1, 'bs_price' => 10 ) );
|
|
$wpdb->insert( self::POSTS, array( 'ID' => 3, 'post_type' => 'hp_listing' ) );
|
|
$wpdb->insert( self::FLAT, array( 'post_id' => 3 ) );
|
|
|
|
$GLOBALS['_wp_options'] = array( 'wpdo_bridge_modes' => array( 'post' => 'dual_write' ) );
|
|
$GLOBALS['_wp_cli_items'] = array();
|
|
$GLOBALS['_wp_cli_output'] = array();
|
|
TMDO_Mode_Manager::reset_cache();
|
|
WPDO_Entity_Registry::init();
|
|
WPDO_Entity_Registry::register_adapter( 'post', new WPDO_Adapter_Post() );
|
|
WPDO_Entity_Registry::register_group( 'post', 'bs_grp', array( array( 'key' => 'bs_price', 'type' => 'decimal' ) ), array( 'post_types' => array( 'hp_listing' ) ) );
|
|
}
|
|
|
|
protected function tearDown(): void {
|
|
self::drop();
|
|
WPDO_Entity_Registry::init();
|
|
TMDO_Mode_Manager::reset_cache();
|
|
}
|
|
|
|
private static function drop(): void {
|
|
global $wpdb;
|
|
foreach ( array( self::POSTS, self::POSTMETA, self::FLAT ) as $table ) {
|
|
$wpdb->query( "DROP TABLE IF EXISTS `{$table}`" );
|
|
}
|
|
}
|
|
|
|
public function test_counts_only_flat_rows_that_hold_a_value_and_posts_of_the_groups_types(): void {
|
|
( new TMDO_CLI_V2() )->bridge_status( array(), array() );
|
|
|
|
$row = array_values( array_filter( $GLOBALS['_wp_cli_items'], static fn( $r ) => 'bs_grp' === $r['group'] ) )[0];
|
|
$this->assertSame( 1, $row['flat_rows'] );
|
|
$this->assertSame( 1, $row['eav_ids'] );
|
|
$this->assertSame( '100%', $row['progress_%'] );
|
|
}
|
|
}
|