forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanager.php
More file actions
75 lines (63 loc) · 2.23 KB
/
manager.php
File metadata and controls
75 lines (63 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
/**
* Tests for the WP_Customize_Manager class.
*
* @group customize
*/
class Tests_WP_Customize_Manager extends WP_UnitTestCase {
function setUp() {
parent::setUp();
require_once( ABSPATH . WPINC . '/class-wp-customize-manager.php' );
$GLOBALS['wp_customize'] = new WP_Customize_Manager();
$this->manager = $GLOBALS['wp_customize'];
$this->undefined = new stdClass();
}
function tearDown() {
$this->manager = null;
unset( $GLOBALS['wp_customize'] );
parent::tearDown();
}
/**
* Instantiate class, set global $wp_customize, and return instance.
*
* @return WP_Customize_Manager
*/
function instantiate() {
$GLOBALS['wp_customize'] = new WP_Customize_Manager();
return $GLOBALS['wp_customize'];
}
/**
* Test WP_Customize_Manager::unsanitized_post_values()
*
* @ticket 30988
*/
function test_unsanitized_post_values() {
$manager = $this->instantiate();
$customized = array(
'foo' => 'bar',
'baz[quux]' => 123,
);
$_POST['customized'] = wp_slash( wp_json_encode( $customized ) );
$post_values = $manager->unsanitized_post_values();
$this->assertEquals( $customized, $post_values );
}
/**
* Test the WP_Customize_Manager::post_value() method
*
* @ticket 30988
*/
function test_post_value() {
$posted_settings = array(
'foo' => 'OOF',
);
$_POST['customized'] = wp_slash( wp_json_encode( $posted_settings ) );
$manager = $this->instantiate();
$manager->add_setting( 'foo', array( 'default' => 'foo_default' ) );
$foo_setting = $manager->get_setting( 'foo' );
$this->assertEquals( 'foo_default', $manager->get_setting( 'foo' )->value(), 'Expected non-previewed setting to return default when value() method called.' );
$this->assertEquals( $posted_settings['foo'], $manager->post_value( $foo_setting, 'post_value_foo_default' ), 'Expected post_value($foo_setting) to return value supplied in $_POST[customized][foo]' );
$manager->add_setting( 'bar', array( 'default' => 'bar_default' ) );
$bar_setting = $manager->get_setting( 'bar' );
$this->assertEquals( 'post_value_bar_default', $manager->post_value( $bar_setting, 'post_value_bar_default' ), 'Expected post_value($bar_setting, $default) to return $default since no value supplied in $_POST[customized][bar]' );
}
}