Changeset 42343 for trunk/tests/phpunit/tests/customize/manager.php
- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/customize/manager.php
r41839 r42343 48 48 public static function wpSetUpBeforeClass( $factory ) { 49 49 self::$subscriber_user_id = $factory->user->create( array( 'role' => 'subscriber' ) ); 50 self::$admin_user_id = $factory->user->create( array( 'role' => 'administrator' ) );50 self::$admin_user_id = $factory->user->create( array( 'role' => 'administrator' ) ); 51 51 } 52 52 … … 57 57 parent::setUp(); 58 58 require_once( ABSPATH . WPINC . '/class-wp-customize-manager.php' ); 59 $this->manager = $this->instantiate();59 $this->manager = $this->instantiate(); 60 60 $this->undefined = new stdClass(); 61 61 62 $orig_file = DIR_TESTDATA . '/images/canola.jpg';62 $orig_file = DIR_TESTDATA . '/images/canola.jpg'; 63 63 $this->test_file = '/tmp/canola.jpg'; 64 64 copy( $orig_file, $this->test_file ); 65 $orig_file2 = DIR_TESTDATA . '/images/waffles.jpg';65 $orig_file2 = DIR_TESTDATA . '/images/waffles.jpg'; 66 66 $this->test_file2 = '/tmp/waffles.jpg'; 67 67 copy( $orig_file2, $this->test_file2 ); … … 110 110 */ 111 111 function test_constructor() { 112 $uuid = wp_generate_uuid4();113 $theme = 'twentyfifteen';112 $uuid = wp_generate_uuid4(); 113 $theme = 'twentyfifteen'; 114 114 $messenger_channel = 'preview-123'; 115 $wp_customize = new WP_Customize_Manager( array( 116 'changeset_uuid' => $uuid, 117 'theme' => $theme, 118 'messenger_channel' => $messenger_channel, 119 ) ); 115 $wp_customize = new WP_Customize_Manager( 116 array( 117 'changeset_uuid' => $uuid, 118 'theme' => $theme, 119 'messenger_channel' => $messenger_channel, 120 ) 121 ); 120 122 $this->assertEquals( $uuid, $wp_customize->changeset_uuid() ); 121 123 $this->assertEquals( $theme, $wp_customize->get_stylesheet() ); … … 124 126 $this->assertTrue( $wp_customize->branching() ); 125 127 126 $wp_customize = new WP_Customize_Manager( array( 127 'changeset_uuid' => null, 128 ) ); 128 $wp_customize = new WP_Customize_Manager( 129 array( 130 'changeset_uuid' => null, 131 ) 132 ); 129 133 $this->assertTrue( wp_is_uuid( $wp_customize->changeset_uuid(), 4 ) ); 130 134 131 $theme = 'twentyfourteen';132 $messenger_channel = 'preview-456';133 $_REQUEST['theme'] = $theme;135 $theme = 'twentyfourteen'; 136 $messenger_channel = 'preview-456'; 137 $_REQUEST['theme'] = $theme; 134 138 $_REQUEST['customize_messenger_channel'] = $messenger_channel; 135 $wp_customize = new WP_Customize_Manager( array( 'changeset_uuid' => $uuid ) );139 $wp_customize = new WP_Customize_Manager( array( 'changeset_uuid' => $uuid ) ); 136 140 $this->assertEquals( $theme, $wp_customize->get_stylesheet() ); 137 141 $this->assertEquals( $messenger_channel, $wp_customize->get_messenger_channel() ); 138 142 139 $theme = 'twentyfourteen';143 $theme = 'twentyfourteen'; 140 144 $_REQUEST['customize_theme'] = $theme; 141 $wp_customize = new WP_Customize_Manager();145 $wp_customize = new WP_Customize_Manager(); 142 146 $this->assertEquals( $theme, $wp_customize->get_stylesheet() ); 143 147 $this->assertTrue( wp_is_uuid( $wp_customize->changeset_uuid(), 4 ) ); … … 162 166 163 167 $uuid1 = wp_generate_uuid4(); 164 $this->factory()->post->create( array( 165 'post_type' => 'customize_changeset', 166 'post_name' => $uuid1, 167 'post_status' => 'draft', 168 'post_content' => wp_json_encode( $data ), 169 'post_author' => get_current_user_id(), 170 'post_date_gmt' => gmdate( 'Y-m-d H:i:s', strtotime( '-2 days' ) ), 171 ) ); 168 $this->factory()->post->create( 169 array( 170 'post_type' => 'customize_changeset', 171 'post_name' => $uuid1, 172 'post_status' => 'draft', 173 'post_content' => wp_json_encode( $data ), 174 'post_author' => get_current_user_id(), 175 'post_date_gmt' => gmdate( 'Y-m-d H:i:s', strtotime( '-2 days' ) ), 176 ) 177 ); 172 178 173 179 /* … … 175 181 * as in non-branching mode there should only be one pending changeset at a time. 176 182 */ 177 $uuid2 = wp_generate_uuid4(); 178 $post_id = $this->factory()->post->create( array( 179 'post_type' => 'customize_changeset', 180 'post_name' => $uuid2, 181 'post_status' => 'draft', 182 'post_content' => wp_json_encode( $data ), 183 'post_author' => $other_admin_user_id, 184 'post_date_gmt' => gmdate( 'Y-m-d H:i:s', strtotime( '-1 day' ) ), 185 ) ); 186 187 $wp_customize = new WP_Customize_Manager( array( 188 'changeset_uuid' => false, // Cause UUID to be deferred. 189 'branching' => false, // To cause drafted changeset to be autoloaded. 190 ) ); 183 $uuid2 = wp_generate_uuid4(); 184 $post_id = $this->factory()->post->create( 185 array( 186 'post_type' => 'customize_changeset', 187 'post_name' => $uuid2, 188 'post_status' => 'draft', 189 'post_content' => wp_json_encode( $data ), 190 'post_author' => $other_admin_user_id, 191 'post_date_gmt' => gmdate( 'Y-m-d H:i:s', strtotime( '-1 day' ) ), 192 ) 193 ); 194 195 $wp_customize = new WP_Customize_Manager( 196 array( 197 'changeset_uuid' => false, // Cause UUID to be deferred. 198 'branching' => false, // To cause drafted changeset to be autoloaded. 199 ) 200 ); 191 201 $this->assertEquals( $uuid2, $wp_customize->changeset_uuid() ); 192 202 $this->assertEquals( $post_id, $wp_customize->changeset_post_id() ); 193 203 194 $wp_customize = new WP_Customize_Manager( array( 195 'changeset_uuid' => false, // Cause UUID to be deferred. 196 'branching' => true, // To cause no drafted changeset to be autoloaded. 197 ) ); 204 $wp_customize = new WP_Customize_Manager( 205 array( 206 'changeset_uuid' => false, // Cause UUID to be deferred. 207 'branching' => true, // To cause no drafted changeset to be autoloaded. 208 ) 209 ); 198 210 $this->assertNotContains( $wp_customize->changeset_uuid(), array( $uuid1, $uuid2 ) ); 199 211 $this->assertEmpty( $wp_customize->changeset_post_id() ); … … 201 213 // Make sure existing changeset is not autoloaded in the case of previewing a theme switch. 202 214 switch_theme( 'twentyseventeen' ); 203 $wp_customize = new WP_Customize_Manager( array( 204 'changeset_uuid' => false, // Cause UUID to be deferred. 205 'branching' => false, 206 'theme' => 'twentyfifteen', 207 ) ); 215 $wp_customize = new WP_Customize_Manager( 216 array( 217 'changeset_uuid' => false, // Cause UUID to be deferred. 218 'branching' => false, 219 'theme' => 'twentyfifteen', 220 ) 221 ); 208 222 $this->assertEmpty( $wp_customize->changeset_post_id() ); 209 223 } … … 220 234 221 235 // Unauthorized. 222 $exception = null;236 $exception = null; 223 237 $wp_customize = new WP_Customize_Manager(); 224 238 wp_set_current_user( self::$subscriber_user_id ); … … 289 303 290 304 wp_set_current_user( 0 ); 291 $exception = null;305 $exception = null; 292 306 $wp_customize = new WP_Customize_Manager(); 293 307 wp_set_current_user( self::$subscriber_user_id ); … … 372 386 */ 373 387 function test_changeset_uuid() { 374 $uuid = wp_generate_uuid4();388 $uuid = wp_generate_uuid4(); 375 389 $wp_customize = new WP_Customize_Manager( array( 'changeset_uuid' => $uuid ) ); 376 390 $this->assertEquals( $uuid, $wp_customize->changeset_uuid() ); … … 388 402 wp_set_current_user( self::$admin_user_id ); 389 403 $wp_customize = new WP_Customize_Manager(); 390 $title = 'Hello World';404 $title = 'Hello World'; 391 405 $wp_customize->set_post_value( 'blogname', $title ); 392 406 $this->assertNotEquals( $title, get_option( 'blogname' ) ); … … 404 418 */ 405 419 function test_find_changeset_post_id() { 406 $uuid = wp_generate_uuid4(); 407 $post_id = $this->factory()->post->create( array( 408 'post_name' => $uuid, 409 'post_type' => 'customize_changeset', 410 'post_status' => 'auto-draft', 411 'post_content' => '{}', 412 ) ); 420 $uuid = wp_generate_uuid4(); 421 $post_id = $this->factory()->post->create( 422 array( 423 'post_name' => $uuid, 424 'post_type' => 'customize_changeset', 425 'post_status' => 'auto-draft', 426 'post_content' => '{}', 427 ) 428 ); 413 429 414 430 $wp_customize = new WP_Customize_Manager(); … … 427 443 */ 428 444 function test_changeset_post_id() { 429 $uuid = wp_generate_uuid4();445 $uuid = wp_generate_uuid4(); 430 446 $wp_customize = new WP_Customize_Manager( array( 'changeset_uuid' => $uuid ) ); 431 447 $this->assertNull( $wp_customize->changeset_post_id() ); 432 448 433 $uuid = wp_generate_uuid4();449 $uuid = wp_generate_uuid4(); 434 450 $wp_customize = new WP_Customize_Manager( array( 'changeset_uuid' => $uuid ) ); 435 $post_id = $this->factory()->post->create( array( 436 'post_name' => $uuid, 437 'post_type' => 'customize_changeset', 438 'post_status' => 'auto-draft', 439 'post_content' => '{}', 440 ) ); 451 $post_id = $this->factory()->post->create( 452 array( 453 'post_name' => $uuid, 454 'post_type' => 'customize_changeset', 455 'post_status' => 'auto-draft', 456 'post_content' => '{}', 457 ) 458 ); 441 459 $this->assertEquals( $post_id, $wp_customize->changeset_post_id() ); 442 460 } … … 450 468 function test_changeset_data() { 451 469 wp_set_current_user( self::$admin_user_id ); 452 $uuid = wp_generate_uuid4();470 $uuid = wp_generate_uuid4(); 453 471 $wp_customize = new WP_Customize_Manager( array( 'changeset_uuid' => $uuid ) ); 454 472 $this->assertEquals( array(), $wp_customize->changeset_data() ); … … 456 474 $uuid = wp_generate_uuid4(); 457 475 $data = array( 458 'blogname' => array( 'value' => 'Hello World' ),476 'blogname' => array( 'value' => 'Hello World' ), 459 477 'blogdescription' => array( 'value' => 'Greet the world' ), 460 478 ); 461 $this->factory()->post->create( array( 462 'post_name' => $uuid, 463 'post_type' => 'customize_changeset', 464 'post_status' => 'draft', 465 'post_content' => wp_json_encode( $data ), 466 ) ); 479 $this->factory()->post->create( 480 array( 481 'post_name' => $uuid, 482 'post_type' => 'customize_changeset', 483 'post_status' => 'draft', 484 'post_content' => wp_json_encode( $data ), 485 ) 486 ); 467 487 $wp_customize = new WP_Customize_Manager( array( 'changeset_uuid' => $uuid ) ); 468 488 $this->assertEquals( $data, $wp_customize->changeset_data() ); … … 471 491 $wp_customize->set_post_value( 'blogname', 'Hola Mundo' ); 472 492 $wp_customize->register_controls(); // That is, settings, so blogname setting is registered. 473 $r = $wp_customize->save_changeset_post( array( 474 'autosave' => true, 475 ) ); 493 $r = $wp_customize->save_changeset_post( 494 array( 495 'autosave' => true, 496 ) 497 ); 476 498 $this->assertNotInstanceOf( 'WP_Error', $r ); 477 499 478 500 // No change to data if not requesting autosave. 479 $wp_customize = new WP_Customize_Manager( array( 480 'changeset_uuid' => $uuid, 481 'autosaved' => false, 482 ) ); 501 $wp_customize = new WP_Customize_Manager( 502 array( 503 'changeset_uuid' => $uuid, 504 'autosaved' => false, 505 ) 506 ); 483 507 $wp_customize->register_controls(); // That is, settings. 484 508 $this->assertFalse( $wp_customize->autosaved() ); … … 486 510 487 511 // No change to data if not requesting autosave. 488 $wp_customize = new WP_Customize_Manager( array( 489 'changeset_uuid' => $uuid, 490 'autosaved' => true, 491 ) ); 512 $wp_customize = new WP_Customize_Manager( 513 array( 514 'changeset_uuid' => $uuid, 515 'autosaved' => true, 516 ) 517 ); 492 518 $this->assertTrue( $wp_customize->autosaved() ); 493 519 $this->assertNotEquals( $data, $wp_customize->changeset_data() ); … … 514 540 add_theme_support( 'custom-background' ); 515 541 516 $existing_canola_attachment_id = self::factory()->attachment->create_object( $this->test_file, 0, array( 517 'post_mime_type' => 'image/jpeg', 518 'post_type' => 'attachment', 519 'post_name' => 'canola', 520 ) ); 521 $existing_published_home_page_id = $this->factory()->post->create( array( 522 'post_name' => 'home', 523 'post_type' => 'page', 524 'post_status' => 'publish' 525 ) ); 526 $existing_auto_draft_about_page_id = $this->factory()->post->create( array( 527 'post_name' => 'about', 528 'post_type' => 'page', 529 'post_status' => 'auto-draft' 530 ) ); 542 $existing_canola_attachment_id = self::factory()->attachment->create_object( 543 $this->test_file, 0, array( 544 'post_mime_type' => 'image/jpeg', 545 'post_type' => 'attachment', 546 'post_name' => 'canola', 547 ) 548 ); 549 $existing_published_home_page_id = $this->factory()->post->create( 550 array( 551 'post_name' => 'home', 552 'post_type' => 'page', 553 'post_status' => 'publish', 554 ) 555 ); 556 $existing_auto_draft_about_page_id = $this->factory()->post->create( 557 array( 558 'post_name' => 'about', 559 'post_type' => 'page', 560 'post_status' => 'auto-draft', 561 ) 562 ); 531 563 532 564 global $wp_customize; 533 $wp_customize = new WP_Customize_Manager();565 $wp_customize = new WP_Customize_Manager(); 534 566 $starter_content_config = array( 535 'widgets' => array(567 'widgets' => array( 536 568 'sidebar-1' => array( 537 569 'text_business_info', 538 'meta_custom' => array( 'meta', array( 539 'title' => 'Pre-hydrated meta widget.', 540 ) ), 570 'meta_custom' => array( 571 'meta', 572 array( 573 'title' => 'Pre-hydrated meta widget.', 574 ), 575 ), 541 576 ), 542 577 ), 543 'nav_menus' => array(578 'nav_menus' => array( 544 579 'top' => array( 545 580 'name' => 'Menu Name', … … 552 587 'link_custom' => array( 553 588 'title' => 'Custom', 554 'url' => 'https://custom.example.com/',589 'url' => 'https://custom.example.com/', 555 590 ), 556 591 ), 557 592 ), 558 593 ), 559 'posts' => array(594 'posts' => array( 560 595 'home', 561 'about' => array(596 'about' => array( 562 597 'template' => 'sample-page-template.php', 563 598 ), 564 599 'blog', 565 'custom' => array(566 'post_type' => 'post',600 'custom' => array( 601 'post_type' => 'post', 567 602 'post_title' => 'Custom', 568 'thumbnail' => '{{waffles}}',603 'thumbnail' => '{{waffles}}', 569 604 ), 570 605 'unknown_cpt' => array( 571 'post_type' => 'unknown_cpt',606 'post_type' => 'unknown_cpt', 572 607 'post_title' => 'Unknown CPT', 573 608 ), … … 575 610 'attachments' => array( 576 611 'waffles' => array( 577 'post_title' => 'Waffles',612 'post_title' => 'Waffles', 578 613 'post_content' => 'Waffles Attachment Description', 579 614 'post_excerpt' => 'Waffles Attachment Caption', 580 'file' => $this->test_file2,615 'file' => $this->test_file2, 581 616 ), 582 'canola' => array(583 'post_title' => 'Canola',617 'canola' => array( 618 'post_title' => 'Canola', 584 619 'post_content' => 'Canola Attachment Description', 585 620 'post_excerpt' => 'Canola Attachment Caption', 586 'file' => $this->test_file,621 'file' => $this->test_file, 587 622 ), 588 623 ), 589 'options' => array(590 'blogname' => 'Starter Content Title',624 'options' => array( 625 'blogname' => 'Starter Content Title', 591 626 'blogdescription' => 'Starter Content Tagline', 592 'show_on_front' => 'page',593 'page_on_front' => '{{home}}',594 'page_for_posts' => '{{blog}}',627 'show_on_front' => 'page', 628 'page_on_front' => '{{home}}', 629 'page_for_posts' => '{{blog}}', 595 630 ), 596 'theme_mods' => array(597 'custom_logo' => '{{canola}}',598 'header_image' => '{{waffles}}',631 'theme_mods' => array( 632 'custom_logo' => '{{canola}}', 633 'header_image' => '{{waffles}}', 599 634 'background_image' => '{{waffles}}', 600 635 ), … … 605 640 $this->assertEmpty( $wp_customize->unsanitized_post_values() ); 606 641 $wp_customize->import_theme_starter_content(); 607 $changeset_values = $wp_customize->unsanitized_post_values();642 $changeset_values = $wp_customize->unsanitized_post_values(); 608 643 $expected_setting_ids = array( 609 644 'blogname', … … 698 733 699 734 // Test that saving non-starter content on top of the changeset clears the starter_content flag. 700 $wp_customize->save_changeset_post( array( 701 'data' => array( 702 'blogname' => array( 'value' => 'Starter Content Modified' ), 703 ), 704 ) ); 735 $wp_customize->save_changeset_post( 736 array( 737 'data' => array( 738 'blogname' => array( 'value' => 'Starter Content Modified' ), 739 ), 740 ) 741 ); 705 742 $changeset_data = $wp_customize->changeset_data(); 706 743 $this->assertArrayNotHasKey( 'starter_content', $changeset_data['blogname'] ); … … 708 745 709 746 // Test that adding blogname starter content is ignored now that it is modified, but updating a non-modified starter content blog description passes. 710 $previous_blogname = $changeset_data['blogname']['value'];747 $previous_blogname = $changeset_data['blogname']['value']; 711 748 $previous_blogdescription = $changeset_data['blogdescription']['value']; 712 $wp_customize->import_theme_starter_content( array( 713 'options' => array( 714 'blogname' => 'Newer Starter Content Title', 715 'blogdescription' => 'Newer Starter Content Description', 716 ), 717 ) ); 749 $wp_customize->import_theme_starter_content( 750 array( 751 'options' => array( 752 'blogname' => 'Newer Starter Content Title', 753 'blogdescription' => 'Newer Starter Content Description', 754 ), 755 ) 756 ); 718 757 $changeset_data = $wp_customize->changeset_data(); 719 758 $this->assertEquals( $previous_blogname, $changeset_data['blogname']['value'] ); … … 761 800 wp_set_current_user( self::$admin_user_id ); 762 801 $did_action_customize_preview_init = did_action( 'customize_preview_init' ); 763 $wp_customize = new WP_Customize_Manager();802 $wp_customize = new WP_Customize_Manager(); 764 803 $wp_customize->customize_preview_init(); 765 804 $this->assertEquals( $did_action_customize_preview_init + 1, did_action( 'customize_preview_init' ) ); … … 784 823 wp_set_current_user( self::$subscriber_user_id ); 785 824 $wp_customize = new WP_Customize_Manager( array( 'messenger_channel' => 'preview-0' ) ); 786 $exception = null;825 $exception = null; 787 826 try { 788 827 $wp_customize->customize_preview_init(); … … 802 841 function test_filter_iframe_security_headers() { 803 842 $customize_url = admin_url( 'customize.php' ); 804 $wp_customize = new WP_Customize_Manager();805 $headers = $wp_customize->filter_iframe_security_headers( array() );843 $wp_customize = new WP_Customize_Manager(); 844 $headers = $wp_customize->filter_iframe_security_headers( array() ); 806 845 $this->assertArrayHasKey( 'X-Frame-Options', $headers ); 807 846 $this->assertArrayHasKey( 'Content-Security-Policy', $headers ); … … 818 857 $preview_theme = $this->get_inactive_core_theme(); 819 858 820 $uuid = wp_generate_uuid4();859 $uuid = wp_generate_uuid4(); 821 860 $messenger_channel = 'preview-0'; 822 $wp_customize = new WP_Customize_Manager( array( 823 'changeset_uuid' => $uuid, 824 'messenger_channel' => $messenger_channel, 825 ) ); 826 $url = $wp_customize->add_state_query_params( home_url( '/' ) ); 827 $parsed_url = wp_parse_url( $url ); 861 $wp_customize = new WP_Customize_Manager( 862 array( 863 'changeset_uuid' => $uuid, 864 'messenger_channel' => $messenger_channel, 865 ) 866 ); 867 $url = $wp_customize->add_state_query_params( home_url( '/' ) ); 868 $parsed_url = wp_parse_url( $url ); 828 869 parse_str( $parsed_url['query'], $query_params ); 829 870 $this->assertArrayHasKey( 'customize_messenger_channel', $query_params ); … … 833 874 $this->assertEquals( $messenger_channel, $query_params['customize_messenger_channel'] ); 834 875 835 $uuid = wp_generate_uuid4(); 836 $wp_customize = new WP_Customize_Manager( array( 837 'changeset_uuid' => $uuid, 838 'messenger_channel' => null, 839 'theme' => $preview_theme, 840 ) ); 841 $url = $wp_customize->add_state_query_params( home_url( '/' ) ); 842 $parsed_url = wp_parse_url( $url ); 876 $uuid = wp_generate_uuid4(); 877 $wp_customize = new WP_Customize_Manager( 878 array( 879 'changeset_uuid' => $uuid, 880 'messenger_channel' => null, 881 'theme' => $preview_theme, 882 ) 883 ); 884 $url = $wp_customize->add_state_query_params( home_url( '/' ) ); 885 $parsed_url = wp_parse_url( $url ); 843 886 parse_str( $parsed_url['query'], $query_params ); 844 887 $this->assertArrayNotHasKey( 'customize_messenger_channel', $query_params ); … … 848 891 $this->assertEquals( $preview_theme, $query_params['customize_theme'] ); 849 892 850 $uuid = wp_generate_uuid4(); 851 $wp_customize = new WP_Customize_Manager( array( 852 'changeset_uuid' => $uuid, 853 'messenger_channel' => null, 854 'theme' => $preview_theme, 855 ) ); 856 $url = $wp_customize->add_state_query_params( 'http://not-allowed.example.com/?q=1' ); 857 $parsed_url = wp_parse_url( $url ); 893 $uuid = wp_generate_uuid4(); 894 $wp_customize = new WP_Customize_Manager( 895 array( 896 'changeset_uuid' => $uuid, 897 'messenger_channel' => null, 898 'theme' => $preview_theme, 899 ) 900 ); 901 $url = $wp_customize->add_state_query_params( 'http://not-allowed.example.com/?q=1' ); 902 $parsed_url = wp_parse_url( $url ); 858 903 parse_str( $parsed_url['query'], $query_params ); 859 904 $this->assertArrayNotHasKey( 'customize_messenger_channel', $query_params ); … … 874 919 $did_action = array( 875 920 'customize_save_validation_before' => did_action( 'customize_save_validation_before' ), 876 'customize_save' => did_action( 'customize_save' ), 877 'customize_save_after' => did_action( 'customize_save_after' ), 878 ); 879 $uuid = wp_generate_uuid4(); 880 881 $wp_customize = $manager = new WP_Customize_Manager( array( 882 'changeset_uuid' => $uuid, 883 ) ); 921 'customize_save' => did_action( 'customize_save' ), 922 'customize_save_after' => did_action( 'customize_save_after' ), 923 ); 924 $uuid = wp_generate_uuid4(); 925 926 $wp_customize = $manager = new WP_Customize_Manager( 927 array( 928 'changeset_uuid' => $uuid, 929 ) 930 ); 884 931 $wp_customize = $manager; 885 932 $manager->register_controls(); … … 888 935 889 936 $pre_saved_data = array( 890 'blogname' => array(937 'blogname' => array( 891 938 'value' => 'Overridden Changeset Title', 892 939 ), … … 895 942 ), 896 943 ); 897 $date = ( gmdate( 'Y' ) + 1 ) . '-12-01 00:00:00'; 898 $r = $manager->save_changeset_post( array( 899 'status' => 'auto-draft', 900 'title' => 'Auto Draft', 901 'date_gmt' => $date, 902 'data' => $pre_saved_data, 903 ) ); 944 $date = ( gmdate( 'Y' ) + 1 ) . '-12-01 00:00:00'; 945 $r = $manager->save_changeset_post( 946 array( 947 'status' => 'auto-draft', 948 'title' => 'Auto Draft', 949 'date_gmt' => $date, 950 'data' => $pre_saved_data, 951 ) 952 ); 904 953 $this->assertInternalType( 'array', $r ); 905 954 … … 926 975 // Test saving with invalid settings, ensuring transaction blocked. 927 976 $previous_saved_data = $saved_data; 928 $manager->add_setting( 'foo_unauthorized', array( 929 'capability' => 'do_not_allow', 930 ) ); 931 $manager->add_setting( 'baz_illegal', array( 932 'validate_callback' => array( $this, 'return_illegal_error' ), 933 ) ); 934 $r = $manager->save_changeset_post( array( 935 'status' => 'auto-draft', 936 'data' => array( 937 'blogname' => array( 938 'value' => 'OK', 977 $manager->add_setting( 978 'foo_unauthorized', array( 979 'capability' => 'do_not_allow', 980 ) 981 ); 982 $manager->add_setting( 983 'baz_illegal', array( 984 'validate_callback' => array( $this, 'return_illegal_error' ), 985 ) 986 ); 987 $r = $manager->save_changeset_post( 988 array( 989 'status' => 'auto-draft', 990 'data' => array( 991 'blogname' => array( 992 'value' => 'OK', 993 ), 994 'foo_unauthorized' => array( 995 'value' => 'No', 996 ), 997 'bar_unknown' => array( 998 'value' => 'No', 999 ), 1000 'baz_illegal' => array( 1001 'value' => 'No', 1002 ), 939 1003 ), 940 'foo_unauthorized' => array( 941 'value' => 'No', 942 ), 943 'bar_unknown' => array( 944 'value' => 'No', 945 ), 946 'baz_illegal' => array( 947 'value' => 'No', 948 ), 949 ), 950 ) ); 1004 ) 1005 ); 951 1006 $this->assertInstanceOf( 'WP_Error', $r ); 952 1007 $this->assertEquals( 'transaction_fail', $r->get_error_code() ); … … 970 1025 971 1026 // Attempt a non-transactional/incremental update. 972 $wp_customize = $manager = new WP_Customize_Manager( array( 973 'changeset_uuid' => $uuid, 974 ) ); 1027 $wp_customize = $manager = new WP_Customize_Manager( 1028 array( 1029 'changeset_uuid' => $uuid, 1030 ) 1031 ); 975 1032 $wp_customize = $manager; 976 1033 $manager->register_controls(); // That is, register settings. 977 $r = $manager->save_changeset_post( array( 978 'status' => null, 979 'data' => array( 980 'blogname' => array( 981 'value' => 'Non-Transactional \o/ <script>unsanitized</script>', 1034 $r = $manager->save_changeset_post( 1035 array( 1036 'status' => null, 1037 'data' => array( 1038 'blogname' => array( 1039 'value' => 'Non-Transactional \o/ <script>unsanitized</script>', 1040 ), 1041 'bar_unknown' => array( 1042 'value' => 'No', 1043 ), 982 1044 ), 983 'bar_unknown' => array( 984 'value' => 'No', 985 ), 986 ), 987 ) ); 1045 ) 1046 ); 988 1047 $this->assertInternalType( 'array', $r ); 989 1048 $this->assertArrayHasKey( 'setting_validities', $r ); … … 997 1056 $customize_changeset_save_data_call_count = $this->customize_changeset_save_data_call_count; 998 1057 add_filter( 'customize_changeset_save_data', array( $this, 'filter_customize_changeset_save_data' ), 10, 2 ); 999 $manager->save_changeset_post( array( 1000 'status' => null, 1001 'data' => array( 1002 'blogname' => array( 1003 'value' => 'Filtered', 1058 $manager->save_changeset_post( 1059 array( 1060 'status' => null, 1061 'data' => array( 1062 'blogname' => array( 1063 'value' => 'Filtered', 1064 ), 1004 1065 ), 1005 ) ,1006 ) );1066 ) 1067 ); 1007 1068 $this->assertEquals( $customize_changeset_save_data_call_count + 1, $this->customize_changeset_save_data_call_count ); 1008 1069 1009 1070 // Publish the changeset: actions will be doubled since also trashed. 1010 1071 $expected_actions = array( 1011 'wp_trash_post' => 1,1012 'clean_post_cache' => 2,1013 'transition_post_status' => 2,1014 'publish_to_trash' => 1,1015 'trash_customize_changeset' => 1,1016 'edit_post' => 2,1072 'wp_trash_post' => 1, 1073 'clean_post_cache' => 2, 1074 'transition_post_status' => 2, 1075 'publish_to_trash' => 1, 1076 'trash_customize_changeset' => 1, 1077 'edit_post' => 2, 1017 1078 'save_post_customize_changeset' => 2, 1018 'save_post' => 2,1019 'wp_insert_post' => 2,1020 'trashed_post' => 1,1021 ); 1022 $action_counts = array();1079 'save_post' => 2, 1080 'wp_insert_post' => 2, 1081 'trashed_post' => 1, 1082 ); 1083 $action_counts = array(); 1023 1084 foreach ( array_keys( $expected_actions ) as $action_name ) { 1024 1085 $action_counts[ $action_name ] = did_action( $action_name ); … … 1027 1088 $wp_customize = $manager = new WP_Customize_Manager( array( 'changeset_uuid' => $uuid ) ); 1028 1089 do_action( 'customize_register', $wp_customize ); 1029 $manager->add_setting( 'scratchpad', array( 1030 'type' => 'option', 1031 'capability' => 'exist', 1032 ) ); 1090 $manager->add_setting( 1091 'scratchpad', array( 1092 'type' => 'option', 1093 'capability' => 'exist', 1094 ) 1095 ); 1033 1096 $manager->get_setting( 'blogname' )->capability = 'exist'; 1034 $original_capabilities = wp_list_pluck( $manager->settings(), 'capability' );1097 $original_capabilities = wp_list_pluck( $manager->settings(), 'capability' ); 1035 1098 wp_set_current_user( self::$subscriber_user_id ); 1036 $r = $manager->save_changeset_post( array( 1037 'status' => 'publish', 1038 'data' => array( 1039 'blogname' => array( 1040 'value' => 'Do it live \o/', 1099 $r = $manager->save_changeset_post( 1100 array( 1101 'status' => 'publish', 1102 'data' => array( 1103 'blogname' => array( 1104 'value' => 'Do it live \o/', 1105 ), 1106 'scratchpad' => array( 1107 'value' => '<script>console.info( "HELLO" )</script>', 1108 ), 1041 1109 ), 1042 'scratchpad' => array( 1043 'value' => '<script>console.info( "HELLO" )</script>', 1044 ), 1045 ), 1046 ) ); 1110 ) 1111 ); 1047 1112 $this->assertInternalType( 'array', $r ); 1048 1113 $this->assertEquals( 'Do it live \o/', get_option( 'blogname' ) ); … … 1061 1126 // Test revisions. 1062 1127 add_post_type_support( 'customize_changeset', 'revisions' ); 1063 $uuid = wp_generate_uuid4();1128 $uuid = wp_generate_uuid4(); 1064 1129 $wp_customize = $manager = new WP_Customize_Manager( array( 'changeset_uuid' => $uuid ) ); 1065 1130 do_action( 'customize_register', $manager ); … … 1128 1193 wp_set_current_user( self::$admin_user_id ); 1129 1194 1130 $preview_theme = $this->get_inactive_core_theme();1195 $preview_theme = $this->get_inactive_core_theme(); 1131 1196 $stashed_theme_mods = array( 1132 1197 $preview_theme => array( … … 1137 1202 ); 1138 1203 update_option( 'customize_stashed_theme_mods', $stashed_theme_mods ); 1139 $uuid = wp_generate_uuid4(); 1140 $manager = new WP_Customize_Manager( array( 1141 'changeset_uuid' => $uuid, 1142 'theme' => $preview_theme, 1143 ) ); 1204 $uuid = wp_generate_uuid4(); 1205 $manager = new WP_Customize_Manager( 1206 array( 1207 'changeset_uuid' => $uuid, 1208 'theme' => $preview_theme, 1209 ) 1210 ); 1144 1211 $wp_customize = $manager; 1145 1212 do_action( 'customize_register', $manager ); … … 1167 1234 $other_admin_user_id = self::factory()->user->create( array( 'role' => 'administrator' ) ); 1168 1235 1169 $uuid = wp_generate_uuid4();1236 $uuid = wp_generate_uuid4(); 1170 1237 $wp_customize = $this->create_test_manager( $uuid ); 1171 $r = $wp_customize->save_changeset_post( array( 1172 'status' => 'auto-draft', 1173 'data' => array( 1174 'blogname' => array( 1175 'value' => 'Admin 1 Title', 1238 $r = $wp_customize->save_changeset_post( 1239 array( 1240 'status' => 'auto-draft', 1241 'data' => array( 1242 'blogname' => array( 1243 'value' => 'Admin 1 Title', 1244 ), 1245 'scratchpad' => array( 1246 'value' => 'Admin 1 Scratch', 1247 ), 1248 'background_color' => array( 1249 'value' => '#000000', 1250 ), 1176 1251 ), 1177 'scratchpad' => array( 1178 'value' => 'Admin 1 Scratch', 1179 ), 1180 'background_color' => array( 1181 'value' => '#000000', 1182 ), 1183 ), 1184 ) ); 1252 ) 1253 ); 1185 1254 $this->assertInternalType( 'array', $r ); 1186 1255 $this->assertEquals( … … 1189 1258 ); 1190 1259 $post_id = $wp_customize->find_changeset_post_id( $uuid ); 1191 $data = json_decode( get_post( $post_id )->post_content, true );1260 $data = json_decode( get_post( $post_id )->post_content, true ); 1192 1261 $this->assertEquals( self::$admin_user_id, $data['blogname']['user_id'] ); 1193 1262 $this->assertEquals( self::$admin_user_id, $data['scratchpad']['user_id'] ); … … 1197 1266 wp_set_current_user( $other_admin_user_id ); 1198 1267 $wp_customize = $this->create_test_manager( $uuid ); 1199 $r = $wp_customize->save_changeset_post( array( 1200 'status' => 'auto-draft', 1201 'data' => array( 1202 'blogname' => array( 1203 'value' => 'Admin 2 Title', 1268 $r = $wp_customize->save_changeset_post( 1269 array( 1270 'status' => 'auto-draft', 1271 'data' => array( 1272 'blogname' => array( 1273 'value' => 'Admin 2 Title', 1274 ), 1275 'background_color' => array( 1276 'value' => '#FFFFFF', 1277 ), 1204 1278 ), 1205 'background_color' => array( 1206 'value' => '#FFFFFF', 1207 ), 1208 ), 1209 ) ); 1279 ) 1280 ); 1210 1281 $this->assertInternalType( 'array', $r ); 1211 1282 $this->assertEquals( … … 1223 1294 // Attempt to save now as under-privileged user. 1224 1295 $wp_customize = $this->create_test_manager( $uuid ); 1225 $r = $wp_customize->save_changeset_post( array( 1226 'status' => 'auto-draft', 1227 'data' => array( 1228 'blogname' => array( 1229 'value' => 'Admin 2 Title', // Identical to what is already in the changeset so will be skipped. 1296 $r = $wp_customize->save_changeset_post( 1297 array( 1298 'status' => 'auto-draft', 1299 'data' => array( 1300 'blogname' => array( 1301 'value' => 'Admin 2 Title', // Identical to what is already in the changeset so will be skipped. 1302 ), 1303 'scratchpad' => array( 1304 'value' => 'Subscriber Scratch', 1305 ), 1230 1306 ), 1231 'scratchpad' => array( 1232 'value' => 'Subscriber Scratch', 1233 ), 1234 ), 1235 'user_id' => self::$subscriber_user_id, 1236 ) ); 1307 'user_id' => self::$subscriber_user_id, 1308 ) 1309 ); 1237 1310 $this->assertInternalType( 'array', $r ); 1238 1311 $this->assertEquals( … … 1246 1319 1247 1320 // Manually update the changeset so that the user_id context is not included. 1248 $data = json_decode( get_post( $post_id )->post_content, true );1321 $data = json_decode( get_post( $post_id )->post_content, true ); 1249 1322 $data['blogdescription']['value'] = 'Programmatically-supplied Tagline'; 1250 wp_update_post( wp_slash( array( 'ID' => $post_id, 'post_content' => wp_json_encode( $data ) ) ) ); 1323 wp_update_post( 1324 wp_slash( 1325 array( 1326 'ID' => $post_id, 1327 'post_content' => wp_json_encode( $data ), 1328 ) 1329 ) 1330 ); 1251 1331 1252 1332 // Ensure the modifying user set as the current user when each is saved, simulating WP Cron envronment. … … 1254 1334 $save_counts = array(); 1255 1335 foreach ( array_keys( $data ) as $setting_id ) { 1256 $setting_id = preg_replace( '/^.+::/', '', $setting_id );1336 $setting_id = preg_replace( '/^.+::/', '', $setting_id ); 1257 1337 $save_counts[ $setting_id ] = did_action( sprintf( 'customize_save_%s', $setting_id ) ); 1258 1338 } … … 1261 1341 add_filter( sprintf( 'customize_sanitize_%s', $setting->id ), array( $this, 'filter_customize_setting_to_log_current_user' ), 10, 2 ); 1262 1342 } 1263 wp_update_post( array( 'ID' => $post_id, 'post_status' => 'publish' ) ); 1343 wp_update_post( 1344 array( 1345 'ID' => $post_id, 1346 'post_status' => 'publish', 1347 ) 1348 ); 1264 1349 foreach ( array_keys( $data ) as $setting_id ) { 1265 1350 $setting_id = preg_replace( '/^.+::/', '', $setting_id ); … … 1281 1366 */ 1282 1367 protected function create_test_manager( $uuid ) { 1283 $manager = new WP_Customize_Manager( array( 1284 'changeset_uuid' => $uuid, 1285 ) ); 1368 $manager = new WP_Customize_Manager( 1369 array( 1370 'changeset_uuid' => $uuid, 1371 ) 1372 ); 1286 1373 do_action( 'customize_register', $manager ); 1287 $manager->add_setting( 'blogfounded', array( 1288 'type' => 'option', 1289 ) ); 1290 $manager->add_setting( 'blogterminated', array( 1291 'type' => 'option', 1292 'capability' => 'do_not_allow', 1293 ) ); 1294 $manager->add_setting( 'scratchpad', array( 1295 'type' => 'option', 1296 'capability' => 'exist', 1297 ) ); 1374 $manager->add_setting( 1375 'blogfounded', array( 1376 'type' => 'option', 1377 ) 1378 ); 1379 $manager->add_setting( 1380 'blogterminated', array( 1381 'type' => 'option', 1382 'capability' => 'do_not_allow', 1383 ) 1384 ); 1385 $manager->add_setting( 1386 'scratchpad', array( 1387 'type' => 'option', 1388 'capability' => 'exist', 1389 ) 1390 ); 1298 1391 return $manager; 1299 1392 } … … 1310 1403 wp_set_current_user( self::$admin_user_id ); 1311 1404 1312 $uuid = wp_generate_uuid4(); 1313 $changeset_post_id = wp_insert_post( array( 1314 'post_type' => 'customize_changeset', 1315 'post_content' => '{}', 1316 'post_name' => $uuid, 1317 'post_status' => 'auto-draft', 1318 'post_date' => gmdate( 'Y-m-d H:i:s', strtotime( '-3 days' ) ), 1319 ) ); 1320 1321 $post = get_post( $changeset_post_id ); 1405 $uuid = wp_generate_uuid4(); 1406 $changeset_post_id = wp_insert_post( 1407 array( 1408 'post_type' => 'customize_changeset', 1409 'post_content' => '{}', 1410 'post_name' => $uuid, 1411 'post_status' => 'auto-draft', 1412 'post_date' => gmdate( 'Y-m-d H:i:s', strtotime( '-3 days' ) ), 1413 ) 1414 ); 1415 1416 $post = get_post( $changeset_post_id ); 1322 1417 $original_post_date = $post->post_date; 1323 1418 1324 1419 $wp_customize = $this->create_test_manager( $uuid ); 1325 $wp_customize->save_changeset_post( array( 1326 'status' => 'auto-draft', 1327 'data' => array( 1328 'blogname' => array( 1329 'value' => 'Admin 1 Title', 1420 $wp_customize->save_changeset_post( 1421 array( 1422 'status' => 'auto-draft', 1423 'data' => array( 1424 'blogname' => array( 1425 'value' => 'Admin 1 Title', 1426 ), 1330 1427 ), 1331 ) ,1332 ) );1428 ) 1429 ); 1333 1430 1334 1431 $post = get_post( $changeset_post_id ); … … 1349 1446 $other_admin_user_id = self::factory()->user->create( array( 'role' => 'administrator' ) ); 1350 1447 1351 $uuid = wp_generate_uuid4();1448 $uuid = wp_generate_uuid4(); 1352 1449 $wp_customize = $this->create_test_manager( $uuid ); 1353 $wp_customize->save_changeset_post( array( 1354 'status' => 'auto-draft', 1355 'data' => array( 1356 'blogname' => array( 1357 'value' => 'Admin 1 Title', 1450 $wp_customize->save_changeset_post( 1451 array( 1452 'status' => 'auto-draft', 1453 'data' => array( 1454 'blogname' => array( 1455 'value' => 'Admin 1 Title', 1456 ), 1457 'blogdescription' => array( 1458 'value' => 'Admin 1 Tagline', 1459 ), 1460 'blogfounded' => array( 1461 'value' => '2016', 1462 ), 1463 'scratchpad' => array( 1464 'value' => 'Admin 1 Scratch', 1465 ), 1358 1466 ), 1359 'blogdescription' => array( 1360 'value' => 'Admin 1 Tagline', 1361 ), 1362 'blogfounded' => array( 1363 'value' => '2016', 1364 ), 1365 'scratchpad' => array( 1366 'value' => 'Admin 1 Scratch', 1367 ), 1368 ), 1369 ) ); 1467 ) 1468 ); 1370 1469 1371 1470 // Make sure that setting properties of unknown and unauthorized settings are rejected. 1372 1471 $data = get_post( $wp_customize->changeset_post_id() )->post_content; 1373 $r = $wp_customize->save_changeset_post( array( 1374 'data' => array( 1375 'unknownsetting' => array( 1376 'custom' => 'prop', 1472 $r = $wp_customize->save_changeset_post( 1473 array( 1474 'data' => array( 1475 'unknownsetting' => array( 1476 'custom' => 'prop', 1477 ), 1478 'blogterminated' => array( 1479 'custom' => 'prop', 1480 ), 1377 1481 ), 1378 'blogterminated' => array( 1379 'custom' => 'prop', 1380 ), 1381 ), 1382 ) ); 1482 ) 1483 ); 1383 1484 $this->assertInstanceOf( 'WP_Error', $r['setting_validities']['unknownsetting'] ); 1384 1485 $this->assertEquals( 'unrecognized', $r['setting_validities']['unknownsetting']->get_error_code() ); … … 1390 1491 wp_set_current_user( $other_admin_user_id ); 1391 1492 $wp_customize = $this->create_test_manager( $uuid ); 1392 $r = $wp_customize->save_changeset_post( array( 1393 'status' => 'auto-draft', 1394 'data' => array( 1395 'blogname' => array( 1396 'value' => 'Admin 1 Title', // Unchanged value. 1493 $r = $wp_customize->save_changeset_post( 1494 array( 1495 'status' => 'auto-draft', 1496 'data' => array( 1497 'blogname' => array( 1498 'value' => 'Admin 1 Title', // Unchanged value. 1499 ), 1500 'blogdescription' => array( 1501 'value' => 'Admin 1 Tagline Changed', // Changed value. 1502 ), 1503 'blogfounded' => array( 1504 'extra' => 'blogfounded_param', // New param. 1505 ), 1506 'scratchpad' => array( 1507 'value' => 'Admin 1 Scratch', // Unchanged value. 1508 'extra' => 'background_scratchpad2', // New param. 1509 ), 1397 1510 ), 1398 'blogdescription' => array( 1399 'value' => 'Admin 1 Tagline Changed', // Changed value. 1400 ), 1401 'blogfounded' => array( 1402 'extra' => 'blogfounded_param', // New param. 1403 ), 1404 'scratchpad' => array( 1405 'value' => 'Admin 1 Scratch', // Unchanged value. 1406 'extra' => 'background_scratchpad2', // New param. 1407 ), 1408 ), 1409 ) ); 1511 ) 1512 ); 1410 1513 1411 1514 // Note that blogfounded is not included among setting_validities because no value was supplied and it is not unrecognized/unauthorized. … … 1429 1532 public function test_save_changeset_post_with_autosave() { 1430 1533 wp_set_current_user( self::$admin_user_id ); 1431 $uuid = wp_generate_uuid4(); 1432 $changeset_post_id = wp_insert_post( array( 1433 'post_type' => 'customize_changeset', 1434 'post_content' => wp_json_encode( array( 1435 'blogname' => array( 1436 'value' => 'Auto-draft Title', 1534 $uuid = wp_generate_uuid4(); 1535 $changeset_post_id = wp_insert_post( 1536 array( 1537 'post_type' => 'customize_changeset', 1538 'post_content' => wp_json_encode( 1539 array( 1540 'blogname' => array( 1541 'value' => 'Auto-draft Title', 1542 ), 1543 ) 1437 1544 ), 1438 ) ), 1439 'post_author' => self::$admin_user_id, 1440 'post_name' => $uuid, 1441 'post_status' => 'auto-draft', 1442 ) ); 1443 1444 $wp_customize = new WP_Customize_Manager( array( 1445 'changeset_uuid' => $uuid, 1446 ) ); 1545 'post_author' => self::$admin_user_id, 1546 'post_name' => $uuid, 1547 'post_status' => 'auto-draft', 1548 ) 1549 ); 1550 1551 $wp_customize = new WP_Customize_Manager( 1552 array( 1553 'changeset_uuid' => $uuid, 1554 ) 1555 ); 1447 1556 $wp_customize->register_controls(); // And settings too. 1448 1557 1449 1558 // Autosave of an auto-draft overwrites original. 1450 $wp_customize->save_changeset_post( array( 1451 'data' => array( 1452 'blogname' => array( 1453 'value' => 'Autosaved Auto-draft Title', 1559 $wp_customize->save_changeset_post( 1560 array( 1561 'data' => array( 1562 'blogname' => array( 1563 'value' => 'Autosaved Auto-draft Title', 1564 ), 1454 1565 ), 1455 ),1456 'autosave' => true,1457 ) );1566 'autosave' => true, 1567 ) 1568 ); 1458 1569 $this->assertFalse( wp_get_post_autosave( $changeset_post_id, get_current_user_id() ) ); 1459 1570 $this->assertContains( 'Autosaved Auto-draft Title', get_post( $changeset_post_id )->post_content ); 1460 1571 1461 1572 // Update status to draft for subsequent tests. 1462 $wp_customize->save_changeset_post( array( 1463 'data' => array( 1464 'blogname' => array( 1465 'value' => 'Draft Title', 1573 $wp_customize->save_changeset_post( 1574 array( 1575 'data' => array( 1576 'blogname' => array( 1577 'value' => 'Draft Title', 1578 ), 1466 1579 ), 1467 ),1468 'status' => 'draft',1469 'autosave' => false,1470 ) );1580 'status' => 'draft', 1581 'autosave' => false, 1582 ) 1583 ); 1471 1584 $this->assertContains( 'Draft Title', get_post( $changeset_post_id )->post_content ); 1472 1585 1473 1586 // Fail: illegal_autosave_with_date_gmt. 1474 $r = $wp_customize->save_changeset_post( array( 1475 'autosave' => true, 1476 'date_gmt' => ( gmdate( 'Y' ) + 1 ) . '-12-01 00:00:00', 1477 ) ); 1587 $r = $wp_customize->save_changeset_post( 1588 array( 1589 'autosave' => true, 1590 'date_gmt' => ( gmdate( 'Y' ) + 1 ) . '-12-01 00:00:00', 1591 ) 1592 ); 1478 1593 $this->assertInstanceOf( 'WP_Error', $r ); 1479 1594 $this->assertEquals( 'illegal_autosave_with_date_gmt', $r->get_error_code() ); 1480 1595 1481 1596 // Fail: illegal_autosave_with_status. 1482 $r = $wp_customize->save_changeset_post( array( 1483 'autosave' => true, 1484 'status' => 'pending', 1485 ) ); 1597 $r = $wp_customize->save_changeset_post( 1598 array( 1599 'autosave' => true, 1600 'status' => 'pending', 1601 ) 1602 ); 1486 1603 $this->assertEquals( 'illegal_autosave_with_status', $r->get_error_code() ); 1487 1604 1488 1605 // Fail: illegal_autosave_with_non_current_user. 1489 $r = $wp_customize->save_changeset_post( array( 1490 'autosave' => true, 1491 'user_id' => $this->factory()->user->create( array( 'role' => 'administrator' ) ), 1492 ) ); 1606 $r = $wp_customize->save_changeset_post( 1607 array( 1608 'autosave' => true, 1609 'user_id' => $this->factory()->user->create( array( 'role' => 'administrator' ) ), 1610 ) 1611 ); 1493 1612 $this->assertEquals( 'illegal_autosave_with_non_current_user', $r->get_error_code() ); 1494 1613 1495 1614 // Try autosave. 1496 1615 $this->assertFalse( wp_get_post_autosave( $changeset_post_id, get_current_user_id() ) ); 1497 $r = $wp_customize->save_changeset_post( array( 1498 'data' => array( 1499 'blogname' => array( 1500 'value' => 'Autosave Title', 1616 $r = $wp_customize->save_changeset_post( 1617 array( 1618 'data' => array( 1619 'blogname' => array( 1620 'value' => 'Autosave Title', 1621 ), 1501 1622 ), 1502 ),1503 'autosave' => true,1504 ) );1623 'autosave' => true, 1624 ) 1625 ); 1505 1626 $this->assertInternalType( 'array', $r ); 1506 1627 … … 1522 1643 1523 1644 $manager = $this->create_test_manager( $uuid ); 1524 $manager->save_changeset_post( array( 1525 'data' => array( 1526 'scratchpad' => array( 1527 'value' => 'foo', 1645 $manager->save_changeset_post( 1646 array( 1647 'data' => array( 1648 'scratchpad' => array( 1649 'value' => 'foo', 1650 ), 1528 1651 ), 1529 ) ,1530 ) );1652 ) 1653 ); 1531 1654 1532 1655 // Create a new manager so post values are unset. … … 1535 1658 $this->assertArrayHasKey( 'scratchpad', $manager->changeset_data() ); 1536 1659 1537 $manager->save_changeset_post( array( 1538 'data' => array( 1539 'scratchpad' => null, 1540 ), 1541 ) ); 1660 $manager->save_changeset_post( 1661 array( 1662 'data' => array( 1663 'scratchpad' => null, 1664 ), 1665 ) 1666 ); 1542 1667 1543 1668 $this->assertArrayNotHasKey( 'scratchpad', $manager->changeset_data() ); … … 1563 1688 do_action( 'customize_register', $wp_customize ); 1564 1689 $wp_customize->set_post_value( 'scratchpad', 'Unfiltered<script>evil</script>' ); 1565 $wp_customize->save_changeset_post( array( 1566 'status' => 'auto-draft', 1567 'user_id' => self::$admin_user_id, 1568 ) ); 1690 $wp_customize->save_changeset_post( 1691 array( 1692 'status' => 'auto-draft', 1693 'user_id' => self::$admin_user_id, 1694 ) 1695 ); 1569 1696 $wp_customize = new WP_Customize_Manager( array( 'changeset_uuid' => $wp_customize->changeset_uuid() ) ); 1570 1697 do_action( 'customize_register', $wp_customize ); … … 1577 1704 do_action( 'customize_register', $wp_customize ); 1578 1705 $wp_customize->set_post_value( 'scratchpad', 'Unfiltered<script>evil</script>' ); 1579 $wp_customize->save_changeset_post( array( 1580 'status' => 'auto-draft', 1581 'user_id' => self::$subscriber_user_id, 1582 ) ); 1706 $wp_customize->save_changeset_post( 1707 array( 1708 'status' => 'auto-draft', 1709 'user_id' => self::$subscriber_user_id, 1710 ) 1711 ); 1583 1712 $wp_customize = new WP_Customize_Manager( array( 'changeset_uuid' => $wp_customize->changeset_uuid() ) ); 1584 1713 do_action( 'customize_register', $wp_customize ); … … 1591 1720 do_action( 'customize_register', $wp_customize ); 1592 1721 $wp_customize->set_post_value( 'scratchpad', 'Unfiltered<script>evil</script>' ); 1593 $wp_customize->save_changeset_post( array( 1594 'status' => 'auto-draft', 1595 'user_id' => self::$admin_user_id, 1596 ) ); 1722 $wp_customize->save_changeset_post( 1723 array( 1724 'status' => 'auto-draft', 1725 'user_id' => self::$admin_user_id, 1726 ) 1727 ); 1597 1728 $changeset_post_id = $wp_customize->changeset_post_id(); 1598 1729 wp_set_current_user( 0 ); … … 1629 1760 $new_sidebar_1 = array_reverse( $new_sidebars_widgets['sidebar-1'] ); 1630 1761 1631 $post_id = $this->factory()->post->create( array( 1632 'post_type' => 'customize_changeset', 1633 'post_status' => 'draft', 1634 'post_name' => wp_generate_uuid4(), 1635 'post_content' => wp_json_encode( array( 1636 'sidebars_widgets[sidebar-1]' => array( 1637 'value' => $new_sidebar_1, 1762 $post_id = $this->factory()->post->create( 1763 array( 1764 'post_type' => 'customize_changeset', 1765 'post_status' => 'draft', 1766 'post_name' => wp_generate_uuid4(), 1767 'post_content' => wp_json_encode( 1768 array( 1769 'sidebars_widgets[sidebar-1]' => array( 1770 'value' => $new_sidebar_1, 1771 ), 1772 ) 1638 1773 ), 1639 ) ),1640 ) );1774 ) 1775 ); 1641 1776 1642 1777 // Save the updated sidebar widgets into the options table by publishing the changeset. … … 1661 1796 $wp_customize = $this->create_test_manager( wp_generate_uuid4() ); 1662 1797 1663 $wp_customize->save_changeset_post( array( 1664 'date_gmt' => gmdate( 'Y-m-d H:i:s', strtotime( '+1 day' ) ), 1665 'status' => 'publish', 1666 'title' => 'Foo', 1667 ) ); 1798 $wp_customize->save_changeset_post( 1799 array( 1800 'date_gmt' => gmdate( 'Y-m-d H:i:s', strtotime( '+1 day' ) ), 1801 'status' => 'publish', 1802 'title' => 'Foo', 1803 ) 1804 ); 1668 1805 1669 1806 $this->assertSame( 'future', get_post_status( $wp_customize->changeset_post_id() ) ); … … 1678 1815 */ 1679 1816 function test_save_changeset_post_for_bad_changeset() { 1680 $uuid = wp_generate_uuid4(); 1681 $post_id = wp_insert_post( array( 1682 'post_type' => 'customize_changeset', 1683 'post_content' => 'INVALID_JSON', 1684 'post_name' => $uuid, 1685 'post_status' => 'auto-draft', 1686 'post_date' => gmdate( 'Y-m-d H:i:s', strtotime( '-3 days' ) ), 1687 ) ); 1817 $uuid = wp_generate_uuid4(); 1818 $post_id = wp_insert_post( 1819 array( 1820 'post_type' => 'customize_changeset', 1821 'post_content' => 'INVALID_JSON', 1822 'post_name' => $uuid, 1823 'post_status' => 'auto-draft', 1824 'post_date' => gmdate( 'Y-m-d H:i:s', strtotime( '-3 days' ) ), 1825 ) 1826 ); 1688 1827 $manager = $this->create_test_manager( $uuid ); 1689 $args = array(1828 $args = array( 1690 1829 'data' => array( 1691 1830 'blogname' => array( … … 1701 1840 } 1702 1841 1703 wp_update_post( array( 1704 'ID' => $post_id, 1705 'post_content' => 'null', 1706 ) ); 1842 wp_update_post( 1843 array( 1844 'ID' => $post_id, 1845 'post_content' => 'null', 1846 ) 1847 ); 1707 1848 $r = $manager->save_changeset_post( $args ); 1708 1849 $this->assertInstanceOf( 'WP_Error', $r ); … … 1717 1858 public function test_trash_changeset_post_preserves_properties() { 1718 1859 $args = array( 1719 'post_type' => 'customize_changeset', 1720 'post_content' => wp_json_encode( array( 1721 'blogname' => array( 1722 'value' => 'Test', 1723 ), 1724 ) ), 1725 'post_name' => wp_generate_uuid4(), 1726 'post_status' => 'draft', 1860 'post_type' => 'customize_changeset', 1861 'post_content' => wp_json_encode( 1862 array( 1863 'blogname' => array( 1864 'value' => 'Test', 1865 ), 1866 ) 1867 ), 1868 'post_name' => wp_generate_uuid4(), 1869 'post_status' => 'draft', 1727 1870 ); 1728 1871 … … 1745 1888 */ 1746 1889 function register_scratchpad_setting( WP_Customize_Manager $wp_customize ) { 1747 $wp_customize->add_setting( 'scratchpad', array( 1748 'type' => 'option', 1749 'capability' => 'exist', 1750 'sanitize_callback' => array( $this, 'filter_sanitize_scratchpad' ), 1751 ) ); 1890 $wp_customize->add_setting( 1891 'scratchpad', array( 1892 'type' => 'option', 1893 'capability' => 'exist', 1894 'sanitize_callback' => array( $this, 'filter_sanitize_scratchpad' ), 1895 ) 1896 ); 1752 1897 } 1753 1898 … … 1863 2008 $manager = $this->manager; 1864 2009 1865 $customized = array(1866 'foo' => 'bar',2010 $customized = array( 2011 'foo' => 'bar', 1867 2012 'baz[quux]' => 123, 1868 2013 ); 1869 2014 $_POST['customized'] = wp_slash( wp_json_encode( $customized ) ); 1870 $post_values = $manager->unsanitized_post_values();2015 $post_values = $manager->unsanitized_post_values(); 1871 2016 $this->assertEquals( $customized, $post_values ); 1872 2017 $this->assertEmpty( $manager->unsanitized_post_values( array( 'exclude_post_data' => true ) ) ); … … 1891 2036 wp_set_current_user( self::$admin_user_id ); 1892 2037 1893 $preview_theme = $this->get_inactive_core_theme();1894 $stashed_theme_mods = array(2038 $preview_theme = $this->get_inactive_core_theme(); 2039 $stashed_theme_mods = array( 1895 2040 $preview_theme => array( 1896 2041 'background_color' => array( … … 1906 2051 update_option( 'customize_stashed_theme_mods', $stashed_theme_mods ); 1907 2052 1908 $post_values = array(2053 $post_values = array( 1909 2054 'blogdescription' => 'Post Input Tagline', 1910 2055 ); 1911 2056 $_POST['customized'] = wp_slash( wp_json_encode( $post_values ) ); 1912 2057 1913 $uuid = wp_generate_uuid4();2058 $uuid = wp_generate_uuid4(); 1914 2059 $changeset_data = array( 1915 'blogname' => array(2060 'blogname' => array( 1916 2061 'value' => 'Changeset Title', 1917 2062 ), … … 1920 2065 ), 1921 2066 ); 1922 $this->factory()->post->create( array( 1923 'post_type' => 'customize_changeset', 1924 'post_status' => 'auto-draft', 1925 'post_name' => $uuid, 1926 'post_content' => wp_json_encode( $changeset_data ), 1927 ) ); 1928 1929 $manager = new WP_Customize_Manager( array( 1930 'changeset_uuid' => $uuid, 1931 ) ); 2067 $this->factory()->post->create( 2068 array( 2069 'post_type' => 'customize_changeset', 2070 'post_status' => 'auto-draft', 2071 'post_name' => $uuid, 2072 'post_content' => wp_json_encode( $changeset_data ), 2073 ) 2074 ); 2075 2076 $manager = new WP_Customize_Manager( 2077 array( 2078 'changeset_uuid' => $uuid, 2079 ) 2080 ); 1932 2081 $this->assertTrue( $manager->is_theme_active() ); 1933 2082 … … 1936 2085 $this->assertEquals( 1937 2086 array( 1938 'blogname' => 'Changeset Title',2087 'blogname' => 'Changeset Title', 1939 2088 'blogdescription' => 'Post Input Tagline', 1940 2089 ), … … 1951 2100 $this->assertEquals( 1952 2101 array( 1953 'blogname' => 'Changeset Title',2102 'blogname' => 'Changeset Title', 1954 2103 'blogdescription' => 'Post Override Tagline', 1955 2104 ), … … 1959 2108 $this->assertEquals( 1960 2109 array( 1961 'blogname' => 'Changeset Title',2110 'blogname' => 'Changeset Title', 1962 2111 'blogdescription' => 'Changeset Tagline', 1963 2112 ), … … 1965 2114 ); 1966 2115 1967 $this->assertEmpty( $manager->unsanitized_post_values( array( 'exclude_post_data' => true, 'exclude_changeset' => true ) ) ); 2116 $this->assertEmpty( 2117 $manager->unsanitized_post_values( 2118 array( 2119 'exclude_post_data' => true, 2120 'exclude_changeset' => true, 2121 ) 2122 ) 2123 ); 1968 2124 1969 2125 // Test unstashing theme mods. 1970 $manager = new WP_Customize_Manager( array( 1971 'changeset_uuid' => $uuid, 1972 'theme' => $preview_theme, 1973 ) ); 2126 $manager = new WP_Customize_Manager( 2127 array( 2128 'changeset_uuid' => $uuid, 2129 'theme' => $preview_theme, 2130 ) 2131 ); 1974 2132 $this->assertFalse( $manager->is_theme_active() ); 1975 $values = $manager->unsanitized_post_values( array( 'exclude_post_data' => true, 'exclude_changeset' => true ) ); 2133 $values = $manager->unsanitized_post_values( 2134 array( 2135 'exclude_post_data' => true, 2136 'exclude_changeset' => true, 2137 ) 2138 ); 1976 2139 $this->assertNotEmpty( $values ); 1977 2140 $this->assertArrayHasKey( 'background_color', $values ); 1978 2141 $this->assertEquals( '#000000', $values['background_color'] ); 1979 2142 1980 $values = $manager->unsanitized_post_values( array( 'exclude_post_data' => false, 'exclude_changeset' => false ) ); 2143 $values = $manager->unsanitized_post_values( 2144 array( 2145 'exclude_post_data' => false, 2146 'exclude_changeset' => false, 2147 ) 2148 ); 1981 2149 $this->assertArrayHasKey( 'background_color', $values ); 1982 2150 $this->assertArrayHasKey( 'blogname', $values ); … … 1991 2159 function test_post_value() { 1992 2160 wp_set_current_user( self::$admin_user_id ); 1993 $posted_settings = array(2161 $posted_settings = array( 1994 2162 'foo' => 'OOF', 1995 2163 ); … … 2016 2184 wp_set_current_user( self::$admin_user_id ); 2017 2185 $default_value = 'foo_default'; 2018 $setting = $this->manager->add_setting( 'foo', array( 2019 'validate_callback' => array( $this, 'filter_customize_validate_foo' ), 2020 'sanitize_callback' => array( $this, 'filter_customize_sanitize_foo' ), 2021 ) ); 2186 $setting = $this->manager->add_setting( 2187 'foo', array( 2188 'validate_callback' => array( $this, 'filter_customize_validate_foo' ), 2189 'sanitize_callback' => array( $this, 'filter_customize_sanitize_foo' ), 2190 ) 2191 ); 2022 2192 $this->assertEquals( $default_value, $this->manager->post_value( $setting, $default_value ) ); 2023 2193 $this->assertEquals( $default_value, $setting->post_value( $default_value ) ); … … 2082 2252 wp_set_current_user( self::$admin_user_id ); 2083 2253 $default_value = '0'; 2084 $setting = $this->manager->add_setting( 'numeric', array( 2085 'validate_callback' => array( $this, 'filter_customize_validate_numeric' ), 2086 'sanitize_callback' => array( $this, 'filter_customize_sanitize_numeric' ), 2087 ) ); 2254 $setting = $this->manager->add_setting( 2255 'numeric', array( 2256 'validate_callback' => array( $this, 'filter_customize_validate_numeric' ), 2257 'sanitize_callback' => array( $this, 'filter_customize_sanitize_numeric' ), 2258 ) 2259 ); 2088 2260 $this->assertEquals( $default_value, $this->manager->post_value( $setting, $default_value ) ); 2089 2261 $this->assertEquals( $default_value, $setting->post_value( $default_value ) ); … … 2126 2298 function test_validate_setting_values() { 2127 2299 wp_set_current_user( self::$admin_user_id ); 2128 $setting = $this->manager->add_setting( 'foo', array( 2129 'validate_callback' => array( $this, 'filter_customize_validate_foo' ), 2130 'sanitize_callback' => array( $this, 'filter_customize_sanitize_foo' ), 2131 ) ); 2300 $setting = $this->manager->add_setting( 2301 'foo', array( 2302 'validate_callback' => array( $this, 'filter_customize_validate_foo' ), 2303 'sanitize_callback' => array( $this, 'filter_customize_sanitize_foo' ), 2304 ) 2305 ); 2132 2306 2133 2307 $post_value = 'bar'; … … 2185 2359 $this->assertTrue( $setting->validate( 'bad' ) ); 2186 2360 $setting_validities = $this->manager->validate_setting_values( array( $setting->id => 'bad' ) ); 2187 $validity = $setting_validities[ $setting->id ];2361 $validity = $setting_validities[ $setting->id ]; 2188 2362 $this->assertInstanceOf( 'WP_Error', $validity ); 2189 2363 $this->assertEquals( 'minlength', $validity->get_error_code() ); … … 2249 2423 function test_validate_setting_values_validation_sanitization_order() { 2250 2424 wp_set_current_user( self::$admin_user_id ); 2251 $setting = $this->manager->add_setting( 'numeric', array( 2252 'validate_callback' => array( $this, 'filter_customize_validate_numeric' ), 2253 'sanitize_callback' => array( $this, 'filter_customize_sanitize_numeric' ), 2254 ) ); 2425 $setting = $this->manager->add_setting( 2426 'numeric', array( 2427 'validate_callback' => array( $this, 'filter_customize_validate_numeric' ), 2428 'sanitize_callback' => array( $this, 'filter_customize_sanitize_numeric' ), 2429 ) 2430 ); 2255 2431 $post_value = '42'; 2256 2432 $this->manager->set_post_value( 'numeric', $post_value ); … … 2291 2467 function test_set_post_value() { 2292 2468 wp_set_current_user( self::$admin_user_id ); 2293 $this->manager->add_setting( 'foo', array( 2294 'sanitize_callback' => array( $this, 'sanitize_foo_for_test_set_post_value' ), 2295 ) ); 2469 $this->manager->add_setting( 2470 'foo', array( 2471 'sanitize_callback' => array( $this, 'sanitize_foo_for_test_set_post_value' ), 2472 ) 2473 ); 2296 2474 $setting = $this->manager->get_setting( 'foo' ); 2297 2475 … … 2340 2518 function capture_customize_post_value_set_actions() { 2341 2519 $action = current_action(); 2342 $args = func_get_args();2520 $args = func_get_args(); 2343 2521 $this->captured_customize_post_value_set_actions[] = compact( 'action', 'args' ); 2344 2522 } … … 2350 2528 */ 2351 2529 function test_add_dynamic_settings() { 2352 $manager = $this->manager;2530 $manager = $this->manager; 2353 2531 $setting_ids = array( 'foo', 'bar' ); 2354 2532 $manager->add_setting( 'foo', array( 'default' => 'foo_default' ) ); … … 2376 2554 $this->assertFalse( $this->manager->has_published_pages() ); 2377 2555 2378 $this->factory()->post->create( array( 'post_type' => 'page', 'post_status' => 'private' ) ); 2556 $this->factory()->post->create( 2557 array( 2558 'post_type' => 'page', 2559 'post_status' => 'private', 2560 ) 2561 ); 2379 2562 $this->assertFalse( $this->manager->has_published_pages() ); 2380 2563 2381 $this->factory()->post->create( array( 'post_type' => 'page', 'post_status' => 'publish' ) ); 2564 $this->factory()->post->create( 2565 array( 2566 'post_type' => 'page', 2567 'post_status' => 'publish', 2568 ) 2569 ); 2382 2570 $this->assertTrue( $this->manager->has_published_pages() ); 2383 2571 } … … 2398 2586 $this->manager->nav_menus->customize_register(); 2399 2587 $setting_id = 'nav_menus_created_posts'; 2400 $setting = $this->manager->get_setting( $setting_id );2588 $setting = $this->manager->get_setting( $setting_id ); 2401 2589 $this->assertInstanceOf( 'WP_Customize_Filter_Setting', $setting ); 2402 $auto_draft_page = $this->factory()->post->create( array( 'post_type' => 'page', 'post_status' => 'auto-draft' ) ); 2590 $auto_draft_page = $this->factory()->post->create( 2591 array( 2592 'post_type' => 'page', 2593 'post_status' => 'auto-draft', 2594 ) 2595 ); 2403 2596 $this->manager->set_post_value( $setting_id, array( $auto_draft_page ) ); 2404 2597 $setting->preview(); … … 2415 2608 function test_register_dynamic_settings() { 2416 2609 wp_set_current_user( self::$admin_user_id ); 2417 $posted_settings = array(2610 $posted_settings = array( 2418 2611 'foo' => 'OOF', 2419 2612 'bar' => 'RAB', … … 2520 2713 $this->assertEquals( $preview_url, $this->manager->get_return_url() ); 2521 2714 2522 $url = home_url( '/referred/' );2715 $url = home_url( '/referred/' ); 2523 2716 $_SERVER['HTTP_REFERER'] = wp_slash( $url ); 2524 2717 $this->assertEquals( $url, $this->manager->get_return_url() ); 2525 2718 2526 $url = 'http://badreferer.example.com/';2719 $url = 'http://badreferer.example.com/'; 2527 2720 $_SERVER['HTTP_REFERER'] = wp_slash( $url ); 2528 2721 $this->assertNotEquals( $url, $this->manager->get_return_url() ); … … 2767 2960 $section_id = 'foo-section'; 2768 2961 wp_set_current_user( self::$admin_user_id ); 2769 $manager->add_section( $section_id, array( 2770 'title' => 'Section', 2771 'priority' => 1, 2772 ) ); 2962 $manager->add_section( 2963 $section_id, array( 2964 'title' => 'Section', 2965 'priority' => 1, 2966 ) 2967 ); 2773 2968 2774 2969 $added_control_ids = array(); 2775 $count = 9;2970 $count = 9; 2776 2971 for ( $i = 0; $i < $count; $i += 1 ) { 2777 $id = 'sort-test-' . $i;2972 $id = 'sort-test-' . $i; 2778 2973 $added_control_ids[] = $id; 2779 2974 $manager->add_setting( $id ); 2780 $control = new WP_Customize_Control( $manager, $id, array( 2781 'section' => $section_id, 2782 'priority' => 1, 2783 'setting' => $id, 2784 ) ); 2975 $control = new WP_Customize_Control( 2976 $manager, $id, array( 2977 'section' => $section_id, 2978 'priority' => 1, 2979 'setting' => $id, 2980 ) 2981 ); 2785 2982 $manager->add_control( $control ); 2786 2983 } … … 2799 2996 wp_set_current_user( self::$admin_user_id ); 2800 2997 2801 $section_id = 'foo-section'; 2802 $result_section = $manager->add_section( $section_id, array( 2803 'title' => 'Section', 2804 'priority' => 1, 2805 ) ); 2998 $section_id = 'foo-section'; 2999 $result_section = $manager->add_section( 3000 $section_id, array( 3001 'title' => 'Section', 3002 'priority' => 1, 3003 ) 3004 ); 2806 3005 2807 3006 $this->assertInstanceOf( 'WP_Customize_Section', $result_section ); 2808 3007 $this->assertEquals( $section_id, $result_section->id ); 2809 3008 2810 $section = new WP_Customize_Section( $manager, $section_id, array( 2811 'title' => 'Section 2', 2812 'priority' => 2, 2813 ) ); 3009 $section = new WP_Customize_Section( 3010 $manager, $section_id, array( 3011 'title' => 'Section 2', 3012 'priority' => 2, 3013 ) 3014 ); 2814 3015 $result_section = $manager->add_section( $section ); 2815 3016 … … 2826 3027 wp_set_current_user( self::$admin_user_id ); 2827 3028 2828 $setting_id = 'foo-setting';3029 $setting_id = 'foo-setting'; 2829 3030 $result_setting = $manager->add_setting( $setting_id ); 2830 3031 … … 2832 3033 $this->assertEquals( $setting_id, $result_setting->id ); 2833 3034 2834 $setting = new WP_Customize_Setting( $manager, $setting_id );3035 $setting = new WP_Customize_Setting( $manager, $setting_id ); 2835 3036 $result_setting = $manager->add_setting( $setting ); 2836 3037 … … 2847 3048 2848 3049 $setting_id = 'dynamic'; 2849 $setting = $manager->add_setting( $setting_id );3050 $setting = $manager->add_setting( $setting_id ); 2850 3051 $this->assertEquals( 'WP_Customize_Setting', get_class( $setting ) ); 2851 3052 $this->assertObjectNotHasAttribute( 'custom', $setting ); … … 2897 3098 wp_set_current_user( self::$admin_user_id ); 2898 3099 2899 $panel_id = 'foo-panel'; 2900 $result_panel = $manager->add_panel( $panel_id, array( 2901 'title' => 'Test Panel', 2902 'priority' => 2, 2903 ) ); 3100 $panel_id = 'foo-panel'; 3101 $result_panel = $manager->add_panel( 3102 $panel_id, array( 3103 'title' => 'Test Panel', 3104 'priority' => 2, 3105 ) 3106 ); 2904 3107 2905 3108 $this->assertInstanceOf( 'WP_Customize_Panel', $result_panel ); 2906 3109 $this->assertEquals( $panel_id, $result_panel->id ); 2907 3110 2908 $panel = new WP_Customize_Panel( $manager, $panel_id, array( 2909 'title' => 'Test Panel 2', 2910 ) ); 3111 $panel = new WP_Customize_Panel( 3112 $manager, $panel_id, array( 3113 'title' => 'Test Panel 2', 3114 ) 3115 ); 2911 3116 $result_panel = $manager->add_panel( $panel ); 2912 3117 … … 2920 3125 */ 2921 3126 function test_add_control_return_instance() { 2922 $manager = new WP_Customize_Manager();3127 $manager = new WP_Customize_Manager(); 2923 3128 $section_id = 'foo-section'; 2924 3129 wp_set_current_user( self::$admin_user_id ); 2925 $manager->add_section( $section_id, array( 2926 'title' => 'Section', 2927 'priority' => 1, 2928 ) ); 3130 $manager->add_section( 3131 $section_id, array( 3132 'title' => 'Section', 3133 'priority' => 1, 3134 ) 3135 ); 2929 3136 2930 3137 $control_id = 'foo-control'; 2931 3138 $manager->add_setting( $control_id ); 2932 3139 2933 $result_control = $manager->add_control( $control_id, array( 2934 'section' => $section_id, 2935 'priority' => 1, 2936 'setting' => $control_id, 2937 ) ); 3140 $result_control = $manager->add_control( 3141 $control_id, array( 3142 'section' => $section_id, 3143 'priority' => 1, 3144 'setting' => $control_id, 3145 ) 3146 ); 2938 3147 $this->assertInstanceOf( 'WP_Customize_Control', $result_control ); 2939 3148 $this->assertEquals( $control_id, $result_control->id ); 2940 3149 2941 $control = new WP_Customize_Control( $manager, $control_id, array( 2942 'section' => $section_id, 2943 'priority' => 1, 2944 'setting' => $control_id, 2945 ) ); 3150 $control = new WP_Customize_Control( 3151 $manager, $control_id, array( 3152 'section' => $section_id, 3153 'priority' => 1, 3154 'setting' => $control_id, 3155 ) 3156 ); 2946 3157 $result_control = $manager->add_control( $control ); 2947 3158 … … 2997 3208 return array( 2998 3209 'custom-device' => array( 2999 'label' => __( 'Enter custom-device preview mode' ),3210 'label' => __( 'Enter custom-device preview mode' ), 3000 3211 'default' => true, 3001 3212 ), … … 3020 3231 wp_set_current_user( self::$admin_user_id ); 3021 3232 3022 $controls = array( 'foo' => 2, 'bar' => 4, 'foobar' => 3, 'key' => 1 ); 3233 $controls = array( 3234 'foo' => 2, 3235 'bar' => 4, 3236 'foobar' => 3, 3237 'key' => 1, 3238 ); 3023 3239 $controls_sorted = array( 'key', 'foo', 'foobar', 'bar' ); 3024 3240 … … 3027 3243 foreach ( $controls as $control_id => $priority ) { 3028 3244 $this->manager->add_setting( $control_id ); 3029 $this->manager->add_control( $control_id, array( 3030 'priority' => $priority, 3031 'section' => 'foosection', 3032 ) ); 3245 $this->manager->add_control( 3246 $control_id, array( 3247 'priority' => $priority, 3248 'section' => 'foosection', 3249 ) 3250 ); 3033 3251 } 3034 3252 … … 3045 3263 wp_set_current_user( self::$admin_user_id ); 3046 3264 3047 $sections = array( 'foo' => 2, 'bar' => 4, 'foobar' => 3, 'key' => 1 ); 3265 $sections = array( 3266 'foo' => 2, 3267 'bar' => 4, 3268 'foobar' => 3, 3269 'key' => 1, 3270 ); 3048 3271 $sections_sorted = array( 'key', 'foo', 'foobar', 'bar' ); 3049 3272 3050 3273 foreach ( $sections as $section_id => $priority ) { 3051 $this->manager->add_section( $section_id, array( 3052 'priority' => $priority, 3053 ) ); 3274 $this->manager->add_section( 3275 $section_id, array( 3276 'priority' => $priority, 3277 ) 3278 ); 3054 3279 } 3055 3280 … … 3066 3291 wp_set_current_user( self::$admin_user_id ); 3067 3292 3068 $panels = array( 'foo' => 2, 'bar' => 4, 'foobar' => 3, 'key' => 1 ); 3293 $panels = array( 3294 'foo' => 2, 3295 'bar' => 4, 3296 'foobar' => 3, 3297 'key' => 1, 3298 ); 3069 3299 $panels_sorted = array( 'key', 'foo', 'foobar', 'bar' ); 3070 3300 3071 3301 foreach ( $panels as $panel_id => $priority ) { 3072 $this->manager->add_panel( $panel_id, array( 3073 'priority' => $priority, 3074 ) ); 3302 $this->manager->add_panel( 3303 $panel_id, array( 3304 'priority' => $priority, 3305 ) 3306 ); 3075 3307 } 3076 3308 … … 3088 3320 function test_sanitize_external_header_video_trim() { 3089 3321 $this->manager->register_controls(); 3090 $setting = $this->manager->get_setting( 'external_header_video' );3322 $setting = $this->manager->get_setting( 'external_header_video' ); 3091 3323 $video_url = 'https://www.youtube.com/watch?v=KiS8rZBeIO0'; 3092 3324 … … 3100 3332 ); 3101 3333 3102 foreach ( $whitespaces as $whitespace 3334 foreach ( $whitespaces as $whitespace ) { 3103 3335 $sanitized = $setting->sanitize( $whitespace . $video_url . $whitespace ); 3104 3336 $this->assertEquals( $video_url, $sanitized );
Note: See TracChangeset
for help on using the changeset viewer.