@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | |
15 | 15 | function setUp() { |
16 | 16 | parent::setUp(); |
17 | - require_once( WP_FIELDS_API_DIR . 'implementation/wp-includes/class-wp-customize-manager.php' ); |
|
17 | + require_once(WP_FIELDS_API_DIR.'implementation/wp-includes/class-wp-customize-manager.php'); |
|
18 | 18 | //require_once( ABSPATH . WPINC . '/class-wp-customize-manager.php' ); |
19 | 19 | $GLOBALS['wp_customize'] = new WP_Customize_Manager(); |
20 | 20 | $this->manager = $GLOBALS['wp_customize']; |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | |
24 | 24 | function tearDown() { |
25 | 25 | $this->manager = null; |
26 | - unset( $GLOBALS['wp_customize'] ); |
|
26 | + unset($GLOBALS['wp_customize']); |
|
27 | 27 | parent::tearDown(); |
28 | 28 | } |
29 | 29 | |
@@ -31,18 +31,18 @@ discard block |
||
31 | 31 | * @see WP_Customize_Section::__construct() |
32 | 32 | */ |
33 | 33 | function test_construct_default_args() { |
34 | - $section = new WP_Customize_Section( $this->manager, 'foo' ); |
|
35 | - $this->assertInternalType( 'int', $section->instance_number ); |
|
36 | - $this->assertEquals( $this->manager, $section->manager ); |
|
37 | - $this->assertEquals( 'foo', $section->id ); |
|
38 | - $this->assertEquals( 160, $section->priority ); |
|
39 | - $this->assertEquals( 'edit_theme_options', $section->capability ); |
|
40 | - $this->assertEquals( '', $section->theme_supports ); |
|
41 | - $this->assertEquals( '', $section->title ); |
|
42 | - $this->assertEquals( '', $section->description ); |
|
43 | - $this->assertEmpty( $section->panel ); |
|
44 | - $this->assertEquals( 'default', $section->type ); |
|
45 | - $this->assertEquals( array( $section, 'active_callback' ), $section->active_callback ); |
|
34 | + $section = new WP_Customize_Section($this->manager, 'foo'); |
|
35 | + $this->assertInternalType('int', $section->instance_number); |
|
36 | + $this->assertEquals($this->manager, $section->manager); |
|
37 | + $this->assertEquals('foo', $section->id); |
|
38 | + $this->assertEquals(160, $section->priority); |
|
39 | + $this->assertEquals('edit_theme_options', $section->capability); |
|
40 | + $this->assertEquals('', $section->theme_supports); |
|
41 | + $this->assertEquals('', $section->title); |
|
42 | + $this->assertEquals('', $section->description); |
|
43 | + $this->assertEmpty($section->panel); |
|
44 | + $this->assertEquals('default', $section->type); |
|
45 | + $this->assertEquals(array($section, 'active_callback'), $section->active_callback); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
@@ -60,11 +60,11 @@ discard block |
||
60 | 60 | 'panel' => 'bar', |
61 | 61 | ); |
62 | 62 | |
63 | - $this->manager->add_panel( 'bar' ); |
|
63 | + $this->manager->add_panel('bar'); |
|
64 | 64 | |
65 | - $section = new WP_Customize_Section( $this->manager, 'foo', $args ); |
|
66 | - foreach ( $args as $key => $value ) { |
|
67 | - $this->assertEquals( $value, $section->$key ); |
|
65 | + $section = new WP_Customize_Section($this->manager, 'foo', $args); |
|
66 | + foreach ($args as $key => $value) { |
|
67 | + $this->assertEquals($value, $section->$key); |
|
68 | 68 | } |
69 | 69 | } |
70 | 70 | |
@@ -72,8 +72,8 @@ discard block |
||
72 | 72 | * @see WP_Customize_Section::__construct() |
73 | 73 | */ |
74 | 74 | function test_construct_custom_type() { |
75 | - $section = new Custom_Section_Test( $this->manager, 'foo' ); |
|
76 | - $this->assertEquals( 'titleless', $section->type ); |
|
75 | + $section = new Custom_Section_Test($this->manager, 'foo'); |
|
76 | + $this->assertEquals('titleless', $section->type); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
@@ -81,15 +81,15 @@ discard block |
||
81 | 81 | * @see WP_Customize_Section::active_callback() |
82 | 82 | */ |
83 | 83 | function test_active() { |
84 | - $section = new WP_Customize_Section( $this->manager, 'foo' ); |
|
85 | - $this->assertTrue( $section->active() ); |
|
84 | + $section = new WP_Customize_Section($this->manager, 'foo'); |
|
85 | + $this->assertTrue($section->active()); |
|
86 | 86 | |
87 | - $section = new WP_Customize_Section( $this->manager, 'foo', array( |
|
87 | + $section = new WP_Customize_Section($this->manager, 'foo', array( |
|
88 | 88 | 'active_callback' => '__return_false', |
89 | - ) ); |
|
90 | - $this->assertFalse( $section->active() ); |
|
91 | - add_filter( 'customize_section_active', array( $this, 'filter_active_test' ), 10, 2 ); |
|
92 | - $this->assertTrue( $section->active() ); |
|
89 | + )); |
|
90 | + $this->assertFalse($section->active()); |
|
91 | + add_filter('customize_section_active', array($this, 'filter_active_test'), 10, 2); |
|
92 | + $this->assertTrue($section->active()); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
@@ -97,9 +97,9 @@ discard block |
||
97 | 97 | * @param WP_Customize_Section $section |
98 | 98 | * @return bool |
99 | 99 | */ |
100 | - function filter_active_test( $active, $section ) { |
|
101 | - $this->assertFalse( $active ); |
|
102 | - $this->assertInstanceOf( 'WP_Customize_Section', $section ); |
|
100 | + function filter_active_test($active, $section) { |
|
101 | + $this->assertFalse($active); |
|
102 | + $this->assertInstanceOf('WP_Customize_Section', $section); |
|
103 | 103 | $active = true; |
104 | 104 | return $active; |
105 | 105 | } |
@@ -119,102 +119,102 @@ discard block |
||
119 | 119 | 'active_callback' => '__return_true', |
120 | 120 | ); |
121 | 121 | |
122 | - $this->manager->add_panel( 'bar' ); |
|
122 | + $this->manager->add_panel('bar'); |
|
123 | 123 | |
124 | - $section = new WP_Customize_Section( $this->manager, 'foo', $args ); |
|
124 | + $section = new WP_Customize_Section($this->manager, 'foo', $args); |
|
125 | 125 | $data = $section->json(); |
126 | - $this->assertEquals( 'foo', $data['id'] ); |
|
127 | - foreach ( array( 'title', 'description', 'priority', 'panel', 'type' ) as $key ) { |
|
128 | - $this->assertEquals( $args[ $key ], $data[ $key ] ); |
|
126 | + $this->assertEquals('foo', $data['id']); |
|
127 | + foreach (array('title', 'description', 'priority', 'panel', 'type') as $key) { |
|
128 | + $this->assertEquals($args[$key], $data[$key]); |
|
129 | 129 | } |
130 | - $this->assertEmpty( $data['content'] ); |
|
131 | - $this->assertTrue( $data['active'] ); |
|
132 | - $this->assertInternalType( 'int', $data['instanceNumber'] ); |
|
130 | + $this->assertEmpty($data['content']); |
|
131 | + $this->assertTrue($data['active']); |
|
132 | + $this->assertInternalType('int', $data['instanceNumber']); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | /** |
136 | 136 | * @see WP_Customize_Section::check_capabilities() |
137 | 137 | */ |
138 | 138 | function test_check_capabilities() { |
139 | - $user_id = $this->factory->user->create( array( 'role' => 'administrator' ) ); |
|
140 | - wp_set_current_user( $user_id ); |
|
139 | + $user_id = $this->factory->user->create(array('role' => 'administrator')); |
|
140 | + wp_set_current_user($user_id); |
|
141 | 141 | |
142 | - $section = new WP_Customize_Section( $this->manager, 'foo' ); |
|
143 | - $this->assertTrue( $section->check_capabilities() ); |
|
142 | + $section = new WP_Customize_Section($this->manager, 'foo'); |
|
143 | + $this->assertTrue($section->check_capabilities()); |
|
144 | 144 | $old_cap = $section->capability; |
145 | 145 | $section->capability = 'do_not_allow'; |
146 | - $this->assertFalse( $section->check_capabilities() ); |
|
146 | + $this->assertFalse($section->check_capabilities()); |
|
147 | 147 | $section->capability = $old_cap; |
148 | - $this->assertTrue( $section->check_capabilities() ); |
|
148 | + $this->assertTrue($section->check_capabilities()); |
|
149 | 149 | $section->theme_supports = 'impossible_feature'; |
150 | - $this->assertFalse( $section->check_capabilities() ); |
|
150 | + $this->assertFalse($section->check_capabilities()); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | /** |
154 | 154 | * @see WP_Customize_Section::get_content() |
155 | 155 | */ |
156 | 156 | function test_get_content() { |
157 | - $section = new WP_Customize_Section( $this->manager, 'foo' ); |
|
158 | - $this->assertEmpty( $section->get_content() ); |
|
157 | + $section = new WP_Customize_Section($this->manager, 'foo'); |
|
158 | + $this->assertEmpty($section->get_content()); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | /** |
162 | 162 | * @see WP_Customize_Section::maybe_render() |
163 | 163 | */ |
164 | 164 | function test_maybe_render() { |
165 | - wp_set_current_user( $this->factory->user->create( array( 'role' => 'administrator' ) ) ); |
|
166 | - $section = new WP_Customize_Section( $this->manager, 'bar' ); |
|
167 | - $customize_render_section_count = did_action( 'customize_render_section' ); |
|
168 | - add_action( 'customize_render_section', array( $this, 'action_customize_render_section_test' ) ); |
|
165 | + wp_set_current_user($this->factory->user->create(array('role' => 'administrator'))); |
|
166 | + $section = new WP_Customize_Section($this->manager, 'bar'); |
|
167 | + $customize_render_section_count = did_action('customize_render_section'); |
|
168 | + add_action('customize_render_section', array($this, 'action_customize_render_section_test')); |
|
169 | 169 | ob_start(); |
170 | 170 | $section->maybe_render(); |
171 | 171 | $content = ob_get_clean(); |
172 | - $this->assertTrue( $section->check_capabilities() ); |
|
173 | - $this->assertEmpty( $content ); |
|
174 | - $this->assertEquals( $customize_render_section_count + 1, did_action( 'customize_render_section' ), 'Unexpected did_action count for customize_render_section' ); |
|
175 | - $this->assertEquals( 1, did_action( "customize_render_section_{$section->id}" ), "Unexpected did_action count for customize_render_section_{$section->id}" ); |
|
172 | + $this->assertTrue($section->check_capabilities()); |
|
173 | + $this->assertEmpty($content); |
|
174 | + $this->assertEquals($customize_render_section_count + 1, did_action('customize_render_section'), 'Unexpected did_action count for customize_render_section'); |
|
175 | + $this->assertEquals(1, did_action("customize_render_section_{$section->id}"), "Unexpected did_action count for customize_render_section_{$section->id}"); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
179 | 179 | * @see WP_Customize_Section::maybe_render() |
180 | 180 | * @param WP_Customize_Section $section |
181 | 181 | */ |
182 | - function action_customize_render_section_test( $section ) { |
|
183 | - $this->assertInstanceOf( 'WP_Customize_Section', $section ); |
|
182 | + function action_customize_render_section_test($section) { |
|
183 | + $this->assertInstanceOf('WP_Customize_Section', $section); |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | /** |
187 | 187 | * @see WP_Customize_Section::print_template() |
188 | 188 | */ |
189 | 189 | function test_print_templates_standard() { |
190 | - wp_set_current_user( $this->factory->user->create( array( 'role' => 'administrator' ) ) ); |
|
190 | + wp_set_current_user($this->factory->user->create(array('role' => 'administrator'))); |
|
191 | 191 | |
192 | - $section = new WP_Customize_Section( $this->manager, 'baz' ); |
|
192 | + $section = new WP_Customize_Section($this->manager, 'baz'); |
|
193 | 193 | ob_start(); |
194 | 194 | $section->print_template(); |
195 | 195 | $content = ob_get_clean(); |
196 | - $this->assertContains( '<script type="text/html" id="tmpl-customize-section-default">', $content ); |
|
197 | - $this->assertContains( 'accordion-section-title', $content ); |
|
198 | - $this->assertContains( 'accordion-section-content', $content ); |
|
196 | + $this->assertContains('<script type="text/html" id="tmpl-customize-section-default">', $content); |
|
197 | + $this->assertContains('accordion-section-title', $content); |
|
198 | + $this->assertContains('accordion-section-content', $content); |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | /** |
202 | 202 | * @see WP_Customize_Section::print_template() |
203 | 203 | */ |
204 | 204 | function test_print_templates_custom() { |
205 | - wp_set_current_user( $this->factory->user->create( array( 'role' => 'administrator' ) ) ); |
|
205 | + wp_set_current_user($this->factory->user->create(array('role' => 'administrator'))); |
|
206 | 206 | |
207 | - $section = new Custom_Section_Test( $this->manager, 'baz' ); |
|
207 | + $section = new Custom_Section_Test($this->manager, 'baz'); |
|
208 | 208 | ob_start(); |
209 | 209 | $section->print_template(); |
210 | 210 | $content = ob_get_clean(); |
211 | - $this->assertContains( '<script type="text/html" id="tmpl-customize-section-titleless">', $content ); |
|
212 | - $this->assertNotContains( 'accordion-section-title', $content ); |
|
213 | - $this->assertContains( 'accordion-section-content', $content ); |
|
211 | + $this->assertContains('<script type="text/html" id="tmpl-customize-section-titleless">', $content); |
|
212 | + $this->assertNotContains('accordion-section-title', $content); |
|
213 | + $this->assertContains('accordion-section-content', $content); |
|
214 | 214 | } |
215 | 215 | } |
216 | 216 | |
217 | -require_once( WP_FIELDS_API_DIR . 'implementation/wp-includes/class-wp-customize-section.php' ); |
|
217 | +require_once(WP_FIELDS_API_DIR.'implementation/wp-includes/class-wp-customize-section.php'); |
|
218 | 218 | //require_once ABSPATH . WPINC . '/class-wp-customize-section.php'; |
219 | 219 | class Custom_Section_Test extends WP_Customize_Section { |
220 | 220 | public $type = 'titleless'; |
@@ -21,9 +21,9 @@ discard block |
||
21 | 21 | */ |
22 | 22 | function setUp() { |
23 | 23 | parent::setUp(); |
24 | - require_once( WP_FIELDS_API_DIR . 'implementation/wp-includes/class-wp-customize-manager.php' ); |
|
24 | + require_once(WP_FIELDS_API_DIR.'implementation/wp-includes/class-wp-customize-manager.php'); |
|
25 | 25 | //require_once ABSPATH . WPINC . '/class-wp-customize-manager.php'; |
26 | - wp_set_current_user( $this->factory->user->create( array( 'role' => 'administrator' ) ) ); |
|
26 | + wp_set_current_user($this->factory->user->create(array('role' => 'administrator'))); |
|
27 | 27 | |
28 | 28 | global $wp_customize; |
29 | 29 | $this->wp_customize = new WP_Customize_Manager(); |
@@ -45,15 +45,15 @@ discard block |
||
45 | 45 | * @return array |
46 | 46 | */ |
47 | 47 | function get_nav_menu_items_option() { |
48 | - return get_option( 'nav_menu_options', array( 'auto_add' => array() ) ); |
|
48 | + return get_option('nav_menu_options', array('auto_add' => array())); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
52 | 52 | * Test constants and statics. |
53 | 53 | */ |
54 | 54 | function test_constants() { |
55 | - do_action( 'customize_register', $this->wp_customize ); |
|
56 | - $this->assertTrue( taxonomy_exists( WP_Customize_Nav_Menu_Setting::TAXONOMY ) ); |
|
55 | + do_action('customize_register', $this->wp_customize); |
|
56 | + $this->assertTrue(taxonomy_exists(WP_Customize_Nav_Menu_Setting::TAXONOMY)); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
@@ -62,49 +62,49 @@ discard block |
||
62 | 62 | * @see WP_Customize_Nav_Menu_Setting::__construct() |
63 | 63 | */ |
64 | 64 | function test_construct() { |
65 | - do_action( 'customize_register', $this->wp_customize ); |
|
66 | - |
|
67 | - $setting = new WP_Customize_Nav_Menu_Setting( $this->wp_customize, 'nav_menu[123]' ); |
|
68 | - $this->assertEquals( 'nav_menu', $setting->type ); |
|
69 | - $this->assertEquals( 'postMessage', $setting->transport ); |
|
70 | - $this->assertEquals( 123, $setting->term_id ); |
|
71 | - $this->assertNull( $setting->previous_term_id ); |
|
72 | - $this->assertNull( $setting->update_status ); |
|
73 | - $this->assertNull( $setting->update_error ); |
|
74 | - $this->assertInternalType( 'array', $setting->default ); |
|
75 | - foreach ( array( 'name', 'description', 'parent' ) as $key ) { |
|
76 | - $this->assertArrayHasKey( $key, $setting->default ); |
|
65 | + do_action('customize_register', $this->wp_customize); |
|
66 | + |
|
67 | + $setting = new WP_Customize_Nav_Menu_Setting($this->wp_customize, 'nav_menu[123]'); |
|
68 | + $this->assertEquals('nav_menu', $setting->type); |
|
69 | + $this->assertEquals('postMessage', $setting->transport); |
|
70 | + $this->assertEquals(123, $setting->term_id); |
|
71 | + $this->assertNull($setting->previous_term_id); |
|
72 | + $this->assertNull($setting->update_status); |
|
73 | + $this->assertNull($setting->update_error); |
|
74 | + $this->assertInternalType('array', $setting->default); |
|
75 | + foreach (array('name', 'description', 'parent') as $key) { |
|
76 | + $this->assertArrayHasKey($key, $setting->default); |
|
77 | 77 | } |
78 | - $this->assertEquals( '', $setting->default['name'] ); |
|
79 | - $this->assertEquals( '', $setting->default['description'] ); |
|
80 | - $this->assertEquals( 0, $setting->default['parent'] ); |
|
78 | + $this->assertEquals('', $setting->default['name']); |
|
79 | + $this->assertEquals('', $setting->default['description']); |
|
80 | + $this->assertEquals(0, $setting->default['parent']); |
|
81 | 81 | |
82 | 82 | $exception = null; |
83 | 83 | try { |
84 | - $bad_setting = new WP_Customize_Nav_Menu_Setting( $this->wp_customize, 'foo_bar_baz' ); |
|
85 | - unset( $bad_setting ); |
|
86 | - } catch ( Exception $e ) { |
|
84 | + $bad_setting = new WP_Customize_Nav_Menu_Setting($this->wp_customize, 'foo_bar_baz'); |
|
85 | + unset($bad_setting); |
|
86 | + } catch (Exception $e) { |
|
87 | 87 | $exception = $e; |
88 | 88 | } |
89 | - $this->assertInstanceOf( 'Exception', $exception ); |
|
89 | + $this->assertInstanceOf('Exception', $exception); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
93 | 93 | * Test empty constructor. |
94 | 94 | */ |
95 | 95 | function test_construct_empty_menus() { |
96 | - do_action( 'customize_register', $this->wp_customize ); |
|
96 | + do_action('customize_register', $this->wp_customize); |
|
97 | 97 | $_wp_customize = $this->wp_customize; |
98 | - unset( $_wp_customize->nav_menus ); |
|
98 | + unset($_wp_customize->nav_menus); |
|
99 | 99 | |
100 | 100 | $exception = null; |
101 | 101 | try { |
102 | - $bad_setting = new WP_Customize_Nav_Menu_Setting( $_wp_customize, 'nav_menu_item[123]' ); |
|
103 | - unset( $bad_setting ); |
|
104 | - } catch ( Exception $e ) { |
|
102 | + $bad_setting = new WP_Customize_Nav_Menu_Setting($_wp_customize, 'nav_menu_item[123]'); |
|
103 | + unset($bad_setting); |
|
104 | + } catch (Exception $e) { |
|
105 | 105 | $exception = $e; |
106 | 106 | } |
107 | - $this->assertInstanceOf( 'Exception', $exception ); |
|
107 | + $this->assertInstanceOf('Exception', $exception); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
@@ -113,15 +113,15 @@ discard block |
||
113 | 113 | * @see WP_Customize_Nav_Menu_Setting::__construct() |
114 | 114 | */ |
115 | 115 | function test_construct_placeholder() { |
116 | - do_action( 'customize_register', $this->wp_customize ); |
|
116 | + do_action('customize_register', $this->wp_customize); |
|
117 | 117 | $default = array( |
118 | 118 | 'name' => 'Lorem', |
119 | 119 | 'description' => 'ipsum', |
120 | 120 | 'parent' => 123, |
121 | 121 | ); |
122 | - $setting = new WP_Customize_Nav_Menu_Setting( $this->wp_customize, 'nav_menu[-5]', compact( 'default' ) ); |
|
122 | + $setting = new WP_Customize_Nav_Menu_Setting($this->wp_customize, 'nav_menu[-5]', compact('default')); |
|
123 | 123 | $this->assertEquals( -5, $setting->term_id ); |
124 | - $this->assertEquals( $default, $setting->default ); |
|
124 | + $this->assertEquals($default, $setting->default); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
@@ -130,33 +130,33 @@ discard block |
||
130 | 130 | * @see WP_Customize_Nav_Menu_Setting::value() |
131 | 131 | */ |
132 | 132 | function test_value() { |
133 | - do_action( 'customize_register', $this->wp_customize ); |
|
133 | + do_action('customize_register', $this->wp_customize); |
|
134 | 134 | |
135 | 135 | $menu_name = 'Test 123'; |
136 | - $parent_menu_id = wp_create_nav_menu( "Parent $menu_name" ); |
|
136 | + $parent_menu_id = wp_create_nav_menu("Parent $menu_name"); |
|
137 | 137 | $description = 'Hello my world.'; |
138 | - $menu_id = wp_update_nav_menu_object( 0, array( |
|
138 | + $menu_id = wp_update_nav_menu_object(0, array( |
|
139 | 139 | 'menu-name' => $menu_name, |
140 | 140 | 'parent' => $parent_menu_id, |
141 | 141 | 'description' => $description, |
142 | - ) ); |
|
142 | + )); |
|
143 | 143 | |
144 | 144 | $setting_id = "nav_menu[$menu_id]"; |
145 | - $setting = new WP_Customize_Nav_Menu_Setting( $this->wp_customize, $setting_id ); |
|
145 | + $setting = new WP_Customize_Nav_Menu_Setting($this->wp_customize, $setting_id); |
|
146 | 146 | |
147 | 147 | $value = $setting->value(); |
148 | - $this->assertInternalType( 'array', $value ); |
|
149 | - foreach ( array( 'name', 'description', 'parent' ) as $key ) { |
|
150 | - $this->assertArrayHasKey( $key, $value ); |
|
148 | + $this->assertInternalType('array', $value); |
|
149 | + foreach (array('name', 'description', 'parent') as $key) { |
|
150 | + $this->assertArrayHasKey($key, $value); |
|
151 | 151 | } |
152 | - $this->assertEquals( $menu_name, $value['name'] ); |
|
153 | - $this->assertEquals( $description, $value['description'] ); |
|
154 | - $this->assertEquals( $parent_menu_id, $value['parent'] ); |
|
152 | + $this->assertEquals($menu_name, $value['name']); |
|
153 | + $this->assertEquals($description, $value['description']); |
|
154 | + $this->assertEquals($parent_menu_id, $value['parent']); |
|
155 | 155 | |
156 | 156 | $new_menu_name = 'Foo'; |
157 | - wp_update_nav_menu_object( $menu_id, array( 'menu-name' => $new_menu_name ) ); |
|
157 | + wp_update_nav_menu_object($menu_id, array('menu-name' => $new_menu_name)); |
|
158 | 158 | $updated_value = $setting->value(); |
159 | - $this->assertEquals( $new_menu_name, $updated_value['name'] ); |
|
159 | + $this->assertEquals($new_menu_name, $updated_value['name']); |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | /** |
@@ -165,18 +165,18 @@ discard block |
||
165 | 165 | * @see WP_Customize_Nav_Menu_Setting::preview() |
166 | 166 | */ |
167 | 167 | function test_preview_updated() { |
168 | - do_action( 'customize_register', $this->wp_customize ); |
|
168 | + do_action('customize_register', $this->wp_customize); |
|
169 | 169 | |
170 | - $menu_id = wp_update_nav_menu_object( 0, array( |
|
170 | + $menu_id = wp_update_nav_menu_object(0, array( |
|
171 | 171 | 'menu-name' => 'Name 1', |
172 | 172 | 'description' => 'Description 1', |
173 | 173 | 'parent' => 0, |
174 | - ) ); |
|
174 | + )); |
|
175 | 175 | $setting_id = "nav_menu[$menu_id]"; |
176 | - $setting = new WP_Customize_Nav_Menu_Setting( $this->wp_customize, $setting_id ); |
|
176 | + $setting = new WP_Customize_Nav_Menu_Setting($this->wp_customize, $setting_id); |
|
177 | 177 | |
178 | 178 | $nav_menu_options = $this->get_nav_menu_items_option(); |
179 | - $this->assertNotContains( $menu_id, $nav_menu_options['auto_add'] ); |
|
179 | + $this->assertNotContains($menu_id, $nav_menu_options['auto_add']); |
|
180 | 180 | |
181 | 181 | $post_value = array( |
182 | 182 | 'name' => 'Name 2', |
@@ -184,41 +184,41 @@ discard block |
||
184 | 184 | 'parent' => 1, |
185 | 185 | 'auto_add' => true, |
186 | 186 | ); |
187 | - $this->wp_customize->set_post_value( $setting_id, $post_value ); |
|
187 | + $this->wp_customize->set_post_value($setting_id, $post_value); |
|
188 | 188 | |
189 | 189 | $value = $setting->value(); |
190 | - $this->assertEquals( 'Name 1', $value['name'] ); |
|
191 | - $this->assertEquals( 'Description 1', $value['description'] ); |
|
192 | - $this->assertEquals( 0, $value['parent'] ); |
|
190 | + $this->assertEquals('Name 1', $value['name']); |
|
191 | + $this->assertEquals('Description 1', $value['description']); |
|
192 | + $this->assertEquals(0, $value['parent']); |
|
193 | 193 | |
194 | - $term = (array) wp_get_nav_menu_object( $menu_id ); |
|
194 | + $term = (array) wp_get_nav_menu_object($menu_id); |
|
195 | 195 | |
196 | 196 | $this->assertEqualSets( |
197 | - wp_array_slice_assoc( $value, array( 'name', 'description', 'parent' ) ), |
|
198 | - wp_array_slice_assoc( $term, array( 'name', 'description', 'parent' ) ) |
|
197 | + wp_array_slice_assoc($value, array('name', 'description', 'parent')), |
|
198 | + wp_array_slice_assoc($term, array('name', 'description', 'parent')) |
|
199 | 199 | ); |
200 | 200 | |
201 | 201 | $setting->preview(); |
202 | 202 | $value = $setting->value(); |
203 | - $this->assertEquals( 'Name 2', $value['name'] ); |
|
204 | - $this->assertEquals( 'Description 2', $value['description'] ); |
|
205 | - $this->assertEquals( 1, $value['parent'] ); |
|
206 | - $term = (array) wp_get_nav_menu_object( $menu_id ); |
|
207 | - $this->assertEqualSets( $value, wp_array_slice_assoc( $term, array_keys( $value ) ) ); |
|
203 | + $this->assertEquals('Name 2', $value['name']); |
|
204 | + $this->assertEquals('Description 2', $value['description']); |
|
205 | + $this->assertEquals(1, $value['parent']); |
|
206 | + $term = (array) wp_get_nav_menu_object($menu_id); |
|
207 | + $this->assertEqualSets($value, wp_array_slice_assoc($term, array_keys($value))); |
|
208 | 208 | |
209 | - $menu_object = wp_get_nav_menu_object( $menu_id ); |
|
210 | - $this->assertEquals( (object) $term, $menu_object ); |
|
211 | - $this->assertEquals( $post_value['name'], $menu_object->name ); |
|
209 | + $menu_object = wp_get_nav_menu_object($menu_id); |
|
210 | + $this->assertEquals((object) $term, $menu_object); |
|
211 | + $this->assertEquals($post_value['name'], $menu_object->name); |
|
212 | 212 | |
213 | - $nav_menu_options = get_option( 'nav_menu_options', array( 'auto_add' => array() ) ); |
|
214 | - $this->assertContains( $menu_id, $nav_menu_options['auto_add'] ); |
|
213 | + $nav_menu_options = get_option('nav_menu_options', array('auto_add' => array())); |
|
214 | + $this->assertContains($menu_id, $nav_menu_options['auto_add']); |
|
215 | 215 | |
216 | 216 | $menus = wp_get_nav_menus(); |
217 | - $menus_ids = wp_list_pluck( $menus, 'term_id' ); |
|
218 | - $i = array_search( $menu_id, $menus_ids ); |
|
219 | - $this->assertInternalType( 'int', $i, 'Update-previewed menu does not appear in wp_get_nav_menus()' ); |
|
220 | - $filtered_menu = $menus[ $i ]; |
|
221 | - $this->assertEquals( 'Name 2', $filtered_menu->name ); |
|
217 | + $menus_ids = wp_list_pluck($menus, 'term_id'); |
|
218 | + $i = array_search($menu_id, $menus_ids); |
|
219 | + $this->assertInternalType('int', $i, 'Update-previewed menu does not appear in wp_get_nav_menus()'); |
|
220 | + $filtered_menu = $menus[$i]; |
|
221 | + $this->assertEquals('Name 2', $filtered_menu->name); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | /** |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | * @see WP_Customize_Nav_Menu_Setting::preview() |
228 | 228 | */ |
229 | 229 | function test_preview_inserted() { |
230 | - do_action( 'customize_register', $this->wp_customize ); |
|
230 | + do_action('customize_register', $this->wp_customize); |
|
231 | 231 | |
232 | 232 | $menu_id = -123; |
233 | 233 | $post_value = array( |
@@ -237,33 +237,33 @@ discard block |
||
237 | 237 | 'auto_add' => false, |
238 | 238 | ); |
239 | 239 | $setting_id = "nav_menu[$menu_id]"; |
240 | - $setting = new WP_Customize_Nav_Menu_Setting( $this->wp_customize, $setting_id ); |
|
240 | + $setting = new WP_Customize_Nav_Menu_Setting($this->wp_customize, $setting_id); |
|
241 | 241 | |
242 | - $this->wp_customize->set_post_value( $setting->id, $post_value ); |
|
242 | + $this->wp_customize->set_post_value($setting->id, $post_value); |
|
243 | 243 | $setting->preview(); |
244 | 244 | $value = $setting->value(); |
245 | - $this->assertEquals( $post_value, $value ); |
|
245 | + $this->assertEquals($post_value, $value); |
|
246 | 246 | |
247 | - $term = (array) wp_get_nav_menu_object( $menu_id ); |
|
248 | - $this->assertNotEmpty( $term ); |
|
249 | - $this->assertNotInstanceOf( 'WP_Error', $term ); |
|
250 | - $this->assertEqualSets( $post_value, wp_array_slice_assoc( $term, array_keys( $value ) ) ); |
|
251 | - $this->assertEquals( $menu_id, $term['term_id'] ); |
|
252 | - $this->assertEquals( $menu_id, $term['term_taxonomy_id'] ); |
|
247 | + $term = (array) wp_get_nav_menu_object($menu_id); |
|
248 | + $this->assertNotEmpty($term); |
|
249 | + $this->assertNotInstanceOf('WP_Error', $term); |
|
250 | + $this->assertEqualSets($post_value, wp_array_slice_assoc($term, array_keys($value))); |
|
251 | + $this->assertEquals($menu_id, $term['term_id']); |
|
252 | + $this->assertEquals($menu_id, $term['term_taxonomy_id']); |
|
253 | 253 | |
254 | - $menu_object = wp_get_nav_menu_object( $menu_id ); |
|
255 | - $this->assertEquals( (object) $term, $menu_object ); |
|
256 | - $this->assertEquals( $post_value['name'], $menu_object->name ); |
|
254 | + $menu_object = wp_get_nav_menu_object($menu_id); |
|
255 | + $this->assertEquals((object) $term, $menu_object); |
|
256 | + $this->assertEquals($post_value['name'], $menu_object->name); |
|
257 | 257 | |
258 | 258 | $nav_menu_options = $this->get_nav_menu_items_option(); |
259 | - $this->assertNotContains( $menu_id, $nav_menu_options['auto_add'] ); |
|
259 | + $this->assertNotContains($menu_id, $nav_menu_options['auto_add']); |
|
260 | 260 | |
261 | 261 | $menus = wp_get_nav_menus(); |
262 | - $menus_ids = wp_list_pluck( $menus, 'term_id' ); |
|
263 | - $i = array_search( $menu_id, $menus_ids ); |
|
264 | - $this->assertInternalType( 'int', $i, 'Insert-previewed menu was not injected into wp_get_nav_menus()' ); |
|
265 | - $filtered_menu = $menus[ $i ]; |
|
266 | - $this->assertEquals( 'New Menu Name 1', $filtered_menu->name ); |
|
262 | + $menus_ids = wp_list_pluck($menus, 'term_id'); |
|
263 | + $i = array_search($menu_id, $menus_ids); |
|
264 | + $this->assertInternalType('int', $i, 'Insert-previewed menu was not injected into wp_get_nav_menus()'); |
|
265 | + $filtered_menu = $menus[$i]; |
|
266 | + $this->assertEquals('New Menu Name 1', $filtered_menu->name); |
|
267 | 267 | } |
268 | 268 | |
269 | 269 | /** |
@@ -272,32 +272,32 @@ discard block |
||
272 | 272 | * @see WP_Customize_Nav_Menu_Setting::preview() |
273 | 273 | */ |
274 | 274 | function test_preview_deleted() { |
275 | - do_action( 'customize_register', $this->wp_customize ); |
|
275 | + do_action('customize_register', $this->wp_customize); |
|
276 | 276 | |
277 | - $menu_id = wp_update_nav_menu_object( 0, array( |
|
277 | + $menu_id = wp_update_nav_menu_object(0, array( |
|
278 | 278 | 'menu-name' => 'Name 1', |
279 | 279 | 'description' => 'Description 1', |
280 | 280 | 'parent' => 0, |
281 | - ) ); |
|
281 | + )); |
|
282 | 282 | $setting_id = "nav_menu[$menu_id]"; |
283 | - $setting = new WP_Customize_Nav_Menu_Setting( $this->wp_customize, $setting_id ); |
|
283 | + $setting = new WP_Customize_Nav_Menu_Setting($this->wp_customize, $setting_id); |
|
284 | 284 | $nav_menu_options = $this->get_nav_menu_items_option(); |
285 | 285 | $nav_menu_options['auto_add'][] = $menu_id; |
286 | - update_option( 'nav_menu_options', $nav_menu_options ); |
|
286 | + update_option('nav_menu_options', $nav_menu_options); |
|
287 | 287 | |
288 | 288 | $nav_menu_options = $this->get_nav_menu_items_option(); |
289 | - $this->assertContains( $menu_id, $nav_menu_options['auto_add'] ); |
|
289 | + $this->assertContains($menu_id, $nav_menu_options['auto_add']); |
|
290 | 290 | |
291 | - $this->wp_customize->set_post_value( $setting_id, false ); |
|
291 | + $this->wp_customize->set_post_value($setting_id, false); |
|
292 | 292 | |
293 | - $this->assertInternalType( 'array', $setting->value() ); |
|
294 | - $this->assertInternalType( 'object', wp_get_nav_menu_object( $menu_id ) ); |
|
293 | + $this->assertInternalType('array', $setting->value()); |
|
294 | + $this->assertInternalType('object', wp_get_nav_menu_object($menu_id)); |
|
295 | 295 | $setting->preview(); |
296 | - $this->assertFalse( $setting->value() ); |
|
297 | - $this->assertFalse( wp_get_nav_menu_object( $menu_id ) ); |
|
296 | + $this->assertFalse($setting->value()); |
|
297 | + $this->assertFalse(wp_get_nav_menu_object($menu_id)); |
|
298 | 298 | |
299 | 299 | $nav_menu_options = $this->get_nav_menu_items_option(); |
300 | - $this->assertNotContains( $menu_id, $nav_menu_options['auto_add'] ); |
|
300 | + $this->assertNotContains($menu_id, $nav_menu_options['auto_add']); |
|
301 | 301 | } |
302 | 302 | |
303 | 303 | /** |
@@ -306,11 +306,11 @@ discard block |
||
306 | 306 | * @see WP_Customize_Nav_Menu_Setting::sanitize() |
307 | 307 | */ |
308 | 308 | function test_sanitize() { |
309 | - do_action( 'customize_register', $this->wp_customize ); |
|
310 | - $setting = new WP_Customize_Nav_Menu_Setting( $this->wp_customize, 'nav_menu[123]' ); |
|
309 | + do_action('customize_register', $this->wp_customize); |
|
310 | + $setting = new WP_Customize_Nav_Menu_Setting($this->wp_customize, 'nav_menu[123]'); |
|
311 | 311 | |
312 | - $this->assertNull( $setting->sanitize( 'not an array' ) ); |
|
313 | - $this->assertNull( $setting->sanitize( 123 ) ); |
|
312 | + $this->assertNull($setting->sanitize('not an array')); |
|
313 | + $this->assertNull($setting->sanitize(123)); |
|
314 | 314 | |
315 | 315 | $value = array( |
316 | 316 | 'name' => ' Hello <b>world</b> ', |
@@ -319,16 +319,16 @@ discard block |
||
319 | 319 | 'auto_add' => true, |
320 | 320 | 'extra' => 'ignored', |
321 | 321 | ); |
322 | - $sanitized = $setting->sanitize( $value ); |
|
323 | - $this->assertEquals( 'Hello <b>world</b>', $sanitized['name'] ); |
|
324 | - $this->assertEquals( 'New line', $sanitized['description'] ); |
|
325 | - $this->assertEquals( 0, $sanitized['parent'] ); |
|
326 | - $this->assertEquals( true, $sanitized['auto_add'] ); |
|
327 | - $this->assertEqualSets( array( 'name', 'description', 'parent', 'auto_add' ), array_keys( $sanitized ) ); |
|
322 | + $sanitized = $setting->sanitize($value); |
|
323 | + $this->assertEquals('Hello <b>world</b>', $sanitized['name']); |
|
324 | + $this->assertEquals('New line', $sanitized['description']); |
|
325 | + $this->assertEquals(0, $sanitized['parent']); |
|
326 | + $this->assertEquals(true, $sanitized['auto_add']); |
|
327 | + $this->assertEqualSets(array('name', 'description', 'parent', 'auto_add'), array_keys($sanitized)); |
|
328 | 328 | |
329 | 329 | $value['name'] = ' '; // Blank spaces. |
330 | - $sanitized = $setting->sanitize( $value ); |
|
331 | - $this->assertEquals( '(unnamed)', $sanitized['name'] ); |
|
330 | + $sanitized = $setting->sanitize($value); |
|
331 | + $this->assertEquals('(unnamed)', $sanitized['name']); |
|
332 | 332 | } |
333 | 333 | |
334 | 334 | /** |
@@ -337,19 +337,19 @@ discard block |
||
337 | 337 | * @see WP_Customize_Nav_Menu_Setting::update() |
338 | 338 | */ |
339 | 339 | function test_save_updated() { |
340 | - do_action( 'customize_register', $this->wp_customize ); |
|
340 | + do_action('customize_register', $this->wp_customize); |
|
341 | 341 | |
342 | - $menu_id = wp_update_nav_menu_object( 0, array( |
|
342 | + $menu_id = wp_update_nav_menu_object(0, array( |
|
343 | 343 | 'menu-name' => 'Name 1', |
344 | 344 | 'description' => 'Description 1', |
345 | 345 | 'parent' => 0, |
346 | - ) ); |
|
346 | + )); |
|
347 | 347 | $nav_menu_options = $this->get_nav_menu_items_option(); |
348 | 348 | $nav_menu_options['auto_add'][] = $menu_id; |
349 | - update_option( 'nav_menu_options', $nav_menu_options ); |
|
349 | + update_option('nav_menu_options', $nav_menu_options); |
|
350 | 350 | |
351 | 351 | $setting_id = "nav_menu[$menu_id]"; |
352 | - $setting = new WP_Customize_Nav_Menu_Setting( $this->wp_customize, $setting_id ); |
|
352 | + $setting = new WP_Customize_Nav_Menu_Setting($this->wp_customize, $setting_id); |
|
353 | 353 | |
354 | 354 | $auto_add = false; |
355 | 355 | $new_value = array( |
@@ -359,36 +359,36 @@ discard block |
||
359 | 359 | 'auto_add' => $auto_add, |
360 | 360 | ); |
361 | 361 | |
362 | - $this->wp_customize->set_post_value( $setting_id, $new_value ); |
|
362 | + $this->wp_customize->set_post_value($setting_id, $new_value); |
|
363 | 363 | $setting->save(); |
364 | 364 | |
365 | - $menu_object = wp_get_nav_menu_object( $menu_id ); |
|
366 | - foreach ( array( 'name', 'description', 'parent' ) as $key ) { |
|
367 | - $this->assertEquals( $new_value[ $key ], $menu_object->$key ); |
|
365 | + $menu_object = wp_get_nav_menu_object($menu_id); |
|
366 | + foreach (array('name', 'description', 'parent') as $key) { |
|
367 | + $this->assertEquals($new_value[$key], $menu_object->$key); |
|
368 | 368 | } |
369 | 369 | $this->assertEqualSets( |
370 | - wp_array_slice_assoc( $new_value, array( 'name', 'description', 'parent' ) ), |
|
371 | - wp_array_slice_assoc( (array) $menu_object, array( 'name', 'description', 'parent' ) ) |
|
370 | + wp_array_slice_assoc($new_value, array('name', 'description', 'parent')), |
|
371 | + wp_array_slice_assoc((array) $menu_object, array('name', 'description', 'parent')) |
|
372 | 372 | ); |
373 | - $this->assertEquals( $new_value, $setting->value() ); |
|
374 | - |
|
375 | - $save_response = apply_filters( 'customize_save_response', array() ); |
|
376 | - $this->assertArrayHasKey( 'nav_menu_updates', $save_response ); |
|
377 | - $update_result = array_shift( $save_response['nav_menu_updates'] ); |
|
378 | - $this->assertArrayHasKey( 'term_id', $update_result ); |
|
379 | - $this->assertArrayHasKey( 'previous_term_id', $update_result ); |
|
380 | - $this->assertArrayHasKey( 'error', $update_result ); |
|
381 | - $this->assertArrayHasKey( 'status', $update_result ); |
|
382 | - $this->assertArrayHasKey( 'saved_value', $update_result ); |
|
383 | - $this->assertEquals( $new_value, $update_result['saved_value'] ); |
|
384 | - |
|
385 | - $this->assertEquals( $menu_id, $update_result['term_id'] ); |
|
386 | - $this->assertNull( $update_result['previous_term_id'] ); |
|
387 | - $this->assertNull( $update_result['error'] ); |
|
388 | - $this->assertEquals( 'updated', $update_result['status'] ); |
|
373 | + $this->assertEquals($new_value, $setting->value()); |
|
374 | + |
|
375 | + $save_response = apply_filters('customize_save_response', array()); |
|
376 | + $this->assertArrayHasKey('nav_menu_updates', $save_response); |
|
377 | + $update_result = array_shift($save_response['nav_menu_updates']); |
|
378 | + $this->assertArrayHasKey('term_id', $update_result); |
|
379 | + $this->assertArrayHasKey('previous_term_id', $update_result); |
|
380 | + $this->assertArrayHasKey('error', $update_result); |
|
381 | + $this->assertArrayHasKey('status', $update_result); |
|
382 | + $this->assertArrayHasKey('saved_value', $update_result); |
|
383 | + $this->assertEquals($new_value, $update_result['saved_value']); |
|
384 | + |
|
385 | + $this->assertEquals($menu_id, $update_result['term_id']); |
|
386 | + $this->assertNull($update_result['previous_term_id']); |
|
387 | + $this->assertNull($update_result['error']); |
|
388 | + $this->assertEquals('updated', $update_result['status']); |
|
389 | 389 | |
390 | 390 | $nav_menu_options = $this->get_nav_menu_items_option(); |
391 | - $this->assertNotContains( $menu_id, $nav_menu_options['auto_add'] ); |
|
391 | + $this->assertNotContains($menu_id, $nav_menu_options['auto_add']); |
|
392 | 392 | } |
393 | 393 | |
394 | 394 | /** |
@@ -397,7 +397,7 @@ discard block |
||
397 | 397 | * @see WP_Customize_Nav_Menu_Setting::update() |
398 | 398 | */ |
399 | 399 | function test_save_inserted() { |
400 | - do_action( 'customize_register', $this->wp_customize ); |
|
400 | + do_action('customize_register', $this->wp_customize); |
|
401 | 401 | |
402 | 402 | $menu_id = -123; |
403 | 403 | $post_value = array( |
@@ -407,37 +407,37 @@ discard block |
||
407 | 407 | 'auto_add' => true, |
408 | 408 | ); |
409 | 409 | $setting_id = "nav_menu[$menu_id]"; |
410 | - $setting = new WP_Customize_Nav_Menu_Setting( $this->wp_customize, $setting_id ); |
|
410 | + $setting = new WP_Customize_Nav_Menu_Setting($this->wp_customize, $setting_id); |
|
411 | 411 | |
412 | - $this->wp_customize->set_post_value( $setting->id, $post_value ); |
|
412 | + $this->wp_customize->set_post_value($setting->id, $post_value); |
|
413 | 413 | |
414 | - $this->assertNull( $setting->previous_term_id ); |
|
415 | - $this->assertLessThan( 0, $setting->term_id ); |
|
414 | + $this->assertNull($setting->previous_term_id); |
|
415 | + $this->assertLessThan(0, $setting->term_id); |
|
416 | 416 | $setting->save(); |
417 | - $this->assertEquals( $menu_id, $setting->previous_term_id ); |
|
418 | - $this->assertGreaterThan( 0, $setting->term_id ); |
|
417 | + $this->assertEquals($menu_id, $setting->previous_term_id); |
|
418 | + $this->assertGreaterThan(0, $setting->term_id); |
|
419 | 419 | |
420 | 420 | $nav_menu_options = $this->get_nav_menu_items_option(); |
421 | - $this->assertContains( $setting->term_id, $nav_menu_options['auto_add'] ); |
|
422 | - |
|
423 | - $menu = wp_get_nav_menu_object( $setting->term_id ); |
|
424 | - unset( $post_value['auto_add'] ); |
|
425 | - $this->assertEqualSets( $post_value, wp_array_slice_assoc( (array) $menu, array_keys( $post_value ) ) ); |
|
426 | - |
|
427 | - $save_response = apply_filters( 'customize_save_response', array() ); |
|
428 | - $this->assertArrayHasKey( 'nav_menu_updates', $save_response ); |
|
429 | - $update_result = array_shift( $save_response['nav_menu_updates'] ); |
|
430 | - $this->assertArrayHasKey( 'term_id', $update_result ); |
|
431 | - $this->assertArrayHasKey( 'previous_term_id', $update_result ); |
|
432 | - $this->assertArrayHasKey( 'error', $update_result ); |
|
433 | - $this->assertArrayHasKey( 'status', $update_result ); |
|
434 | - $this->assertArrayHasKey( 'saved_value', $update_result ); |
|
435 | - $this->assertEquals( $setting->value(), $update_result['saved_value'] ); |
|
436 | - |
|
437 | - $this->assertEquals( $menu->term_id, $update_result['term_id'] ); |
|
438 | - $this->assertEquals( $menu_id, $update_result['previous_term_id'] ); |
|
439 | - $this->assertNull( $update_result['error'] ); |
|
440 | - $this->assertEquals( 'inserted', $update_result['status'] ); |
|
421 | + $this->assertContains($setting->term_id, $nav_menu_options['auto_add']); |
|
422 | + |
|
423 | + $menu = wp_get_nav_menu_object($setting->term_id); |
|
424 | + unset($post_value['auto_add']); |
|
425 | + $this->assertEqualSets($post_value, wp_array_slice_assoc((array) $menu, array_keys($post_value))); |
|
426 | + |
|
427 | + $save_response = apply_filters('customize_save_response', array()); |
|
428 | + $this->assertArrayHasKey('nav_menu_updates', $save_response); |
|
429 | + $update_result = array_shift($save_response['nav_menu_updates']); |
|
430 | + $this->assertArrayHasKey('term_id', $update_result); |
|
431 | + $this->assertArrayHasKey('previous_term_id', $update_result); |
|
432 | + $this->assertArrayHasKey('error', $update_result); |
|
433 | + $this->assertArrayHasKey('status', $update_result); |
|
434 | + $this->assertArrayHasKey('saved_value', $update_result); |
|
435 | + $this->assertEquals($setting->value(), $update_result['saved_value']); |
|
436 | + |
|
437 | + $this->assertEquals($menu->term_id, $update_result['term_id']); |
|
438 | + $this->assertEquals($menu_id, $update_result['previous_term_id']); |
|
439 | + $this->assertNull($update_result['error']); |
|
440 | + $this->assertEquals('inserted', $update_result['status']); |
|
441 | 441 | } |
442 | 442 | |
443 | 443 | /** |
@@ -446,23 +446,23 @@ discard block |
||
446 | 446 | * @see WP_Customize_Nav_Menu_Setting::update() |
447 | 447 | */ |
448 | 448 | function test_save_inserted_conflicted_name() { |
449 | - do_action( 'customize_register', $this->wp_customize ); |
|
449 | + do_action('customize_register', $this->wp_customize); |
|
450 | 450 | |
451 | 451 | $menu_name = 'Foo'; |
452 | - wp_update_nav_menu_object( 0, array( 'menu-name' => $menu_name ) ); |
|
452 | + wp_update_nav_menu_object(0, array('menu-name' => $menu_name)); |
|
453 | 453 | |
454 | 454 | $menu_id = -123; |
455 | 455 | $setting_id = "nav_menu[$menu_id]"; |
456 | - $setting = new WP_Customize_Nav_Menu_Setting( $this->wp_customize, $setting_id ); |
|
457 | - $this->wp_customize->set_post_value( $setting->id, array( 'name' => $menu_name ) ); |
|
456 | + $setting = new WP_Customize_Nav_Menu_Setting($this->wp_customize, $setting_id); |
|
457 | + $this->wp_customize->set_post_value($setting->id, array('name' => $menu_name)); |
|
458 | 458 | $setting->save(); |
459 | 459 | |
460 | 460 | $expected_resolved_menu_name = "$menu_name (2)"; |
461 | - $new_menu = wp_get_nav_menu_object( $setting->term_id ); |
|
462 | - $this->assertEquals( $expected_resolved_menu_name, $new_menu->name ); |
|
461 | + $new_menu = wp_get_nav_menu_object($setting->term_id); |
|
462 | + $this->assertEquals($expected_resolved_menu_name, $new_menu->name); |
|
463 | 463 | |
464 | - $save_response = apply_filters( 'customize_save_response', array() ); |
|
465 | - $this->assertEquals( $expected_resolved_menu_name, $save_response['nav_menu_updates'][0]['saved_value']['name'] ); |
|
464 | + $save_response = apply_filters('customize_save_response', array()); |
|
465 | + $this->assertEquals($expected_resolved_menu_name, $save_response['nav_menu_updates'][0]['saved_value']['name']); |
|
466 | 466 | } |
467 | 467 | |
468 | 468 | /** |
@@ -471,41 +471,41 @@ discard block |
||
471 | 471 | * @see WP_Customize_Nav_Menu_Setting::update() |
472 | 472 | */ |
473 | 473 | function test_save_deleted() { |
474 | - do_action( 'customize_register', $this->wp_customize ); |
|
474 | + do_action('customize_register', $this->wp_customize); |
|
475 | 475 | |
476 | 476 | $menu_name = 'Lorem Ipsum'; |
477 | - $menu_id = wp_create_nav_menu( $menu_name ); |
|
477 | + $menu_id = wp_create_nav_menu($menu_name); |
|
478 | 478 | $setting_id = "nav_menu[$menu_id]"; |
479 | - $setting = new WP_Customize_Nav_Menu_Setting( $this->wp_customize, $setting_id ); |
|
479 | + $setting = new WP_Customize_Nav_Menu_Setting($this->wp_customize, $setting_id); |
|
480 | 480 | $nav_menu_options = $this->get_nav_menu_items_option(); |
481 | 481 | $nav_menu_options['auto_add'][] = $menu_id; |
482 | - update_option( 'nav_menu_options', $nav_menu_options ); |
|
482 | + update_option('nav_menu_options', $nav_menu_options); |
|
483 | 483 | |
484 | - $menu = wp_get_nav_menu_object( $menu_id ); |
|
485 | - $this->assertEquals( $menu_name, $menu->name ); |
|
484 | + $menu = wp_get_nav_menu_object($menu_id); |
|
485 | + $this->assertEquals($menu_name, $menu->name); |
|
486 | 486 | |
487 | - $this->wp_customize->set_post_value( $setting_id, false ); |
|
487 | + $this->wp_customize->set_post_value($setting_id, false); |
|
488 | 488 | $setting->save(); |
489 | 489 | |
490 | - $this->assertFalse( wp_get_nav_menu_object( $menu_id ) ); |
|
490 | + $this->assertFalse(wp_get_nav_menu_object($menu_id)); |
|
491 | 491 | |
492 | - $save_response = apply_filters( 'customize_save_response', array() ); |
|
493 | - $this->assertArrayHasKey( 'nav_menu_updates', $save_response ); |
|
494 | - $update_result = array_shift( $save_response['nav_menu_updates'] ); |
|
495 | - $this->assertArrayHasKey( 'term_id', $update_result ); |
|
496 | - $this->assertArrayHasKey( 'previous_term_id', $update_result ); |
|
497 | - $this->assertArrayHasKey( 'error', $update_result ); |
|
498 | - $this->assertArrayHasKey( 'status', $update_result ); |
|
499 | - $this->assertArrayHasKey( 'saved_value', $update_result ); |
|
500 | - $this->assertNull( $update_result['saved_value'] ); |
|
492 | + $save_response = apply_filters('customize_save_response', array()); |
|
493 | + $this->assertArrayHasKey('nav_menu_updates', $save_response); |
|
494 | + $update_result = array_shift($save_response['nav_menu_updates']); |
|
495 | + $this->assertArrayHasKey('term_id', $update_result); |
|
496 | + $this->assertArrayHasKey('previous_term_id', $update_result); |
|
497 | + $this->assertArrayHasKey('error', $update_result); |
|
498 | + $this->assertArrayHasKey('status', $update_result); |
|
499 | + $this->assertArrayHasKey('saved_value', $update_result); |
|
500 | + $this->assertNull($update_result['saved_value']); |
|
501 | 501 | |
502 | - $this->assertEquals( $menu_id, $update_result['term_id'] ); |
|
503 | - $this->assertNull( $update_result['previous_term_id'] ); |
|
504 | - $this->assertNull( $update_result['error'] ); |
|
505 | - $this->assertEquals( 'deleted', $update_result['status'] ); |
|
502 | + $this->assertEquals($menu_id, $update_result['term_id']); |
|
503 | + $this->assertNull($update_result['previous_term_id']); |
|
504 | + $this->assertNull($update_result['error']); |
|
505 | + $this->assertEquals('deleted', $update_result['status']); |
|
506 | 506 | |
507 | 507 | $nav_menu_options = $this->get_nav_menu_items_option(); |
508 | - $this->assertNotContains( $menu_id, $nav_menu_options['auto_add'] ); |
|
508 | + $this->assertNotContains($menu_id, $nav_menu_options['auto_add']); |
|
509 | 509 | } |
510 | 510 | |
511 | 511 | } |
@@ -14,54 +14,54 @@ discard block |
||
14 | 14 | |
15 | 15 | function setUp() { |
16 | 16 | parent::setUp(); |
17 | - require_once( WP_FIELDS_API_DIR . 'implementation/wp-includes/class-wp-customize-manager.php' ); |
|
17 | + require_once(WP_FIELDS_API_DIR.'implementation/wp-includes/class-wp-customize-manager.php'); |
|
18 | 18 | //require_once( ABSPATH . WPINC . '/class-wp-customize-manager.php' ); |
19 | 19 | $GLOBALS['wp_customize'] = new WP_Customize_Manager(); |
20 | 20 | $this->manager = $GLOBALS['wp_customize']; |
21 | 21 | |
22 | - unset( $GLOBALS['_wp_sidebars_widgets'] ); // clear out cache set by wp_get_sidebars_widgets() |
|
22 | + unset($GLOBALS['_wp_sidebars_widgets']); // clear out cache set by wp_get_sidebars_widgets() |
|
23 | 23 | $sidebars_widgets = wp_get_sidebars_widgets(); |
24 | - $this->assertEqualSets( array( 'wp_inactive_widgets', 'sidebar-1' ), array_keys( wp_get_sidebars_widgets() ) ); |
|
25 | - $this->assertContains( 'search-2', $sidebars_widgets['sidebar-1'] ); |
|
26 | - $this->assertContains( 'categories-2', $sidebars_widgets['sidebar-1'] ); |
|
27 | - $this->assertArrayHasKey( 2, get_option( 'widget_search' ) ); |
|
28 | - $widget_categories = get_option( 'widget_categories' ); |
|
29 | - $this->assertArrayHasKey( 2, $widget_categories ); |
|
30 | - $this->assertEquals( '', $widget_categories[2]['title'] ); |
|
31 | - |
|
32 | - remove_action( 'after_setup_theme', 'twentyfifteen_setup' ); // @todo We should not be including a theme anyway |
|
33 | - |
|
34 | - $user_id = $this->factory->user->create( array( 'role' => 'administrator' ) ); |
|
35 | - wp_set_current_user( $user_id ); |
|
24 | + $this->assertEqualSets(array('wp_inactive_widgets', 'sidebar-1'), array_keys(wp_get_sidebars_widgets())); |
|
25 | + $this->assertContains('search-2', $sidebars_widgets['sidebar-1']); |
|
26 | + $this->assertContains('categories-2', $sidebars_widgets['sidebar-1']); |
|
27 | + $this->assertArrayHasKey(2, get_option('widget_search')); |
|
28 | + $widget_categories = get_option('widget_categories'); |
|
29 | + $this->assertArrayHasKey(2, $widget_categories); |
|
30 | + $this->assertEquals('', $widget_categories[2]['title']); |
|
31 | + |
|
32 | + remove_action('after_setup_theme', 'twentyfifteen_setup'); // @todo We should not be including a theme anyway |
|
33 | + |
|
34 | + $user_id = $this->factory->user->create(array('role' => 'administrator')); |
|
35 | + wp_set_current_user($user_id); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | function tearDown() { |
39 | 39 | $this->manager = null; |
40 | - unset( $GLOBALS['wp_customize'] ); |
|
41 | - unset( $GLOBALS['wp_scripts'] ); |
|
40 | + unset($GLOBALS['wp_customize']); |
|
41 | + unset($GLOBALS['wp_scripts']); |
|
42 | 42 | parent::tearDown(); |
43 | 43 | } |
44 | 44 | |
45 | - function set_customized_post_data( $customized ) { |
|
46 | - $_POST['customized'] = wp_slash( wp_json_encode( $customized ) ); |
|
45 | + function set_customized_post_data($customized) { |
|
46 | + $_POST['customized'] = wp_slash(wp_json_encode($customized)); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | function do_customize_boot_actions() { |
50 | 50 | $_SERVER['REQUEST_METHOD'] = 'POST'; |
51 | - do_action( 'setup_theme' ); |
|
52 | - $_REQUEST['nonce'] = wp_create_nonce( 'preview-customize_' . $this->manager->theme()->get_stylesheet() ); |
|
53 | - do_action( 'after_setup_theme' ); |
|
54 | - do_action( 'init' ); |
|
55 | - do_action( 'wp_loaded' ); |
|
56 | - do_action( 'wp', $GLOBALS['wp'] ); |
|
51 | + do_action('setup_theme'); |
|
52 | + $_REQUEST['nonce'] = wp_create_nonce('preview-customize_'.$this->manager->theme()->get_stylesheet()); |
|
53 | + do_action('after_setup_theme'); |
|
54 | + do_action('init'); |
|
55 | + do_action('wp_loaded'); |
|
56 | + do_action('wp', $GLOBALS['wp']); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
60 | 60 | * Test WP_Customize_Widgets::__construct() |
61 | 61 | */ |
62 | 62 | function test_construct() { |
63 | - $this->assertInstanceOf( 'WP_Customize_Widgets', $this->manager->widgets ); |
|
64 | - $this->assertEquals( $this->manager, $this->manager->widgets->manager ); |
|
63 | + $this->assertInstanceOf('WP_Customize_Widgets', $this->manager->widgets); |
|
64 | + $this->assertEquals($this->manager, $this->manager->widgets->manager); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
@@ -83,20 +83,20 @@ discard block |
||
83 | 83 | ), |
84 | 84 | ); |
85 | 85 | $customized = array(); |
86 | - foreach ( $raw_widget_customized as $setting_id => $instance ) { |
|
87 | - $customized[ $setting_id ] = $this->manager->widgets->sanitize_widget_js_instance( $instance ); |
|
86 | + foreach ($raw_widget_customized as $setting_id => $instance) { |
|
87 | + $customized[$setting_id] = $this->manager->widgets->sanitize_widget_js_instance($instance); |
|
88 | 88 | } |
89 | 89 | |
90 | - $this->set_customized_post_data( $customized ); |
|
90 | + $this->set_customized_post_data($customized); |
|
91 | 91 | $this->do_customize_boot_actions(); |
92 | - $this->assertTrue( is_customize_preview() ); |
|
92 | + $this->assertTrue(is_customize_preview()); |
|
93 | 93 | |
94 | - $this->assertNotEmpty( $this->manager->get_setting( 'widget_categories[2]' ), 'Expected setting for pre-existing widget category-2, being customized.' ); |
|
95 | - $this->assertNotEmpty( $this->manager->get_setting( 'widget_search[2]' ), 'Expected setting for pre-existing widget search-2, not being customized.' ); |
|
96 | - $this->assertNotEmpty( $this->manager->get_setting( 'widget_search[3]' ), 'Expected dynamic setting for non-existing widget search-3, being customized.' ); |
|
94 | + $this->assertNotEmpty($this->manager->get_setting('widget_categories[2]'), 'Expected setting for pre-existing widget category-2, being customized.'); |
|
95 | + $this->assertNotEmpty($this->manager->get_setting('widget_search[2]'), 'Expected setting for pre-existing widget search-2, not being customized.'); |
|
96 | + $this->assertNotEmpty($this->manager->get_setting('widget_search[3]'), 'Expected dynamic setting for non-existing widget search-3, being customized.'); |
|
97 | 97 | |
98 | - $widget_categories = get_option( 'widget_categories' ); |
|
99 | - $this->assertEquals( $raw_widget_customized['widget_categories[2]'], $widget_categories[2], 'Expected $wp_customize->get_setting(widget_categories[2])->preview() to have been called.' ); |
|
98 | + $widget_categories = get_option('widget_categories'); |
|
99 | + $this->assertEquals($raw_widget_customized['widget_categories[2]'], $widget_categories[2], 'Expected $wp_customize->get_setting(widget_categories[2])->preview() to have been called.'); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
@@ -104,68 +104,68 @@ discard block |
||
104 | 104 | */ |
105 | 105 | function test_get_setting_args() { |
106 | 106 | |
107 | - add_filter( 'widget_customizer_setting_args', array( $this, 'filter_widget_customizer_setting_args' ), 10, 2 ); |
|
107 | + add_filter('widget_customizer_setting_args', array($this, 'filter_widget_customizer_setting_args'), 10, 2); |
|
108 | 108 | |
109 | 109 | $default_args = array( |
110 | 110 | 'type' => 'option', |
111 | 111 | 'capability' => 'edit_theme_options', |
112 | 112 | 'transport' => 'refresh', |
113 | 113 | 'default' => array(), |
114 | - 'sanitize_callback' => array( $this->manager->widgets, 'sanitize_widget_instance' ), |
|
115 | - 'sanitize_js_callback' => array( $this->manager->widgets, 'sanitize_widget_js_instance' ), |
|
114 | + 'sanitize_callback' => array($this->manager->widgets, 'sanitize_widget_instance'), |
|
115 | + 'sanitize_js_callback' => array($this->manager->widgets, 'sanitize_widget_js_instance'), |
|
116 | 116 | ); |
117 | 117 | |
118 | - $args = $this->manager->widgets->get_setting_args( 'widget_foo[2]' ); |
|
119 | - foreach ( $default_args as $key => $default_value ) { |
|
120 | - $this->assertEquals( $default_value, $args[ $key ] ); |
|
118 | + $args = $this->manager->widgets->get_setting_args('widget_foo[2]'); |
|
119 | + foreach ($default_args as $key => $default_value) { |
|
120 | + $this->assertEquals($default_value, $args[$key]); |
|
121 | 121 | } |
122 | - $this->assertEquals( 'WIDGET_FOO[2]', $args['uppercase_id_set_by_filter'] ); |
|
122 | + $this->assertEquals('WIDGET_FOO[2]', $args['uppercase_id_set_by_filter']); |
|
123 | 123 | |
124 | 124 | $override_args = array( |
125 | 125 | 'type' => 'theme_mod', |
126 | 126 | 'capability' => 'edit_posts', |
127 | 127 | 'transport' => 'postMessage', |
128 | - 'default' => array( 'title' => 'asd' ), |
|
128 | + 'default' => array('title' => 'asd'), |
|
129 | 129 | 'sanitize_callback' => '__return_empty_array', |
130 | 130 | 'sanitize_js_callback' => '__return_empty_array', |
131 | 131 | ); |
132 | - $args = $this->manager->widgets->get_setting_args( 'widget_bar[3]', $override_args ); |
|
133 | - foreach ( $override_args as $key => $override_value ) { |
|
134 | - $this->assertEquals( $override_value, $args[ $key ] ); |
|
132 | + $args = $this->manager->widgets->get_setting_args('widget_bar[3]', $override_args); |
|
133 | + foreach ($override_args as $key => $override_value) { |
|
134 | + $this->assertEquals($override_value, $args[$key]); |
|
135 | 135 | } |
136 | - $this->assertEquals( 'WIDGET_BAR[3]', $args['uppercase_id_set_by_filter'] ); |
|
136 | + $this->assertEquals('WIDGET_BAR[3]', $args['uppercase_id_set_by_filter']); |
|
137 | 137 | |
138 | 138 | $default_args = array( |
139 | 139 | 'type' => 'option', |
140 | 140 | 'capability' => 'edit_theme_options', |
141 | 141 | 'transport' => 'refresh', |
142 | 142 | 'default' => array(), |
143 | - 'sanitize_callback' => array( $this->manager->widgets, 'sanitize_sidebar_widgets' ), |
|
144 | - 'sanitize_js_callback' => array( $this->manager->widgets, 'sanitize_sidebar_widgets_js_instance' ), |
|
143 | + 'sanitize_callback' => array($this->manager->widgets, 'sanitize_sidebar_widgets'), |
|
144 | + 'sanitize_js_callback' => array($this->manager->widgets, 'sanitize_sidebar_widgets_js_instance'), |
|
145 | 145 | ); |
146 | - $args = $this->manager->widgets->get_setting_args( 'sidebars_widgets[sidebar-1]' ); |
|
147 | - foreach ( $default_args as $key => $default_value ) { |
|
148 | - $this->assertEquals( $default_value, $args[ $key ] ); |
|
146 | + $args = $this->manager->widgets->get_setting_args('sidebars_widgets[sidebar-1]'); |
|
147 | + foreach ($default_args as $key => $default_value) { |
|
148 | + $this->assertEquals($default_value, $args[$key]); |
|
149 | 149 | } |
150 | - $this->assertEquals( 'SIDEBARS_WIDGETS[SIDEBAR-1]', $args['uppercase_id_set_by_filter'] ); |
|
150 | + $this->assertEquals('SIDEBARS_WIDGETS[SIDEBAR-1]', $args['uppercase_id_set_by_filter']); |
|
151 | 151 | |
152 | 152 | $override_args = array( |
153 | 153 | 'type' => 'theme_mod', |
154 | 154 | 'capability' => 'edit_posts', |
155 | 155 | 'transport' => 'postMessage', |
156 | - 'default' => array( 'title' => 'asd' ), |
|
156 | + 'default' => array('title' => 'asd'), |
|
157 | 157 | 'sanitize_callback' => '__return_empty_array', |
158 | 158 | 'sanitize_js_callback' => '__return_empty_array', |
159 | 159 | ); |
160 | - $args = $this->manager->widgets->get_setting_args( 'sidebars_widgets[sidebar-2]', $override_args ); |
|
161 | - foreach ( $override_args as $key => $override_value ) { |
|
162 | - $this->assertEquals( $override_value, $args[ $key ] ); |
|
160 | + $args = $this->manager->widgets->get_setting_args('sidebars_widgets[sidebar-2]', $override_args); |
|
161 | + foreach ($override_args as $key => $override_value) { |
|
162 | + $this->assertEquals($override_value, $args[$key]); |
|
163 | 163 | } |
164 | - $this->assertEquals( 'SIDEBARS_WIDGETS[SIDEBAR-2]', $args['uppercase_id_set_by_filter'] ); |
|
164 | + $this->assertEquals('SIDEBARS_WIDGETS[SIDEBAR-2]', $args['uppercase_id_set_by_filter']); |
|
165 | 165 | } |
166 | 166 | |
167 | - function filter_widget_customizer_setting_args( $args, $id ) { |
|
168 | - $args['uppercase_id_set_by_filter'] = strtoupper( $id ); |
|
167 | + function filter_widget_customizer_setting_args($args, $id) { |
|
168 | + $args['uppercase_id_set_by_filter'] = strtoupper($id); |
|
169 | 169 | return $args; |
170 | 170 | } |
171 | 171 | |
@@ -182,18 +182,18 @@ discard block |
||
182 | 182 | 'dropdown' => '1', |
183 | 183 | ); |
184 | 184 | |
185 | - $sanitized_for_js = $this->manager->widgets->sanitize_widget_js_instance( $new_categories_instance ); |
|
186 | - $this->assertArrayHasKey( 'encoded_serialized_instance', $sanitized_for_js ); |
|
187 | - $this->assertTrue( is_serialized( base64_decode( $sanitized_for_js['encoded_serialized_instance'] ), true ) ); |
|
188 | - $this->assertEquals( $new_categories_instance['title'], $sanitized_for_js['title'] ); |
|
189 | - $this->assertTrue( $sanitized_for_js['is_widget_customizer_js_value'] ); |
|
190 | - $this->assertArrayHasKey( 'instance_hash_key', $sanitized_for_js ); |
|
185 | + $sanitized_for_js = $this->manager->widgets->sanitize_widget_js_instance($new_categories_instance); |
|
186 | + $this->assertArrayHasKey('encoded_serialized_instance', $sanitized_for_js); |
|
187 | + $this->assertTrue(is_serialized(base64_decode($sanitized_for_js['encoded_serialized_instance']), true)); |
|
188 | + $this->assertEquals($new_categories_instance['title'], $sanitized_for_js['title']); |
|
189 | + $this->assertTrue($sanitized_for_js['is_widget_customizer_js_value']); |
|
190 | + $this->assertArrayHasKey('instance_hash_key', $sanitized_for_js); |
|
191 | 191 | |
192 | 192 | $corrupted_sanitized_for_js = $sanitized_for_js; |
193 | - $corrupted_sanitized_for_js['encoded_serialized_instance'] = base64_encode( serialize( array( 'title' => 'EVIL' ) ) ); |
|
194 | - $this->assertNull( $this->manager->widgets->sanitize_widget_instance( $corrupted_sanitized_for_js ), 'Expected sanitize_widget_instance to reject corrupted data.' ); |
|
193 | + $corrupted_sanitized_for_js['encoded_serialized_instance'] = base64_encode(serialize(array('title' => 'EVIL'))); |
|
194 | + $this->assertNull($this->manager->widgets->sanitize_widget_instance($corrupted_sanitized_for_js), 'Expected sanitize_widget_instance to reject corrupted data.'); |
|
195 | 195 | |
196 | - $unsanitized_from_js = $this->manager->widgets->sanitize_widget_instance( $sanitized_for_js ); |
|
197 | - $this->assertEquals( $unsanitized_from_js, $new_categories_instance ); |
|
196 | + $unsanitized_from_js = $this->manager->widgets->sanitize_widget_instance($sanitized_for_js); |
|
197 | + $this->assertEquals($unsanitized_from_js, $new_categories_instance); |
|
198 | 198 | } |
199 | 199 | } |
@@ -5,28 +5,28 @@ |
||
5 | 5 | * @package WordPress |
6 | 6 | * @subpackage Fields API |
7 | 7 | */ |
8 | -define( 'WP_TESTS_FORCE_KNOWN_BUGS', true ); |
|
8 | +define('WP_TESTS_FORCE_KNOWN_BUGS', true); |
|
9 | 9 | |
10 | 10 | // Support for: |
11 | 11 | // 1. `WP_DEVELOP_DIR` environment variable |
12 | 12 | // 2. Plugin installed inside of WordPress.org developer checkout |
13 | 13 | // 3. Tests checked out to /tmp |
14 | 14 | // 4. VVV tests |
15 | -if ( false !== getenv( 'WP_DEVELOP_DIR' ) ) { |
|
16 | - $test_root = getenv( 'WP_DEVELOP_DIR' ) . '/tests/phpunit'; |
|
17 | -} else if ( file_exists( '../../../../tests/phpunit/includes/bootstrap.php' ) ) { |
|
15 | +if (false !== getenv('WP_DEVELOP_DIR')) { |
|
16 | + $test_root = getenv('WP_DEVELOP_DIR').'/tests/phpunit'; |
|
17 | +} else if (file_exists('../../../../tests/phpunit/includes/bootstrap.php')) { |
|
18 | 18 | $test_root = '../../../../tests/phpunit'; |
19 | -} else if ( file_exists( '/tmp/wordpress-tests-lib/includes/bootstrap.php' ) ) { |
|
19 | +} else if (file_exists('/tmp/wordpress-tests-lib/includes/bootstrap.php')) { |
|
20 | 20 | $test_root = '/tmp/wordpress-tests-lib'; |
21 | -} else if ( file_exists( '/srv/www/wordpress-develop/tests/phpunit/includes/bootstrap.php' ) ) { |
|
21 | +} else if (file_exists('/srv/www/wordpress-develop/tests/phpunit/includes/bootstrap.php')) { |
|
22 | 22 | $test_root = '/srv/www/wordpress-develop/tests/phpunit'; |
23 | 23 | } |
24 | 24 | |
25 | -require $test_root . '/includes/functions.php'; |
|
25 | +require $test_root.'/includes/functions.php'; |
|
26 | 26 | |
27 | 27 | function _manually_load_plugin() { |
28 | - require dirname( __FILE__ ) . '/../wordpress-fields-api.php'; |
|
28 | + require dirname(__FILE__).'/../wordpress-fields-api.php'; |
|
29 | 29 | } |
30 | -tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' ); |
|
30 | +tests_add_filter('muplugins_loaded', '_manually_load_plugin'); |
|
31 | 31 | |
32 | -require $test_root . '/includes/bootstrap.php'; |
|
32 | +require $test_root.'/includes/bootstrap.php'; |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | |
157 | 157 | $args = func_get_args(); |
158 | 158 | |
159 | - call_user_func_array( array( $this, 'init' ), $args ); |
|
159 | + call_user_func_array(array($this, 'init'), $args); |
|
160 | 160 | |
161 | 161 | } |
162 | 162 | |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | * @param string $id A specific ID of the section. |
168 | 168 | * @param array $args Section arguments. |
169 | 169 | */ |
170 | - public function init( $object_type, $id, $args = array() ) { |
|
170 | + public function init($object_type, $id, $args = array()) { |
|
171 | 171 | |
172 | 172 | /** |
173 | 173 | * @var $wp_fields WP_Fields_API |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | |
177 | 177 | $this->object_type = $object_type; |
178 | 178 | |
179 | - if ( is_array( $id ) ) { |
|
179 | + if (is_array($id)) { |
|
180 | 180 | $args = $id; |
181 | 181 | |
182 | 182 | $id = ''; |
@@ -184,19 +184,19 @@ discard block |
||
184 | 184 | $this->id = $id; |
185 | 185 | } |
186 | 186 | |
187 | - $keys = array_keys( get_object_vars( $this ) ); |
|
187 | + $keys = array_keys(get_object_vars($this)); |
|
188 | 188 | |
189 | - foreach ( $keys as $key ) { |
|
190 | - if ( isset( $args[ $key ] ) ) { |
|
191 | - $this->$key = $args[ $key ]; |
|
189 | + foreach ($keys as $key) { |
|
190 | + if (isset($args[$key])) { |
|
191 | + $this->$key = $args[$key]; |
|
192 | 192 | } |
193 | 193 | } |
194 | 194 | |
195 | 195 | self::$instance_count += 1; |
196 | 196 | $this->instance_number = self::$instance_count; |
197 | 197 | |
198 | - if ( empty( $this->active_callback ) ) { |
|
199 | - $this->active_callback = array( $this, 'active_callback' ); |
|
198 | + if (empty($this->active_callback)) { |
|
199 | + $this->active_callback = array($this, 'active_callback'); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | /*if ( $this->screen ) { |
@@ -224,8 +224,8 @@ discard block |
||
224 | 224 | $section = $this; |
225 | 225 | $active = true; |
226 | 226 | |
227 | - if ( is_callable( $this->active_callback ) ) { |
|
228 | - $active = call_user_func( $this->active_callback, $this ); |
|
227 | + if (is_callable($this->active_callback)) { |
|
228 | + $active = call_user_func($this->active_callback, $this); |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | /** |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | * @param bool $active Whether the Fields API section is active. |
235 | 235 | * @param WP_Fields_API_Section $section {@see WP_Fields_API_Section} instance. |
236 | 236 | */ |
237 | - $active = apply_filters( 'fields_api_section_active_' . $this->object_type, $active, $section ); |
|
237 | + $active = apply_filters('fields_api_section_active_'.$this->object_type, $active, $section); |
|
238 | 238 | |
239 | 239 | return $active; |
240 | 240 | |
@@ -264,8 +264,8 @@ discard block |
||
264 | 264 | */ |
265 | 265 | public function json() { |
266 | 266 | |
267 | - $array = wp_array_slice_assoc( (array) $this, array( 'id', 'description', 'priority', 'screen', 'type' ) ); |
|
268 | - $array['title'] = html_entity_decode( $this->title, ENT_QUOTES, get_bloginfo( 'charset' ) ); |
|
267 | + $array = wp_array_slice_assoc((array) $this, array('id', 'description', 'priority', 'screen', 'type')); |
|
268 | + $array['title'] = html_entity_decode($this->title, ENT_QUOTES, get_bloginfo('charset')); |
|
269 | 269 | $array['content'] = $this->get_content(); |
270 | 270 | $array['active'] = $this->active(); |
271 | 271 | $array['instanceNumber'] = $this->instance_number; |
@@ -282,18 +282,18 @@ discard block |
||
282 | 282 | */ |
283 | 283 | public function check_capabilities() { |
284 | 284 | |
285 | - if ( $this->capability && ! call_user_func_array( 'current_user_can', (array) $this->capability ) ) { |
|
285 | + if ($this->capability && ! call_user_func_array('current_user_can', (array) $this->capability)) { |
|
286 | 286 | return false; |
287 | 287 | } |
288 | 288 | |
289 | - if ( $this->theme_supports && ! call_user_func_array( 'current_theme_supports', (array) $this->theme_supports ) ) { |
|
289 | + if ($this->theme_supports && ! call_user_func_array('current_theme_supports', (array) $this->theme_supports)) { |
|
290 | 290 | return false; |
291 | 291 | } |
292 | 292 | |
293 | 293 | $access = true; |
294 | 294 | |
295 | - if ( is_callable( $this->capabilities_callback ) ) { |
|
296 | - $access = call_user_func( $this->capabilities_callback, $this ); |
|
295 | + if (is_callable($this->capabilities_callback)) { |
|
296 | + $access = call_user_func($this->capabilities_callback, $this); |
|
297 | 297 | } |
298 | 298 | |
299 | 299 | return $access; |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | |
312 | 312 | $this->maybe_render(); |
313 | 313 | |
314 | - $template = trim( ob_get_contents() ); |
|
314 | + $template = trim(ob_get_contents()); |
|
315 | 315 | |
316 | 316 | ob_end_clean(); |
317 | 317 | |
@@ -324,7 +324,7 @@ discard block |
||
324 | 324 | */ |
325 | 325 | final public function maybe_render() { |
326 | 326 | |
327 | - if ( ! $this->check_capabilities() ) { |
|
327 | + if ( ! $this->check_capabilities()) { |
|
328 | 328 | return; |
329 | 329 | } |
330 | 330 | |
@@ -336,7 +336,7 @@ discard block |
||
336 | 336 | * |
337 | 337 | * @param WP_Fields_API_Section $this WP_Fields API_Section instance. |
338 | 338 | */ |
339 | - do_action( "fields_api_render_section_{$this->object_type}", $this ); |
|
339 | + do_action("fields_api_render_section_{$this->object_type}", $this); |
|
340 | 340 | |
341 | 341 | /** |
342 | 342 | * Fires before rendering a specific Fields API section. |
@@ -348,7 +348,7 @@ discard block |
||
348 | 348 | * of the specific Fields API section to be rendered. |
349 | 349 | * |
350 | 350 | */ |
351 | - do_action( "fields_api_render_section_{$this->object_type}_{$this->object_name}_{$this->id}" ); |
|
351 | + do_action("fields_api_render_section_{$this->object_type}_{$this->object_name}_{$this->id}"); |
|
352 | 352 | |
353 | 353 | $this->render(); |
354 | 354 | |
@@ -360,7 +360,7 @@ discard block |
||
360 | 360 | * // @todo Merge render_template / print_template() from Customizer |
361 | 361 | */ |
362 | 362 | protected function render() { |
363 | - echo esc_html( $this->title ); |
|
363 | + echo esc_html($this->title); |
|
364 | 364 | } |
365 | 365 | |
366 | 366 | /** |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | |
150 | 150 | $args = func_get_args(); |
151 | 151 | |
152 | - call_user_func_array( array( $this, 'init' ), $args ); |
|
152 | + call_user_func_array(array($this, 'init'), $args); |
|
153 | 153 | |
154 | 154 | } |
155 | 155 | |
@@ -160,11 +160,11 @@ discard block |
||
160 | 160 | * @param string $id A specific ID of the screen. |
161 | 161 | * @param array $args Screen arguments. |
162 | 162 | */ |
163 | - public function init( $object_type, $id, $args = array() ) { |
|
163 | + public function init($object_type, $id, $args = array()) { |
|
164 | 164 | |
165 | 165 | $this->object_type = $object_type; |
166 | 166 | |
167 | - if ( is_array( $id ) ) { |
|
167 | + if (is_array($id)) { |
|
168 | 168 | $args = $id; |
169 | 169 | |
170 | 170 | $id = ''; |
@@ -172,19 +172,19 @@ discard block |
||
172 | 172 | $this->id = $id; |
173 | 173 | } |
174 | 174 | |
175 | - $keys = array_keys( get_object_vars( $this ) ); |
|
175 | + $keys = array_keys(get_object_vars($this)); |
|
176 | 176 | |
177 | - foreach ( $keys as $key ) { |
|
178 | - if ( isset( $args[ $key ] ) ) { |
|
179 | - $this->$key = $args[ $key ]; |
|
177 | + foreach ($keys as $key) { |
|
178 | + if (isset($args[$key])) { |
|
179 | + $this->$key = $args[$key]; |
|
180 | 180 | } |
181 | 181 | } |
182 | 182 | |
183 | 183 | self::$instance_count += 1; |
184 | 184 | $this->instance_number = self::$instance_count; |
185 | 185 | |
186 | - if ( empty( $this->active_callback ) ) { |
|
187 | - $this->active_callback = array( $this, 'active_callback' ); |
|
186 | + if (empty($this->active_callback)) { |
|
187 | + $this->active_callback = array($this, 'active_callback'); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | $this->sections = array(); // Users cannot customize the $sections array. |
@@ -203,8 +203,8 @@ discard block |
||
203 | 203 | $screen = $this; |
204 | 204 | $active = true; |
205 | 205 | |
206 | - if ( is_callable( $this->active_callback ) ) { |
|
207 | - $active = call_user_func( $this->active_callback, $this ); |
|
206 | + if (is_callable($this->active_callback)) { |
|
207 | + $active = call_user_func($this->active_callback, $this); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | /** |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | * @param bool $active Whether the Fields API screen is active. |
215 | 215 | * @param WP_Fields_API_Screen $screen {@see WP_Fields_API_Screen} instance. |
216 | 216 | */ |
217 | - $active = apply_filters( 'fields_api_screen_active_' . $this->object_type, $active, $screen ); |
|
217 | + $active = apply_filters('fields_api_screen_active_'.$this->object_type, $active, $screen); |
|
218 | 218 | |
219 | 219 | return $active; |
220 | 220 | |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | */ |
244 | 244 | public function json() { |
245 | 245 | |
246 | - $array = wp_array_slice_assoc( (array) $this, array( 'id', 'title', 'description', 'priority', 'type' ) ); |
|
246 | + $array = wp_array_slice_assoc((array) $this, array('id', 'title', 'description', 'priority', 'type')); |
|
247 | 247 | |
248 | 248 | $array['content'] = $this->get_content(); |
249 | 249 | $array['active'] = $this->active(); |
@@ -261,18 +261,18 @@ discard block |
||
261 | 261 | */ |
262 | 262 | public function check_capabilities() { |
263 | 263 | |
264 | - if ( $this->capability && ! call_user_func_array( 'current_user_can', (array) $this->capability ) ) { |
|
264 | + if ($this->capability && ! call_user_func_array('current_user_can', (array) $this->capability)) { |
|
265 | 265 | return false; |
266 | 266 | } |
267 | 267 | |
268 | - if ( $this->theme_supports && ! call_user_func_array( 'current_theme_supports', (array) $this->theme_supports ) ) { |
|
268 | + if ($this->theme_supports && ! call_user_func_array('current_theme_supports', (array) $this->theme_supports)) { |
|
269 | 269 | return false; |
270 | 270 | } |
271 | 271 | |
272 | 272 | $access = true; |
273 | 273 | |
274 | - if ( is_callable( $this->capabilities_callback ) ) { |
|
275 | - $access = call_user_func( $this->capabilities_callback, $this ); |
|
274 | + if (is_callable($this->capabilities_callback)) { |
|
275 | + $access = call_user_func($this->capabilities_callback, $this); |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | return $access; |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | |
291 | 291 | $this->maybe_render(); |
292 | 292 | |
293 | - $template = trim( ob_get_contents() ); |
|
293 | + $template = trim(ob_get_contents()); |
|
294 | 294 | |
295 | 295 | ob_end_clean(); |
296 | 296 | |
@@ -304,7 +304,7 @@ discard block |
||
304 | 304 | */ |
305 | 305 | final public function maybe_render() { |
306 | 306 | |
307 | - if ( ! $this->check_capabilities() ) { |
|
307 | + if ( ! $this->check_capabilities()) { |
|
308 | 308 | return; |
309 | 309 | } |
310 | 310 | |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | * |
314 | 314 | * @param WP_Fields_API_Screen $this WP_Fields_API_Screen instance. |
315 | 315 | */ |
316 | - do_action( "fields_api_render_screen_{$this->object_type}", $this ); |
|
316 | + do_action("fields_api_render_screen_{$this->object_type}", $this); |
|
317 | 317 | |
318 | 318 | /** |
319 | 319 | * Fires before rendering a specific Fields API screen. |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | * The dynamic portion of the hook name, `$this->id`, refers to |
322 | 322 | * the ID of the specific Fields API screen to be rendered. |
323 | 323 | */ |
324 | - do_action( "fields_api_render_screen_{$this->object_type}_{$this->object_name}_{$this->id}" ); |
|
324 | + do_action("fields_api_render_screen_{$this->object_type}_{$this->object_name}_{$this->id}"); |
|
325 | 325 | |
326 | 326 | $this->render(); |
327 | 327 | |
@@ -333,12 +333,12 @@ discard block |
||
333 | 333 | * @access protected |
334 | 334 | */ |
335 | 335 | protected function render() { |
336 | - $classes = 'accordion-section control-section control-screen control-screen-' . $this->type; |
|
336 | + $classes = 'accordion-section control-section control-screen control-screen-'.$this->type; |
|
337 | 337 | ?> |
338 | - <li id="accordion-screen-<?php echo esc_attr( $this->id ); ?>" class="<?php echo esc_attr( $classes ); ?>"> |
|
338 | + <li id="accordion-screen-<?php echo esc_attr($this->id); ?>" class="<?php echo esc_attr($classes); ?>"> |
|
339 | 339 | <h3 class="accordion-section-title" tabindex="0"> |
340 | - <?php echo esc_html( $this->title ); ?> |
|
341 | - <span class="screen-reader-text"><?php _e( 'Press return or enter to open this screen' ); ?></span> |
|
340 | + <?php echo esc_html($this->title); ?> |
|
341 | + <span class="screen-reader-text"><?php _e('Press return or enter to open this screen'); ?></span> |
|
342 | 342 | </h3> |
343 | 343 | <ul class="accordion-sub-container control-screen-content"> |
344 | 344 | <?php $this->render_content(); ?> |
@@ -401,14 +401,14 @@ discard block |
||
401 | 401 | */ |
402 | 402 | protected function render_content() { |
403 | 403 | ?> |
404 | - <li class="screen-meta accordion-section control-section<?php if ( empty( $this->description ) ) { echo ' cannot-expand'; } ?>"> |
|
404 | + <li class="screen-meta accordion-section control-section<?php if (empty($this->description)) { echo ' cannot-expand'; } ?>"> |
|
405 | 405 | <div class="accordion-section-title" tabindex="0"> |
406 | 406 | <span class="preview-notice"><?php |
407 | 407 | /* translators: %s is the site/screen title in the Fields API */ |
408 | - printf( __( 'You are editing %s' ), '<strong class="screen-title">' . esc_html( $this->title ) . '</strong>' ); |
|
408 | + printf(__('You are editing %s'), '<strong class="screen-title">'.esc_html($this->title).'</strong>'); |
|
409 | 409 | ?></span> |
410 | 410 | </div> |
411 | - <?php if ( ! empty( $this->description ) ) : ?> |
|
411 | + <?php if ( ! empty($this->description)) : ?> |
|
412 | 412 | <div class="accordion-section-content description"> |
413 | 413 | <?php echo $this->description; ?> |
414 | 414 | </div> |
@@ -22,32 +22,32 @@ discard block |
||
22 | 22 | /** |
23 | 23 | * The absolute server path to the fields API directory. |
24 | 24 | */ |
25 | -define( 'WP_FIELDS_API_DIR', plugin_dir_path( __FILE__ ) ); |
|
25 | +define('WP_FIELDS_API_DIR', plugin_dir_path(__FILE__)); |
|
26 | 26 | |
27 | 27 | /** |
28 | 28 | * On `plugins_loaded`, create an instance of the Fields API manager class. |
29 | 29 | */ |
30 | 30 | function _wp_fields_api_include() { |
31 | 31 | |
32 | - require_once( WP_FIELDS_API_DIR . 'includes/class-wp-fields-api.php' ); |
|
32 | + require_once(WP_FIELDS_API_DIR.'includes/class-wp-fields-api.php'); |
|
33 | 33 | |
34 | 34 | // Init Customize class |
35 | 35 | $GLOBALS['wp_fields'] = new WP_Fields_API; |
36 | 36 | |
37 | 37 | } |
38 | 38 | |
39 | -add_action( 'plugins_loaded', '_wp_fields_api_include', 8 ); |
|
39 | +add_action('plugins_loaded', '_wp_fields_api_include', 8); |
|
40 | 40 | |
41 | 41 | /** |
42 | 42 | * Implement Fields API Customizer instead of WP Core Customizer. |
43 | 43 | */ |
44 | 44 | function _wp_fields_api_customize_include() { |
45 | 45 | |
46 | - if ( ! ( ( isset( $_REQUEST['wp_customize'] ) && 'on' == $_REQUEST['wp_customize'] ) || ( is_admin() && 'customize.php' == basename( $_SERVER['PHP_SELF'] ) ) ) ) { |
|
46 | + if ( ! ((isset($_REQUEST['wp_customize']) && 'on' == $_REQUEST['wp_customize']) || (is_admin() && 'customize.php' == basename($_SERVER['PHP_SELF'])))) { |
|
47 | 47 | return; |
48 | 48 | } |
49 | 49 | |
50 | - require_once( WP_FIELDS_API_DIR . 'implementation/wp-includes/class-wp-customize-manager.php' ); |
|
50 | + require_once(WP_FIELDS_API_DIR.'implementation/wp-includes/class-wp-customize-manager.php'); |
|
51 | 51 | |
52 | 52 | // Init Customize class |
53 | 53 | $GLOBALS['wp_customize'] = new WP_Customize_Manager; |
@@ -62,16 +62,16 @@ discard block |
||
62 | 62 | */ |
63 | 63 | function _wp_fields_api_user_edit_include() { |
64 | 64 | |
65 | - require_once( WP_FIELDS_API_DIR . 'implementation/user-profile.php' ); |
|
65 | + require_once(WP_FIELDS_API_DIR.'implementation/user-profile.php'); |
|
66 | 66 | |
67 | 67 | return; |
68 | 68 | |
69 | 69 | // Load our overrides |
70 | - require_once( WP_FIELDS_API_DIR . 'implementation/wp-admin/includes/user.php' ); |
|
71 | - require_once( WP_FIELDS_API_DIR . 'implementation/wp-admin/user-edit.php' ); |
|
70 | + require_once(WP_FIELDS_API_DIR.'implementation/wp-admin/includes/user.php'); |
|
71 | + require_once(WP_FIELDS_API_DIR.'implementation/wp-admin/user-edit.php'); |
|
72 | 72 | |
73 | 73 | // Bail on original core file, don't run the rest |
74 | 74 | exit; |
75 | 75 | |
76 | 76 | } |
77 | -add_action( 'load-user-edit.php', '_wp_fields_api_user_edit_include' ); |
|
78 | 77 | \ No newline at end of file |
78 | +add_action('load-user-edit.php', '_wp_fields_api_user_edit_include'); |
|
79 | 79 | \ No newline at end of file |