mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 12:20:22 +00:00
Customizer: Export nonce, theme, and url app settings in preview as exported in pane.
* Introduce `WP_Customize_Manager::get_nonces()` to consolidate logic for retrieving nonces. * Export nonces centrally in `wp.customize.settings.nonce` with each request and update nav menus preview to utilize. * Send updated nonces to preview upon `nonce-refresh`. * Request full preview refresh if Nav Menu selective refresh request fails (e.g. due to bad nonce). * Update nav menus and widgets in Customizer to utilize `customize_refresh_nonces` for exporting nonces and keeping them up to date. See #27355. Fixes #35617. git-svn-id: https://develop.svn.wordpress.org/trunk@36414 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -368,6 +368,36 @@ class Tests_WP_Customize_Manager extends WP_UnitTestCase {
|
||||
$this->assertEmpty( $this->manager->get_autofocus() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get_nonces() method.
|
||||
*
|
||||
* @see WP_Customize_Manager::get_nonces()
|
||||
*/
|
||||
function test_nonces() {
|
||||
$nonces = $this->manager->get_nonces();
|
||||
$this->assertInternalType( 'array', $nonces );
|
||||
$this->assertArrayHasKey( 'save', $nonces );
|
||||
$this->assertArrayHasKey( 'preview', $nonces );
|
||||
|
||||
add_filter( 'customize_refresh_nonces', array( $this, 'filter_customize_refresh_nonces' ), 10, 2 );
|
||||
$nonces = $this->manager->get_nonces();
|
||||
$this->assertArrayHasKey( 'foo', $nonces );
|
||||
$this->assertEquals( wp_create_nonce( 'foo' ), $nonces['foo'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter for customize_refresh_nonces.
|
||||
*
|
||||
* @param array $nonces Nonces.
|
||||
* @param WP_Customize_Manager $manager Manager.
|
||||
* @return array Nonces.
|
||||
*/
|
||||
function filter_customize_refresh_nonces( $nonces, $manager ) {
|
||||
$this->assertInstanceOf( 'WP_Customize_Manager', $manager );
|
||||
$nonces['foo'] = wp_create_nonce( 'foo' );
|
||||
return $nonces;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test customize_pane_settings() method.
|
||||
*
|
||||
@@ -401,6 +431,38 @@ class Tests_WP_Customize_Manager extends WP_UnitTestCase {
|
||||
$this->assertArrayHasKey( 'preview', $data['nonce'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test customize_preview_settings() method.
|
||||
*
|
||||
* @see WP_Customize_Manager::customize_preview_settings()
|
||||
*/
|
||||
function test_customize_preview_settings() {
|
||||
wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
|
||||
$this->manager->register_controls();
|
||||
$this->manager->prepare_controls();
|
||||
$this->manager->set_post_value( 'foo', 'bar' );
|
||||
$_POST['customize_messenger_channel'] = 'preview-0';
|
||||
|
||||
ob_start();
|
||||
$this->manager->customize_preview_settings();
|
||||
$content = ob_get_clean();
|
||||
|
||||
$this->assertEquals( 1, preg_match( '/var _wpCustomizeSettings = ({.+});/', $content, $matches ) );
|
||||
$settings = json_decode( $matches[1], true );
|
||||
|
||||
$this->assertArrayHasKey( 'theme', $settings );
|
||||
$this->assertArrayHasKey( 'url', $settings );
|
||||
$this->assertArrayHasKey( 'channel', $settings );
|
||||
$this->assertArrayHasKey( 'activePanels', $settings );
|
||||
$this->assertArrayHasKey( 'activeSections', $settings );
|
||||
$this->assertArrayHasKey( 'activeControls', $settings );
|
||||
$this->assertArrayHasKey( 'nonce', $settings );
|
||||
$this->assertArrayHasKey( '_dirty', $settings );
|
||||
|
||||
$this->assertArrayHasKey( 'preview', $settings['nonce'] );
|
||||
$this->assertEquals( array( 'foo' ), $settings['_dirty'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 33552
|
||||
*/
|
||||
|
||||
@@ -647,12 +647,6 @@ class Test_WP_Customize_Nav_Menus extends WP_UnitTestCase {
|
||||
$this->assertContains( 'renderQueryVar', $data );
|
||||
$this->assertContains( 'renderNonceValue', $data );
|
||||
$this->assertContains( 'renderNoncePostKey', $data );
|
||||
$this->assertContains( 'requestUri', $data );
|
||||
$this->assertContains( 'theme', $data );
|
||||
$this->assertContains( 'previewCustomizeNonce', $data );
|
||||
$this->assertContains( 'navMenuInstanceArgs', $data );
|
||||
$this->assertContains( 'requestUri', $data );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user