@@ -377,7 +377,55 @@ public function test_is_theme_active() {
377377 * @covers Customize_Snapshot_Manager::should_import_and_preview_snapshot()
378378 */
379379 public function test_should_import_and_preview_snapshot () {
380- $ this ->markTestIncomplete ();
380+ global $ pagenow , $ wp_customize ;
381+ $ _REQUEST ['customize_snapshot_uuid ' ] = self ::UUID ;
382+ $ manager = $ this ->plugin ->customize_snapshot_manager ;
383+ $ post_id = $ manager ->post_type ->save ( array (
384+ 'uuid ' => self ::UUID ,
385+ 'data ' => array ( 'blogname ' => array ( 'value ' => 'Foo ' ) ),
386+ ) );
387+ $ snapshot = new Customize_Snapshot ( $ manager , self ::UUID );
388+
389+ // Not if admin.
390+ set_current_screen ( 'posts ' );
391+ $ pagenow = 'posts.php ' ; // WPCS: global override ok.
392+ $ this ->assertTrue ( is_admin () );
393+ $ this ->assertFalse ( $ manager ->should_import_and_preview_snapshot ( $ snapshot ) );
394+
395+ // Not if theme switch error.
396+ set_current_screen ( 'customize ' );
397+ $ pagenow = 'customize.php ' ; // WPCS: global override ok.
398+ update_post_meta ( $ post_id , '_snapshot_theme ' , 'Foo ' );
399+ $ this ->assertFalse ( $ manager ->should_import_and_preview_snapshot ( $ snapshot ) );
400+ delete_post_meta ( $ post_id , '_snapshot_theme ' );
401+
402+ // Not if customize_save.
403+ $ _REQUEST ['action ' ] = 'customize_save ' ;
404+ $ this ->assertFalse ( $ manager ->should_import_and_preview_snapshot ( $ snapshot ) );
405+ unset( $ _REQUEST ['action ' ] );
406+
407+ // Not if published snapshot.
408+ $ manager ->post_type ->save ( array (
409+ 'uuid ' => self ::UUID ,
410+ 'status ' => 'publish ' ,
411+ ) );
412+ $ this ->assertFalse ( $ manager ->should_import_and_preview_snapshot ( $ snapshot ) );
413+ $ manager ->post_type ->save ( array (
414+ 'uuid ' => self ::UUID ,
415+ 'status ' => 'draft ' ,
416+ ) );
417+
418+ // Not if unsanitized post values is not empty.
419+ $ manager ->customize_manager = new \WP_Customize_Manager ();
420+ $ wp_customize = $ manager ->customize_manager ; // WPCS: global override ok.
421+ $ wp_customize ->set_post_value ( 'name ' , 'value ' );
422+ $ this ->assertNotEmpty ( $ manager ->customize_manager ->unsanitized_post_values () );
423+ $ this ->assertFalse ( $ manager ->should_import_and_preview_snapshot ( $ snapshot ) );
424+
425+ // OK.
426+ $ manager ->customize_manager = new \WP_Customize_Manager ();
427+ $ wp_customize = $ manager ->customize_manager ; // WPCS: global override ok.
428+ $ this ->assertTrue ( $ manager ->should_import_and_preview_snapshot ( $ snapshot ) );
381429 }
382430
383431 /**
0 commit comments