|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Smoke test that DMC bundle artifact hooks register at plugin load time. |
| 4 | + * |
| 5 | + * Run: php tests/smoke-bundle-artifact-early-registration.php |
| 6 | + * |
| 7 | + * @package DataMachineCode\Tests |
| 8 | + */ |
| 9 | + |
| 10 | +declare( strict_types=1 ); |
| 11 | + |
| 12 | +if ( ! defined( 'WPINC' ) ) { |
| 13 | + define( 'WPINC', 'wp-includes' ); |
| 14 | +} |
| 15 | +if ( ! defined( 'ABSPATH' ) ) { |
| 16 | + define( 'ABSPATH', __DIR__ . '/' ); |
| 17 | +} |
| 18 | + |
| 19 | +$filters = array(); |
| 20 | +$actions = array(); |
| 21 | + |
| 22 | +function plugin_dir_path( string $file ): string { |
| 23 | + return dirname( $file ) . '/'; |
| 24 | +} |
| 25 | + |
| 26 | +function plugin_dir_url( string $file ): string { |
| 27 | + return 'https://example.test/wp-content/plugins/' . basename( dirname( $file ) ) . '/'; |
| 28 | +} |
| 29 | + |
| 30 | +function register_activation_hook( string $file, callable|string $callback ): void { |
| 31 | + unset( $file, $callback ); |
| 32 | +} |
| 33 | + |
| 34 | +function add_action( string $hook, callable|string|array $callback, int $priority = 10, int $accepted_args = 1 ): void { |
| 35 | + global $actions; |
| 36 | + $actions[ $hook ][ $priority ][] = array( $callback, $accepted_args ); |
| 37 | +} |
| 38 | + |
| 39 | +function add_filter( string $hook, callable|string|array $callback, int $priority = 10, int $accepted_args = 1 ): void { |
| 40 | + global $filters; |
| 41 | + $filters[ $hook ][ $priority ][] = array( $callback, $accepted_args ); |
| 42 | +} |
| 43 | + |
| 44 | +function apply_filters( string $hook, mixed $value, mixed ...$args ): mixed { |
| 45 | + global $filters; |
| 46 | + if ( empty( $filters[ $hook ] ) ) { |
| 47 | + return $value; |
| 48 | + } |
| 49 | + |
| 50 | + ksort( $filters[ $hook ] ); |
| 51 | + foreach ( $filters[ $hook ] as $callbacks ) { |
| 52 | + foreach ( $callbacks as $callback ) { |
| 53 | + $value = call_user_func_array( $callback[0], array_slice( array_merge( array( $value ), $args ), 0, (int) $callback[1] ) ); |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + return $value; |
| 58 | +} |
| 59 | + |
| 60 | +require __DIR__ . '/../data-machine-code.php'; |
| 61 | + |
| 62 | +$types = apply_filters( 'datamachine_agent_bundle_artifact_types', array( 'agent' ) ); |
| 63 | +$ok = in_array( 'datamachine-code/workspace_preload', $types, true ); |
| 64 | + |
| 65 | +echo 'Bundle artifact early registration - smoke' . PHP_EOL; |
| 66 | +echo ( $ok ? ' ok registers workspace preload artifact before bootstrap' : ' fail registers workspace preload artifact before bootstrap' ) . PHP_EOL; |
| 67 | +echo PHP_EOL . 'Result: ' . ( $ok ? '1/1 passed' : '0/1 passed' ) . PHP_EOL; |
| 68 | + |
| 69 | +exit( $ok ? 0 : 1 ); |
0 commit comments