mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 14:20:15 +00:00
Customize: Allow controls to be registered without any associated settings.
* Improves parity between partials and controls. A partial or control can be settingless if instantiated with `settings` param as empty array (otherwise, if null, then the partial/control ID is used). * Eliminate need to create dummy settings that serve no purpose except to place a control in the UI. * Removes dummy settings for `create_new_menu` and `new_menu_name`. * Introduces `WP_Customize_Control::$capability` and `WP_Customize_Partial::$capability`, and if set checks them in the respective `check_capabilities()` methods. * Prevents PHP fatal error from happening when non-existing settings are provided to control: "Call to a member function `check_capabilities()` on a non-object". * Fixes issue where nav menu items and widgets were no longer working with selective refresh because cap check was failing. See #27355. Fixes #35926. git-svn-id: https://develop.svn.wordpress.org/trunk@36689 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
88
tests/phpunit/tests/customize/control.php
Normal file
88
tests/phpunit/tests/customize/control.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
/**
|
||||
* Test_WP_Customize_Control tests.
|
||||
*
|
||||
* @package WordPress
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests for the Test_WP_Customize_Control class.
|
||||
*
|
||||
* @todo This is missing dedicated tests for all but one of the methods.
|
||||
*
|
||||
* @group customize
|
||||
*/
|
||||
class Test_WP_Customize_Control extends WP_UnitTestCase {
|
||||
|
||||
/**
|
||||
* Manager.
|
||||
*
|
||||
* @var WP_Customize_Manager
|
||||
*/
|
||||
public $wp_customize;
|
||||
|
||||
/**
|
||||
* Set up.
|
||||
*/
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
require_once( ABSPATH . WPINC . '/class-wp-customize-manager.php' );
|
||||
// @codingStandardsIgnoreStart
|
||||
$GLOBALS['wp_customize'] = new WP_Customize_Manager();
|
||||
// @codingStandardsIgnoreEnd
|
||||
$this->wp_customize = $GLOBALS['wp_customize'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test WP_Customize_Control::check_capabilities().
|
||||
*
|
||||
* @see WP_Customize_Control::check_capabilities()
|
||||
*/
|
||||
function test_check_capabilities() {
|
||||
wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
|
||||
do_action( 'customize_register', $this->wp_customize );
|
||||
$control = new WP_Customize_Control( $this->wp_customize, 'blogname', array(
|
||||
'settings' => array( 'blogname' ),
|
||||
) );
|
||||
$this->assertTrue( $control->check_capabilities() );
|
||||
|
||||
$control = new WP_Customize_Control( $this->wp_customize, 'blogname', array(
|
||||
'settings' => array( 'blogname', 'non_existing' ),
|
||||
) );
|
||||
$this->assertFalse( $control->check_capabilities() );
|
||||
|
||||
$this->wp_customize->add_setting( 'top_secret_message', array(
|
||||
'capability' => 'top_secret_clearance',
|
||||
) );
|
||||
$control = new WP_Customize_Control( $this->wp_customize, 'blogname', array(
|
||||
'settings' => array( 'blogname', 'top_secret_clearance' ),
|
||||
) );
|
||||
$this->assertFalse( $control->check_capabilities() );
|
||||
|
||||
$control = new WP_Customize_Control( $this->wp_customize, 'no_setting', array(
|
||||
'settings' => array(),
|
||||
) );
|
||||
$this->assertTrue( $control->check_capabilities() );
|
||||
|
||||
$control = new WP_Customize_Control( $this->wp_customize, 'no_setting', array(
|
||||
'settings' => array(),
|
||||
'capability' => 'top_secret_clearance',
|
||||
) );
|
||||
$this->assertFalse( $control->check_capabilities() );
|
||||
|
||||
$control = new WP_Customize_Control( $this->wp_customize, 'no_setting', array(
|
||||
'settings' => array(),
|
||||
'capability' => 'edit_theme_options',
|
||||
) );
|
||||
$this->assertTrue( $control->check_capabilities() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Tear down.
|
||||
*/
|
||||
function tearDown() {
|
||||
$this->wp_customize = null;
|
||||
unset( $GLOBALS['wp_customize'] );
|
||||
parent::tearDown();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user