forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrol.php
More file actions
180 lines (164 loc) · 4.92 KB
/
control.php
File metadata and controls
180 lines (164 loc) · 4.92 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<?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();
wp_set_current_user( $this->factory()->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()
*/
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
*/
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->assertNotContains( '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->assertContains( '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->assertContains( '<option value="0">', $content, 'Dropdown-pages renders select even without any pages published.' );
// Ensure that auto-draft pages are included if they are among the nav_menus_created_posts.
$auto_draft_page_id = $this->factory()->post->create(
array(
'post_type' => 'page',
'post_status' => 'auto-draft',
'post_title' => 'Auto Draft Page',
)
);
$this->factory()->post->create(
array(
'post_type' => 'page',
'post_status' => 'auto-draft',
'post_title' => 'Orphan Auto Draft Page',
)
);
$auto_draft_post_id = $this->factory()->post->create(
array(
'post_type' => 'post',
'post_status' => 'auto-draft',
'post_title' => 'Auto Draft Post',
)
);
$this->wp_customize->set_post_value( $nav_menus_created_posts_setting->id, array( $auto_draft_page_id, $auto_draft_post_id ) );
$nav_menus_created_posts_setting->preview();
ob_start();
$page_on_front_control->maybe_render();
$content = ob_get_clean();
$this->assertContains( sprintf( '<option value="%d">Auto Draft Page</option>', $auto_draft_page_id ), $content );
$this->assertNotContains( 'Auto Draft Post', $content );
$this->assertNotContains( 'Orphan Auto Draft Page', $content );
}
/**
* Tear down.
*/
function tearDown() {
$this->wp_customize = null;
unset( $GLOBALS['wp_customize'] );
parent::tearDown();
}
}