post->create( array( 'post_title' => 'Unrelated sticky' ) ); $featured = array( self::factory()->post->create( array( 'post_title' => 'Fixture one' ) ), self::factory()->post->create( array( 'post_title' => 'Fixture two' ) ), self::factory()->post->create( array( 'post_title' => 'Fixture three' ) ), ); $subscribe = self::factory()->post->create( array( 'post_type' => 'page', 'post_status' => 'private', 'post_title' => 'Existing fixture Subscribe', ) ); update_post_meta( $subscribe, '_chrnx_fixture_key', 'page-subscribe' ); foreach ( $featured as $index => $post_id ) { update_post_meta( $post_id, '_chrnx_fixture_key', 'post-fixture-' . $index ); } update_option( 'sticky_posts', array( $unrelated ) ); update_option( 'blogname', 'Outer title' ); update_option( 'blogdescription', 'Outer description' ); update_option( 'show_on_front', 'posts' ); update_option( 'page_on_front', 0 ); delete_option( 'page_for_posts' ); update_option( 'permalink_structure', '' ); update_option( 'chrnx_subscribe_page_id', 987654 ); $before = array(); foreach ( chrnx_fixture_environment_option_names() as $name ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- Exact persisted option bytes are the contract. $before[ $name ] = $wpdb->get_var( $wpdb->prepare( "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s", $name ) ); } $this->assertTrue( chrnx_fixture_environment_snapshot() ); $this->assertFalse( chrnx_fixture_environment_snapshot(), 'A scenario must not replace the outer snapshot.' ); chrnx_fixture_environment_apply( array( 'featured_ids' => $featured, 'featured_count' => 1, 'subscribe_id' => $subscribe, 'subscribe_status' => 'draft', 'subscribe_available' => false, ) ); $this->assertSame( array( $unrelated, $featured[0] ), array_map( 'absint', get_option( 'sticky_posts' ) ) ); $this->assertSame( 'draft', get_post_status( $subscribe ) ); $this->assertSame( 0, absint( get_option( 'chrnx_subscribe_page_id' ) ) ); $this->assertTrue( chrnx_fixture_environment_restore() ); $this->assertSame( 'private', get_post_status( $subscribe ) ); $this->assertFalse( get_option( '_chrnx_fixture_environment_snapshot_v1', false ) ); foreach ( $before as $name => $raw ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- Exact persisted option bytes are the contract. $after = $wpdb->get_var( $wpdb->prepare( "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s", $name ) ); $this->assertSame( $raw, $after, $name ); } } }