title. Ids should match catalog event ids when they are * static (wc_new_order). Dynamic form ids use a logical name (form_submitted). * * @return array */ abstract public function scenarios(); /** * Run one scenario, or every scenario when $scenario is empty. * * Unavailable plugins must skip, not fail. * * @param Pawa_Cli_Harness $harness Shared harness. * @param string $scenario Scenario id or catalog event id, or ''. */ abstract public function run( $harness, $scenario = '' ); /** * Run under this adapter's own scope (see Pawa_Cli_Harness::$scope). * Every caller outside the adapter goes through here, not run(). * * @param Pawa_Cli_Harness $harness Shared harness. * @param string $scenario Scenario id or catalog event id, or ''. */ public function run_scoped( $harness, $scenario = '' ) { $previous = $harness->scope; $harness->scope = (string) $this->id(); try { $this->run( $harness, $scenario ); } finally { $harness->scope = $previous; } } /** * core | third_party * * @return string */ public function kind() { return 'third_party'; } /** * Extra CLI slugs that resolve to this adapter. * * @return string[] */ public function aliases() { return array(); } /** * Optional seed for `wp pawa test seed`. Default: nothing. * * @param Pawa_Cli_Harness $harness Harness. */ public function seed( $harness ) { unset( $harness ); } /** * @return bool */ public function is_installed() { if ( ! defined( 'WP_PLUGIN_DIR' ) ) { return $this->is_active(); } foreach ( $this->plugin_files() as $file ) { if ( $file && file_exists( WP_PLUGIN_DIR . '/' . $file ) ) { return true; } } return $this->is_active(); } /** * @return array{installed:bool,active:bool,message:string} */ public function availability() { $active = $this->is_active(); $installed = $this->is_installed(); if ( $active ) { return array( 'installed' => true, 'active' => true, 'message' => '', ); } if ( $installed ) { return array( 'installed' => true, 'active' => false, 'message' => $this->title() . ' is installed but inactive.', ); } return array( 'installed' => false, 'active' => false, 'message' => $this->title() . ' is not installed.', ); } /** * Skip the whole adapter when the vendor plugin is missing/inactive. * * @param Pawa_Cli_Harness $harness Harness. * @return bool True when the caller should return (skipped). */ protected function skip_if_unavailable( $harness ) { $avail = $this->availability(); if ( $avail['active'] ) { return false; } $harness->skip( $this->title(), $avail['message'] ); return true; } /** * @param string $wanted Requested scenario. * @return string[] Scenario ids to run. */ protected function wanted_scenarios( $wanted ) { $all = array_keys( $this->scenarios() ); $wanted = str_replace( '-', '_', (string) $wanted ); if ( '' === $wanted ) { return $all; } foreach ( $all as $id ) { if ( str_replace( '-', '_', (string) $id ) === $wanted ) { return array( $id ); } } return array( $wanted ); } }