|
21 | 21 | $GLOBALS['ssi_plan_root'] = sys_get_temp_dir() . '/ssi-plan-' . bin2hex( random_bytes( 4 ) ); |
22 | 22 | $GLOBALS['ssi_plan_posts'] = array(); |
23 | 23 | $GLOBALS['ssi_plan_meta'] = array(); |
24 | | -$GLOBALS['ssi_plan_options'] = array( 'show_on_front' => 'posts', 'page_on_front' => 0, 'blogname' => 'Before' ); |
| 24 | +$GLOBALS['ssi_plan_options'] = array( 'show_on_front' => 'posts', 'page_on_front' => 0, 'blogname' => 'Before', 'use_smilies' => true ); |
25 | 25 | $GLOBALS['ssi_plan_fail_after'] = 0; |
26 | 26 | $GLOBALS['ssi_plan_font_requests'] = array(); |
27 | 27 | mkdir( $GLOBALS['ssi_plan_root'], 0777, true ); |
@@ -64,8 +64,9 @@ function wp_safe_remote_get( string $url, array $args ) { |
64 | 64 | } |
65 | 65 | function wp_remote_retrieve_response_code( $response ): int { return (int) ( $response['response']['code'] ?? 0 ); } |
66 | 66 | function wp_remote_retrieve_body( $response ): string { return (string) ( $response['body'] ?? '' ); } |
67 | | -function update_option( string $key, $value ): void { $GLOBALS['ssi_plan_options'][ $key ] = $value; } |
| 67 | +function update_option( string $key, $value ): bool { $GLOBALS['ssi_plan_options'][ $key ] = $value; return true; } |
68 | 68 | function switch_theme( string $slug ): void { $GLOBALS['ssi_plan_options']['stylesheet'] = $slug; } |
| 69 | +function convert_smilies( string $content, string $which = 'content' ): string { return ( $GLOBALS['ssi_plan_options']['use_smilies'] ?? true ) ? 'smilied-' . $which : $content; } |
69 | 70 | function sanitize_text_field( string $value ): string { return $value; } |
70 | 71 | function update_post_meta( int $id, string $key, string $value ): void { $GLOBALS['ssi_plan_meta'][ $id ][ $key ] = $value; } |
71 | 72 | function get_post_meta( int $id, string $key, bool $single = true ): string { return (string) ( $GLOBALS['ssi_plan_meta'][ $id ][ $key ] ?? '' ); } |
@@ -349,14 +350,37 @@ function wp_insert_post( array $post, bool $wp_error ) { |
349 | 350 | $assert( hash_file( 'sha256', $publication_file ) === ( $publication_report['actual_content_hash'] ?? '' ) && $publication_plan['runtime_declarations'][0]['expected_content_hash'] === ( $publication_report['expected_content_hash'] ?? '' ), 'publication receipt proves canonical and resolved content integrity' ); |
350 | 351 | $assert( str_contains( file_get_contents( $publication_file ), 'https://example.test/wp-content/themes/publication-plan/assets/assets/font.woff2' ), 'font-bearing SVG resolves only its declared local font URL' ); |
351 | 352 |
|
352 | | -$GLOBALS['ssi_plan_options'] = array( 'show_on_front' => 'posts', 'page_on_front' => 0, 'blogname' => 'Before' ); |
| 353 | +$GLOBALS['ssi_plan_options'] = array( 'show_on_front' => 'posts', 'page_on_front' => 0, 'blogname' => 'Before', 'use_smilies' => true ); |
353 | 354 | $preview = Static_Site_Importer_WordPress_Site_Plan_Materializer::materialize( $plan, array( 'slug' => 'site-plan', 'overwrite' => true ) ); |
354 | 355 | $assert( 'completed' === $preview['status'], 'preview materialization completes' ); |
355 | 356 | $assert( array( 'canonical_validations' => 1, 'plan_resolutions' => 1, 'destination_preflights' => 2, 'immutable_projection_reused' => true ) === ( $preview['preparation'] ?? array() ), 'materialization reuses one immutable projection while repeating destination preflight' ); |
356 | 357 | $assert( 'posts' === $GLOBALS['ssi_plan_options']['show_on_front'] && ! isset( $GLOBALS['ssi_plan_options']['stylesheet'] ), 'activate=false preserves runtime options' ); |
357 | 358 | $activated = Static_Site_Importer_WordPress_Site_Plan_Materializer::materialize( $plan, array( 'slug' => 'site-plan', 'overwrite' => true, 'activate' => true, 'site_title' => 'Activated Plan' ) ); |
358 | 359 | $assert( 'site-plan' === $GLOBALS['ssi_plan_options']['stylesheet'] && 'page' === $GLOBALS['ssi_plan_options']['show_on_front'] && 'Activated Plan' === $GLOBALS['ssi_plan_options']['blogname'], 'activate=true applies theme title and reading policy' ); |
359 | 360 |
|
| 361 | +// disable_smilies (issue #780): non-activating import must not touch the global option. |
| 362 | +$GLOBALS['ssi_plan_options'] = array( 'show_on_front' => 'posts', 'page_on_front' => 0, 'blogname' => 'Before', 'use_smilies' => true ); |
| 363 | +$receipt_default = Static_Site_Importer_WordPress_Site_Plan_Materializer::materialize( $plan, array( 'slug' => 'site-plan', 'overwrite' => true ) ); |
| 364 | +$assert( true === ( $receipt_default['completed']['runtime_policy']['disable_smilies']['requested'] ?? null ), 'disable-smilies-defaults-requested-true' ); |
| 365 | +$assert( false === ( $receipt_default['completed']['runtime_policy']['disable_smilies']['applied'] ?? null ), 'disable-smilies-not-applied-without-activate' ); |
| 366 | +$assert( true === $GLOBALS['ssi_plan_options']['use_smilies'], 'non-activating-import-preserves-use-smilies' ); |
| 367 | + |
| 368 | +// Explicit opt-out, non-activating: requested and applied both false. |
| 369 | +$receipt_off = Static_Site_Importer_WordPress_Site_Plan_Materializer::materialize( $plan, array( 'slug' => 'site-plan', 'overwrite' => true, 'disable_smilies' => false ) ); |
| 370 | +$assert( false === ( $receipt_off['completed']['runtime_policy']['disable_smilies']['requested'] ?? null ) && false === ( $receipt_off['completed']['runtime_policy']['disable_smilies']['applied'] ?? null ), 'disable-smilies-false-requested-and-applied-false' ); |
| 371 | + |
| 372 | +// Activating import with default policy flips the option so literal :) stays text. |
| 373 | +$activated_smilies = Static_Site_Importer_WordPress_Site_Plan_Materializer::materialize( $plan, array( 'slug' => 'site-plan', 'overwrite' => true, 'activate' => true, 'site_title' => 'Activated Plan' ) ); |
| 374 | +$assert( false === $GLOBALS['ssi_plan_options']['use_smilies'], 'activating-import-sets-use-smilies-false' ); |
| 375 | +$assert( 'Hello :)' === convert_smilies( 'Hello :)' ), 'convert-smilies-output-unchanged-when-disabled' ); |
| 376 | +$assert( true === ( $activated_smilies['completed']['runtime_policy']['disable_smilies']['requested'] ?? null ) && true === ( $activated_smilies['completed']['runtime_policy']['disable_smilies']['applied'] ?? null ), 'activating-import-records-requested-and-applied' ); |
| 377 | + |
| 378 | +// Explicit opt-out, activating: option untouched, policy not applied. |
| 379 | +$GLOBALS['ssi_plan_options'] = array( 'show_on_front' => 'posts', 'page_on_front' => 0, 'blogname' => 'Before', 'use_smilies' => true ); |
| 380 | +$activated_off = Static_Site_Importer_WordPress_Site_Plan_Materializer::materialize( $plan, array( 'slug' => 'site-plan', 'overwrite' => true, 'activate' => true, 'disable_smilies' => false, 'site_title' => 'Activated Off' ) ); |
| 381 | +$assert( true === $GLOBALS['ssi_plan_options']['use_smilies'], 'activate-with-disable-smilies-false-keeps-smilies' ); |
| 382 | +$assert( false === ( $activated_off['completed']['runtime_policy']['disable_smilies']['requested'] ?? null ) && false === ( $activated_off['completed']['runtime_policy']['disable_smilies']['applied'] ?? null ), 'disable-smilies-false-not-applied-on-activate' ); |
| 383 | + |
360 | 384 | $repeat = Static_Site_Importer_WordPress_Site_Plan_Materializer::materialize( $plan, array( 'slug' => 'site-plan' ) ); |
361 | 385 | $assert( 'completed' === $repeat['status'], 'reconciliation repeat completes' ); |
362 | 386 | $assert( count( $GLOBALS['ssi_plan_posts'] ) === count( $plan['pages'] ), 'reconciliation preserves source page identity' ); |
|
0 commit comments