event id or prefix => reason */ public static function unsupported() { return array( 'webhook' => 'Webhook events are received over HTTP at the catch URL. WP-CLI does not POST a forged webhook (that would skip signature checks or invent a secret).', 'date_time' => 'Date/time triggers fire from the Workflow Automation engine tick (WP-Cron `pawa_engine_tick`), not from a single isolated scenario.', 'database' => 'Watched-table events require a real write to that table through WordPress/$wpdb. There is no generic safe simulator.', ); } /** * Find an adapter + scenario for a catalog event or scenario id. * * @param string $event_name Event or scenario id. * @return array{0:Pawa_Cli_Integration,1:string}|null */ public static function resolve( $event_name ) { if ( ! class_exists( 'Pawa_Cli_Registry' ) ) { return null; } $key = self::normalize( $event_name ); if ( '' === $key ) { return null; } foreach ( Pawa_Cli_Registry::instance()->all() as $item ) { foreach ( array_keys( $item->scenarios() ) as $sid ) { if ( self::normalize( $sid ) === $key ) { return array( $item, $sid ); } } // A form adapter (cli/form-integration.php, development checkout only). if ( method_exists( $item, 'event_prefix' ) ) { $prefix = self::normalize( $item->event_prefix() ); if ( $prefix && 0 === strpos( $key, $prefix ) ) { return array( $item, 'form_submitted' ); } } } return null; } /** * Reason this event cannot be simulated, or empty. * * @param string $event_name Event id. * @return string */ public static function unsupported_reason( $event_name ) { $key = self::normalize( $event_name ); if ( 0 === strpos( $key, 'webhook' ) ) { return self::unsupported()['webhook']; } if ( 'date_time' === $key ) { return self::unsupported()['date_time']; } if ( 0 === strpos( $key, 'cpt_' ) ) { return 'Custom post type events have no generic CLI scenario. Create a post of that type on a disposable site, or add an adapter.'; } return ''; } /** * @param string $id Id. * @return string */ public static function normalize( $id ) { $id = str_replace( '-', '_', (string) $id ); $id = function_exists( 'sanitize_title' ) ? sanitize_title( $id ) : strtolower( $id ); return str_replace( '-', '_', $id ); } /** * Run a harness test for one adapter/scenario and return structured results. * * @param Pawa_Cli_Integration $item Adapter. * @param string $scenario Scenario id. * @param array $assoc_args Assoc args (--keep, --format). * @return Pawa_Cli_Harness */ public static function run_adapter( $item, $scenario, $assoc_args ) { if ( ! class_exists( 'Pawa_Cli_Harness' ) ) { // The live-test harness ships only in a development checkout. WP_CLI::error( 'Live tests are not part of this package. Run them from a development checkout of Workflow Automation.' ); } return call_user_func( array( 'Pawa_Cli_Harness', 'run_adapter' ), $item, $scenario, $assoc_args ); } }