@@ -660,6 +660,14 @@ static function (): bool {
660660
661661Static_Site_Importer_Theme_Generator::$ last_artifact = array ();
662662Static_Site_Importer_Theme_Generator::$ last_args = array ();
663+ add_filter (
664+ 'static_site_importer_playground_package ' ,
665+ static fn () => array (
666+ 'url ' => 'https://github.com/Automattic/static-site-importer/releases/download/v1.2.3/static-site-importer.zip ' ,
667+ 'version ' => 'v1.2.3 ' ,
668+ 'sha256 ' => str_repeat ( 'a ' , 64 ),
669+ )
670+ );
663671$ playground_response = static_site_importer_rest_create_import (
664672 new WP_REST_Request (
665673 array (
@@ -681,8 +689,14 @@ static function (): bool {
681689$ playground_blueprint = json_decode ( $ playground_blueprint_json , true );
682690$ assert ( is_array ( $ playground_blueprint ), 'rest-playground-open-blueprint-decodes ' );
683691$ playground_blueprint_code = wp_json_encode ( $ playground_blueprint );
684- $ playground_plugin_step = $ playground_blueprint ['steps ' ][1 ] ?? array ();
685- $ assert ( 'https://github.com/Automattic/static-site-importer/releases/latest/download/static-site-importer.zip ' === ( $ playground_plugin_step ['pluginData ' ]['url ' ] ?? '' ), 'rest-playground-open-blueprint-installs-release-zip ' );
692+ $ playground_download_steps = array_values ( array_filter ( $ playground_blueprint ['steps ' ] ?? array (), static fn ( array $ step ): bool => 'writeFile ' === ( $ step ['step ' ] ?? '' ) ) );
693+ $ playground_plugin_steps = array_values ( array_filter ( $ playground_blueprint ['steps ' ] ?? array (), static fn ( array $ step ): bool => 'installPlugin ' === ( $ step ['step ' ] ?? '' ) ) );
694+ $ playground_download_step = $ playground_download_steps [0 ] ?? array ();
695+ $ playground_plugin_step = $ playground_plugin_steps [0 ] ?? array ();
696+ $ assert ( 'https://github.com/Automattic/static-site-importer/releases/download/v1.2.3/static-site-importer.zip ' === ( $ playground_download_step ['data ' ]['url ' ] ?? '' ), 'rest-playground-open-blueprint-downloads-pinned-release-zip ' );
697+ $ assert ( 'vfs ' === ( $ playground_plugin_step ['pluginData ' ]['resource ' ] ?? '' ), 'rest-playground-open-blueprint-installs-verified-vfs-package ' );
698+ $ assert ( ( $ playground_download_step ['path ' ] ?? null ) === ( $ playground_plugin_step ['pluginData ' ]['path ' ] ?? null ), 'rest-playground-open-blueprint-installs-downloaded-package ' );
699+ $ assert ( str_contains ( (string ) $ playground_blueprint_code , str_repeat ( 'a ' , 64 ) ), 'rest-playground-open-blueprint-verifies-package-digest ' );
686700$ assert ( str_contains ( (string ) $ playground_blueprint_code , 'static_site_importer_ability_import ' ), 'rest-playground-open-blueprint-runs-import-ability ' );
687701$ assert ( str_contains ( (string ) $ playground_blueprint_code , "'activate' => true " ), 'rest-playground-open-blueprint-activates-generated-site ' );
688702$ assert ( str_contains ( (string ) $ playground_blueprint_code , "'overwrite' => true " ), 'rest-playground-open-blueprint-overwrites-generated-site ' );
@@ -748,7 +762,8 @@ static function ( mixed $output, array $request ): mixed {
748762$ assert ( 'playground-provider-arg ' === ( $ GLOBALS ['ssi_last_url_provider_request ' ]['provider_args ' ]['token ' ] ?? '' ), 'rest-playground-url-only-preserves-provider-args ' );
749763$ url_playground_blueprint_json = rawurldecode ( substr ( (string ) ( $ url_playground_response ['preview ' ]['playground ' ]['blueprint_url ' ] ?? '' ), strlen ( 'https://playground.wordpress.net/# ' ) ) );
750764$ url_playground_blueprint = json_decode ( $ url_playground_blueprint_json , true );
751- $ url_playground_import_code = is_array ( $ url_playground_blueprint ) ? (string ) ( $ url_playground_blueprint ['steps ' ][2 ]['code ' ] ?? '' ) : '' ;
765+ $ url_playground_import_steps = is_array ( $ url_playground_blueprint ) ? array_values ( array_filter ( $ url_playground_blueprint ['steps ' ] ?? array (), static fn ( array $ step ): bool => 'runPHP ' === ( $ step ['step ' ] ?? '' ) && str_contains ( (string ) ( $ step ['code ' ] ?? '' ), 'static_site_importer_ability_import ' ) ) ) : array ();
766+ $ url_playground_import_code = (string ) ( $ url_playground_import_steps [0 ]['code ' ] ?? '' );
752767$ assert ( str_contains ( $ url_playground_blueprint_json , 'Facebook Fixture ' ), 'rest-playground-url-only-blueprint-contains-fetched-artifact ' );
753768$ assert ( str_contains ( $ url_playground_import_code , "'source_url' => 'https://facebook.com' " ), 'rest-playground-url-only-blueprint-preserves-source-url ' );
754769$ assert ( str_contains ( $ url_playground_import_code , "'provider_token' => 'playground-provider-arg' " ), 'rest-playground-url-only-blueprint-preserves-provider-arg-metadata ' );
@@ -1005,9 +1020,14 @@ static function ( mixed $output, array $request ): mixed {
10051020$ assert ( str_contains ( $ blueprint_code , '"openInPlayground":true ' ), 'playground-blueprint-targets-open-in-playground ' );
10061021$ assert ( ! str_contains ( $ blueprint_code , 'generateInCurrentRuntime ' ), 'playground-blueprint-does-not-reference-current-runtime-generation ' );
10071022$ assert ( str_contains ( $ blueprint_code , 'static_site_importer_protected_pages ' ), 'playground-blueprint-protects-import-page ' );
1008- $ plugin_steps = array_values ( array_filter ( $ blueprint ['steps ' ] ?? array (), static fn ( array $ step ): bool => 'installPlugin ' === ( $ step ['step ' ] ?? '' ) ) );
1009- $ plugin_step = $ plugin_steps [0 ] ?? array ();
1010- $ assert ( 'https://github.com/Automattic/static-site-importer/releases/download/{{RELEASE_TAG}}/static-site-importer.zip ' === ( $ plugin_step ['pluginData ' ]['url ' ] ?? '' ), 'playground-blueprint-installs-same-release-package ' );
1023+ $ download_steps = array_values ( array_filter ( $ blueprint ['steps ' ] ?? array (), static fn ( array $ step ): bool => 'writeFile ' === ( $ step ['step ' ] ?? '' ) ) );
1024+ $ plugin_steps = array_values ( array_filter ( $ blueprint ['steps ' ] ?? array (), static fn ( array $ step ): bool => 'installPlugin ' === ( $ step ['step ' ] ?? '' ) ) );
1025+ $ download_step = $ download_steps [0 ] ?? array ();
1026+ $ plugin_step = $ plugin_steps [0 ] ?? array ();
1027+ $ assert ( 'https://github.com/Automattic/static-site-importer/releases/download/{{RELEASE_TAG}}/static-site-importer.zip ' === ( $ download_step ['data ' ]['url ' ] ?? '' ), 'playground-blueprint-downloads-same-release-package ' );
1028+ $ assert ( 'vfs ' === ( $ plugin_step ['pluginData ' ]['resource ' ] ?? '' ), 'playground-blueprint-installs-verified-vfs-package ' );
1029+ $ assert ( ( $ download_step ['path ' ] ?? null ) === ( $ plugin_step ['pluginData ' ]['path ' ] ?? null ), 'playground-blueprint-installs-downloaded-package ' );
1030+ $ assert ( str_contains ( $ blueprint_code , '{{PACKAGE_SHA256}} ' ), 'playground-blueprint-verifies-release-package ' );
10111031
10121032$ GLOBALS ['ssi_test_options ' ]['static_site_importer_protected_pages ' ] = array ( 'import ' , 'tools/settings ' , '42 ' );
10131033$ assert ( Static_Site_Importer_Page_Materializer::is_protected_page ( new WP_Post ( 7 , 'import ' ) ), 'protected-page-matches-slug ' );
0 commit comments