mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 20:30:23 +00:00
User Settings: allow dashes in get|set_user_setting() in PHP and get|setUserSetting() in JS.
Add unit tests - there were none. Mock `set_user_setting()` since it won't run due to `headers_sent()` being `true`. Fixes #22781. git-svn-id: https://develop.svn.wordpress.org/trunk@33840 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
class Tests_User_Settings extends WP_UnitTestCase {
|
||||
protected $user_id;
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->user_id = $this->factory->user->create( array(
|
||||
'role' => 'administrator'
|
||||
) );
|
||||
|
||||
wp_set_current_user( $this->user_id );
|
||||
}
|
||||
|
||||
function tearDown() {
|
||||
unset( $GLOBALS['_updated_user_settings'] );
|
||||
delete_user_option( $this->user_id, 'user-settings' );
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
function test_set_user_setting() {
|
||||
$foo = get_user_setting( 'foo' );
|
||||
|
||||
$this->assertEmpty( $foo );
|
||||
|
||||
$this->set_user_setting( 'foo', 'bar' );
|
||||
|
||||
$this->assertEquals( 'bar', get_user_setting( 'foo' ) );
|
||||
}
|
||||
|
||||
function test_set_user_setting_dashes() {
|
||||
$foo = get_user_setting( 'foo' );
|
||||
|
||||
$this->assertEmpty( $foo );
|
||||
|
||||
$this->set_user_setting( 'foo', 'foo-bar' );
|
||||
|
||||
$this->assertEquals( 'foo-bar', get_user_setting( 'foo' ) );
|
||||
}
|
||||
|
||||
// set_user_setting bails if `headers_sent()` is true
|
||||
function set_user_setting( $name, $value ) {
|
||||
$all_user_settings = get_all_user_settings();
|
||||
$all_user_settings[ $name ] = $value;
|
||||
|
||||
return wp_set_all_user_settings( $all_user_settings );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user