user->create( array( 'role' => 'administrator' ) ) );
require_once ABSPATH . WPINC . '/class-wp-customize-manager.php';
$GLOBALS['wp_customize'] = new WP_Customize_Manager();
$this->wp_customize = $GLOBALS['wp_customize'];
}
/**
* Test WP_Customize_Control::check_capabilities().
*
* @see WP_Customize_Control::check_capabilities()
*/
public function test_check_capabilities() {
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() );
}
/**
* @ticket 38164
*/
public function test_dropdown_pages() {
do_action( 'customize_register', $this->wp_customize );
$this->assertInstanceOf( 'WP_Customize_Nav_Menus', $this->wp_customize->nav_menus );
$nav_menus_created_posts_setting = $this->wp_customize->get_setting( 'nav_menus_created_posts' );
$this->assertInstanceOf( 'WP_Customize_Filter_Setting', $nav_menus_created_posts_setting );
$page_on_front_control = $this->wp_customize->get_control( 'page_on_front' );
// Ensure the add-new-toggle is absent if allow_addition param is not set.
$page_on_front_control->allow_addition = false;
ob_start();
$page_on_front_control->maybe_render();
$content = ob_get_clean();
$this->assertStringNotContainsString( 'add-new-toggle', $content );
// Ensure the add-new-toggle is absent if allow_addition param is set.
$page_on_front_control->allow_addition = true;
ob_start();
$page_on_front_control->maybe_render();
$content = ob_get_clean();
$this->assertStringContainsString( 'add-new-toggle', $content );
// Ensure that dropdown-pages delect is rendered even if there are no pages published (yet).
foreach ( get_pages() as $page ) {
wp_delete_post( $page->ID );
}
$page_on_front_control->allow_addition = true;
ob_start();
$page_on_front_control->maybe_render();
$content = ob_get_clean();
$this->assertStringContainsString( '', $auto_draft_page_id ), $content );
$this->assertStringNotContainsString( 'Auto Draft Post', $content );
$this->assertStringNotContainsString( 'Orphan Auto Draft Page', $content );
}
/**
* Tear down.
*/
public function tear_down() {
$this->wp_customize = null;
unset( $GLOBALS['wp_customize'] );
parent::tear_down();
}
}