Skip to content
This repository was archived by the owner on Dec 27, 2022. It is now read-only.

Commit 3e5ce8a

Browse files
committed
Merge branch 'feature/schedule-ui-customizer' of github.com:xwp/wp-customize-snapshots into feature/schedule-ui-customizer
2 parents 85e590c + 4ea308b commit 3e5ce8a

3 files changed

+98
-49
lines changed

tests/php/test-class-customize-snapshot-manager.php

+90-41
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ function test_construct_with_customize_bootstrapped() {
190190
/**
191191
* Tests init hooks.
192192
*
193-
* @covers Customize_Snapshot_Manager::init()
193+
* @covers CustomizeSnapshots\Customize_Snapshot_Manager::init()
194194
*/
195195
public function test_init_hooks() {
196196
$manager = new Customize_Snapshot_Manager( $this->plugin );
@@ -219,8 +219,8 @@ public function test_init_hooks() {
219219
/**
220220
* Tests init hooks.
221221
*
222-
* @covers Customize_Snapshot_Manager::init()
223-
* @covers Customize_Snapshot_Manager::read_current_snapshot_uuid()
222+
* @covers CustomizeSnapshots\Customize_Snapshot_Manager::init()
223+
* @covers CustomizeSnapshots\Customize_Snapshot_Manager::read_current_snapshot_uuid()
224224
*/
225225
public function test_read_current_snapshot_uuid() {
226226
$manager = new Customize_Snapshot_Manager( $this->plugin );
@@ -244,8 +244,8 @@ public function test_read_current_snapshot_uuid() {
244244
/**
245245
* Tests load_snapshot.
246246
*
247-
* @covers Customize_Snapshot_Manager::init()
248-
* @covers Customize_Snapshot_Manager::load_snapshot()
247+
* @covers CustomizeSnapshots\Customize_Snapshot_Manager::init()
248+
* @covers CustomizeSnapshots\Customize_Snapshot_Manager::load_snapshot()
249249
*/
250250
public function test_load_snapshot() {
251251
global $wp_actions;
@@ -272,8 +272,8 @@ public function test_load_snapshot() {
272272
/**
273273
* Tests setup_preview_ajax_requests.
274274
*
275-
* @covers Customize_Snapshot_Manager::init()
276-
* @covers Customize_Snapshot_Manager::setup_preview_ajax_requests()
275+
* @covers CustomizeSnapshots\Customize_Snapshot_Manager::init()
276+
* @covers CustomizeSnapshots\Customize_Snapshot_Manager::setup_preview_ajax_requests()
277277
*/
278278
public function test_setup_preview_ajax_requests() {
279279
wp_set_current_user( $this->user_id );
@@ -293,7 +293,7 @@ public function test_setup_preview_ajax_requests() {
293293
/**
294294
* Tests override_request_method.
295295
*
296-
* @covers Customize_Snapshot_Manager::override_request_method()
296+
* @covers CustomizeSnapshots\Customize_Snapshot_Manager::override_request_method()
297297
*/
298298
public function test_override_request_method() {
299299
global $wp;
@@ -328,7 +328,7 @@ public function test_override_request_method() {
328328
/**
329329
* Tests doing_customize_save_ajax.
330330
*
331-
* @covers Customize_Snapshot_Manager::doing_customize_save_ajax()
331+
* @covers CustomizeSnapshots\Customize_Snapshot_Manager::doing_customize_save_ajax()
332332
*/
333333
public function test_doing_customize_save_ajax() {
334334
$manager = new Customize_Snapshot_Manager( $this->plugin );
@@ -344,7 +344,7 @@ public function test_doing_customize_save_ajax() {
344344
/**
345345
* Tests ensure_customize_manager.
346346
*
347-
* @covers Customize_Snapshot_Manager::ensure_customize_manager()
347+
* @covers CustomizeSnapshots\Customize_Snapshot_Manager::ensure_customize_manager()
348348
*/
349349
public function test_ensure_customize_manager() {
350350
global $wp_customize;
@@ -359,7 +359,7 @@ public function test_ensure_customize_manager() {
359359
/**
360360
* Tests is_theme_active.
361361
*
362-
* @covers Customize_Snapshot_Manager::is_theme_active()
362+
* @covers CustomizeSnapshots\Customize_Snapshot_Manager::is_theme_active()
363363
*/
364364
public function test_is_theme_active() {
365365
global $wp_customize;
@@ -374,7 +374,7 @@ public function test_is_theme_active() {
374374
/**
375375
* Tests should_import_and_preview_snapshot.
376376
*
377-
* @covers Customize_Snapshot_Manager::should_import_and_preview_snapshot()
377+
* @covers CustomizeSnapshots\Customize_Snapshot_Manager::should_import_and_preview_snapshot()
378378
*/
379379
public function test_should_import_and_preview_snapshot() {
380380
global $pagenow, $wp_customize;
@@ -431,7 +431,7 @@ public function test_should_import_and_preview_snapshot() {
431431
/**
432432
* Tests is_previewing_settings.
433433
*
434-
* @covers Customize_Snapshot_Manager::is_previewing_settings()
434+
* @covers CustomizeSnapshots\Customize_Snapshot_Manager::is_previewing_settings()
435435
*/
436436
public function test_is_previewing_settings() {
437437
$_REQUEST['customize_snapshot_uuid'] = self::UUID;
@@ -448,7 +448,7 @@ public function test_is_previewing_settings() {
448448
/**
449449
* Tests is_previewing_settings.
450450
*
451-
* @covers Customize_Snapshot_Manager::is_previewing_settings()
451+
* @covers CustomizeSnapshots\Customize_Snapshot_Manager::is_previewing_settings()
452452
*/
453453
public function test_is_previewing_settings_via_preview_init() {
454454
$manager = new Customize_Snapshot_Manager( $this->plugin );
@@ -460,25 +460,74 @@ public function test_is_previewing_settings_via_preview_init() {
460460
/**
461461
* Tests preview_snapshot_settings.
462462
*
463-
* @covers Customize_Snapshot_Manager::preview_snapshot_settings()
463+
* @covers CustomizeSnapshots\Customize_Snapshot_Manager::preview_snapshot_settings()
464464
*/
465465
public function test_preview_snapshot_settings() {
466-
$this->markTestIncomplete();
466+
global $wp_actions;
467+
$_REQUEST['customize_snapshot_uuid'] = self::UUID;
468+
$this->manager->post_type->save( array(
469+
'uuid' => self::UUID,
470+
'data' => array(
471+
'blogname' => array( 'value' => 'Hello' ),
472+
),
473+
'status' => 'draft',
474+
) );
475+
476+
// Prevent init from calling preview_snapshot_settings straight away.
477+
unset( $wp_actions['wp_loaded'] );
478+
479+
$manager = new Customize_Snapshot_Manager( $this->plugin );
480+
$manager->init();
481+
$manager->ensure_customize_manager();
482+
do_action( 'customize_register', $manager->customize_manager );
483+
$this->assertFalse( $manager->is_previewing_settings() );
484+
$this->assertFalse( $manager->customize_manager->get_setting( 'blogname' )->dirty );
485+
$this->assertNotEquals( 'Hello', get_option( 'blogname' ) );
486+
$manager->preview_snapshot_settings();
487+
$this->assertEquals( 'Hello', get_option( 'blogname' ) );
488+
$this->assertTrue( $manager->customize_manager->get_setting( 'blogname' )->dirty );
467489
}
468490

469491
/**
470492
* Tests import_snapshot_data.
471493
*
472-
* @covers Customize_Snapshot_Manager::import_snapshot_data()
494+
* @covers CustomizeSnapshots\Customize_Snapshot_Manager::import_snapshot_data()
473495
*/
474496
public function test_import_snapshot_data() {
475-
$this->markTestIncomplete();
497+
global $wp_actions;
498+
$_REQUEST['customize_snapshot_uuid'] = self::UUID;
499+
$this->manager->post_type->save( array(
500+
'uuid' => self::UUID,
501+
'data' => array(
502+
'blogname' => array( 'value' => 'Hello' ),
503+
'blogdescription' => array( 'value' => null ),
504+
),
505+
'status' => 'draft',
506+
) );
507+
508+
// Prevent init from calling import_snapshot_data straight away.
509+
unset( $wp_actions['setup_theme'] );
510+
511+
$manager = new Customize_Snapshot_Manager( $this->plugin );
512+
$manager->init();
513+
$manager->ensure_customize_manager();
514+
do_action( 'customize_register', $manager->customize_manager );
515+
516+
$this->assertArrayNotHasKey( 'customized', $_POST );
517+
$this->assertArrayNotHasKey( 'customized', $_REQUEST );
518+
$this->assertArrayNotHasKey( 'blogname', $manager->customize_manager->unsanitized_post_values() );
519+
$this->assertArrayNotHasKey( 'blogdescription', $manager->customize_manager->unsanitized_post_values() );
520+
$manager->import_snapshot_data();
521+
$this->assertArrayHasKey( 'customized', $_POST );
522+
$this->assertArrayHasKey( 'customized', $_REQUEST );
523+
$this->assertArrayHasKey( 'blogname', $manager->customize_manager->unsanitized_post_values() );
524+
$this->assertArrayNotHasKey( 'blogdescription', $manager->customize_manager->unsanitized_post_values() );
476525
}
477526

478527
/**
479528
* Tests add_widget_setting_preview_filters.
480529
*
481-
* @covers Customize_Snapshot_Manager::add_widget_setting_preview_filters()
530+
* @covers CustomizeSnapshots\Customize_Snapshot_Manager::add_widget_setting_preview_filters()
482531
*/
483532
public function test_add_widget_setting_preview_filters() {
484533
$this->markTestIncomplete();
@@ -487,7 +536,7 @@ public function test_add_widget_setting_preview_filters() {
487536
/**
488537
* Tests add_nav_menu_setting_preview_filters.
489538
*
490-
* @covers Customize_Snapshot_Manager::add_nav_menu_setting_preview_filters()
539+
* @covers CustomizeSnapshots\Customize_Snapshot_Manager::add_nav_menu_setting_preview_filters()
491540
*/
492541
public function test_add_nav_menu_setting_preview_filters() {
493542
$this->markTestIncomplete();
@@ -496,7 +545,7 @@ public function test_add_nav_menu_setting_preview_filters() {
496545
/**
497546
* Tests preview_early_nav_menus_in_customizer.
498547
*
499-
* @covers Customize_Snapshot_Manager::preview_early_nav_menus_in_customizer()
548+
* @covers CustomizeSnapshots\Customize_Snapshot_Manager::preview_early_nav_menus_in_customizer()
500549
*/
501550
public function test_preview_early_nav_menus_in_customizer() {
502551
$this->markTestIncomplete();
@@ -523,7 +572,7 @@ public function test_add_snapshot_uuid_to_return_url() {
523572
/**
524573
* Tests show_theme_switch_error.
525574
*
526-
* @covers Customize_Snapshot_Manager::show_theme_switch_error()
575+
* @covers CustomizeSnapshots\Customize_Snapshot_Manager::show_theme_switch_error()
527576
*/
528577
function test_show_theme_switch_error() {
529578
$this->markTestIncomplete();
@@ -532,7 +581,7 @@ function test_show_theme_switch_error() {
532581
/**
533582
* Tests get_theme_switch_error.
534583
*
535-
* @covers Customize_Snapshot_Manager::get_theme_switch_error()
584+
* @covers CustomizeSnapshots\Customize_Snapshot_Manager::get_theme_switch_error()
536585
*/
537586
function test_get_theme_switch_error() {
538587
$this->markTestIncomplete();
@@ -541,7 +590,7 @@ function test_get_theme_switch_error() {
541590
/**
542591
* Tests check_customize_publish_authorization.
543592
*
544-
* @covers Customize_Snapshot_Manager::check_customize_publish_authorization()
593+
* @covers CustomizeSnapshots\Customize_Snapshot_Manager::check_customize_publish_authorization()
545594
*/
546595
function test_check_customize_publish_authorization() {
547596
$this->markTestIncomplete();
@@ -600,7 +649,7 @@ function test_enqueue_frontend_scripts() {
600649
/**
601650
* Test filter_customize_refresh_nonces.
602651
*
603-
* @covers Customize_Snapshot_Manager::filter_customize_refresh_nonces()
652+
* @covers CustomizeSnapshots\Customize_Snapshot_Manager::filter_customize_refresh_nonces()
604653
*/
605654
function test_filter_customize_refresh_nonces() {
606655
$this->markTestIncomplete();
@@ -621,7 +670,7 @@ function test_snapshot() {
621670
/**
622671
* Test publish snapshot with customize_save_after.
623672
*
624-
* @covers Customize_Snapshot_Manager::publish_snapshot_with_customize_save_after()
673+
* @covers CustomizeSnapshots\Customize_Snapshot_Manager::publish_snapshot_with_customize_save_after()
625674
*/
626675
function test_publish_snapshot_with_customize_save_after() {
627676
wp_set_current_user( $this->user_id );
@@ -645,7 +694,7 @@ function test_publish_snapshot_with_customize_save_after() {
645694
/**
646695
* Test prepare_snapshot_post_content_for_publish.
647696
*
648-
* @covers Customize_Snapshot_Manager::prepare_snapshot_post_content_for_publish()
697+
* @covers CustomizeSnapshots\Customize_Snapshot_Manager::prepare_snapshot_post_content_for_publish()
649698
*/
650699
public function test_prepare_snapshot_post_content_for_publish() {
651700
$snapshot_manager = get_plugin_instance()->customize_snapshot_manager;
@@ -676,7 +725,7 @@ public function test_prepare_snapshot_post_content_for_publish() {
676725
/**
677726
* Test save_settings_with_publish_snapshot.
678727
*
679-
* @covers Customize_Snapshot_Manager::save_settings_with_publish_snapshot()
728+
* @covers CustomizeSnapshots\Customize_Snapshot_Manager::save_settings_with_publish_snapshot()
680729
*/
681730
public function test_save_settings_with_publish_snapshot() {
682731
$post_type = $this->manager->post_type;
@@ -740,7 +789,7 @@ public function test_save_settings_with_publish_snapshot() {
740789
/**
741790
* Test prepare_errors_for_response.
742791
*
743-
* @covers Customize_Snapshot_Manager::prepare_errors_for_response()
792+
* @covers CustomizeSnapshots\Customize_Snapshot_Manager::prepare_errors_for_response()
744793
*/
745794
public function test_prepare_errors_for_response() {
746795
$this->markTestIncomplete();
@@ -749,7 +798,7 @@ public function test_prepare_errors_for_response() {
749798
/**
750799
* Tests generate_uuid.
751800
*
752-
* @covers Customize_Snapshot_Manager::generate_uuid()
801+
* @covers CustomizeSnapshots\Customize_Snapshot_Manager::generate_uuid()
753802
*/
754803
public function test_generate_uuid() {
755804
$this->markTestIncomplete();
@@ -758,7 +807,7 @@ public function test_generate_uuid() {
758807
/**
759808
* Tests is_valid_uuid.
760809
*
761-
* @covers Customize_Snapshot_Manager::is_valid_uuid()
810+
* @covers CustomizeSnapshots\Customize_Snapshot_Manager::is_valid_uuid()
762811
*/
763812
public function test_is_valid_uuid() {
764813
$this->markTestIncomplete();
@@ -814,7 +863,7 @@ public function test_customize_menu_return() {
814863
/**
815864
* Tests print_admin_bar_styles.
816865
*
817-
* @covers Customize_Snapshot_Manager::print_admin_bar_styles()
866+
* @covers CustomizeSnapshots\Customize_Snapshot_Manager::print_admin_bar_styles()
818867
*/
819868
public function test_print_admin_bar_styles() {
820869
$manager = new Customize_Snapshot_Manager( $this->plugin );
@@ -828,7 +877,7 @@ public function test_print_admin_bar_styles() {
828877
/**
829878
* Test replace_customize_link.
830879
*
831-
* @covers Customize_Snapshot_Manager::replace_customize_link()
880+
* @covers CustomizeSnapshots\Customize_Snapshot_Manager::replace_customize_link()
832881
*/
833882
public function test_replace_customize_link() {
834883
global $wp_admin_bar;
@@ -871,10 +920,10 @@ public function test_replace_customize_link() {
871920
/**
872921
* Test misc admin bar extensions.
873922
*
874-
* @covers Customize_Snapshot_Manager::add_post_edit_screen_link()
875-
* @covers Customize_Snapshot_Manager::add_snapshot_exit_link()
876-
* @covers Customize_Snapshot_Manager::add_resume_snapshot_link()
877-
* @covers Customize_Snapshot_Manager::remove_all_non_snapshot_admin_bar_links()
923+
* @covers CustomizeSnapshots\Customize_Snapshot_Manager::add_post_edit_screen_link()
924+
* @covers CustomizeSnapshots\Customize_Snapshot_Manager::add_snapshot_exit_link()
925+
* @covers CustomizeSnapshots\Customize_Snapshot_Manager::add_resume_snapshot_link()
926+
* @covers CustomizeSnapshots\Customize_Snapshot_Manager::remove_all_non_snapshot_admin_bar_links()
878927
*/
879928
public function test_add_post_edit_and_exit_links() {
880929
global $wp_admin_bar;
@@ -921,7 +970,7 @@ public function test_add_post_edit_and_exit_links() {
921970
/**
922971
* Test render templates.
923972
*
924-
* @covers Customize_Snapshot_Manager::render_templates()
973+
* @covers CustomizeSnapshots\Customize_Snapshot_Manager::render_templates()
925974
*/
926975
public function test_render_templates() {
927976
ob_start();
@@ -940,7 +989,7 @@ public function test_render_templates() {
940989
/**
941990
* Test format_gmt_offset
942991
*
943-
* @covers Customize_Snapshot_Manager::format_gmt_offset()
992+
* @covers CustomizeSnapshots\Customize_Snapshot_Manager::format_gmt_offset()
944993
*/
945994
public function test_format_gmt_offset() {
946995
$offset = $this->manager->format_gmt_offset( 7.0 );
@@ -950,7 +999,7 @@ public function test_format_gmt_offset() {
950999
/**
9511000
* Test month choices
9521001
*
953-
* @covers Customize_Snapshot_Manager::get_month_choices()
1002+
* @covers CustomizeSnapshots\Customize_Snapshot_Manager::get_month_choices()
9541003
*/
9551004
public function test_get_month_choices() {
9561005
$data = $this->manager->get_month_choices();
@@ -961,7 +1010,7 @@ public function test_get_month_choices() {
9611010
/**
9621011
* Test override post date if empty.
9631012
*
964-
* @covers Customize_Snapshot_Manager::override_post_date_default_data()
1013+
* @covers CustomizeSnapshots\Customize_Snapshot_Manager::override_post_date_default_data()
9651014
*/
9661015
public function test_override_post_date_default_data() {
9671016
$post_id = $this->factory()->post->create();

0 commit comments

Comments
 (0)