Changeset 35724 for trunk/tests/phpunit/tests/customize/manager.php
- Timestamp:
- 11/21/2015 02:51:57 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/customize/manager.php
r35635 r35724 33 33 parent::setUp(); 34 34 require_once( ABSPATH . WPINC . '/class-wp-customize-manager.php' ); 35 $GLOBALS['wp_customize'] = new WP_Customize_Manager(); 36 $this->manager = $GLOBALS['wp_customize']; 35 $this->manager = $this->instantiate(); 37 36 $this->undefined = new stdClass(); 38 37 } … … 67 66 } 68 67 69 $manager = $this-> instantiate();68 $manager = $this->manager; 70 69 $this->assertTrue( $manager->doing_ajax() ); 71 70 … … 83 82 } 84 83 85 $manager = $this-> instantiate();84 $manager = $this->manager; 86 85 $this->assertFalse( $manager->doing_ajax() ); 87 86 } … … 93 92 */ 94 93 function test_unsanitized_post_values() { 95 $manager = $this-> instantiate();94 $manager = $this->manager; 96 95 97 96 $customized = array( … … 115 114 $_POST['customized'] = wp_slash( wp_json_encode( $posted_settings ) ); 116 115 117 $manager = $this-> instantiate();116 $manager = $this->manager; 118 117 119 118 $manager->add_setting( 'foo', array( 'default' => 'foo_default' ) ); … … 128 127 129 128 /** 129 * Test WP_Customize_Manager::set_post_value(). 130 * 131 * @see WP_Customize_Manager::set_post_value() 132 */ 133 function test_set_post_value() { 134 $this->manager->add_setting( 'foo', array( 135 'sanitize_callback' => array( $this, 'sanitize_foo_for_test_set_post_value' ), 136 ) ); 137 $setting = $this->manager->get_setting( 'foo' ); 138 139 $this->assertEmpty( $this->captured_customize_post_value_set_actions ); 140 add_action( 'customize_post_value_set', array( $this, 'capture_customize_post_value_set_actions' ), 10, 3 ); 141 add_action( 'customize_post_value_set_foo', array( $this, 'capture_customize_post_value_set_actions' ), 10, 2 ); 142 $this->manager->set_post_value( $setting->id, '123abc' ); 143 $this->assertCount( 2, $this->captured_customize_post_value_set_actions ); 144 $this->assertEquals( 'customize_post_value_set_foo', $this->captured_customize_post_value_set_actions[0]['action'] ); 145 $this->assertEquals( 'customize_post_value_set', $this->captured_customize_post_value_set_actions[1]['action'] ); 146 $this->assertEquals( array( '123abc', $this->manager ), $this->captured_customize_post_value_set_actions[0]['args'] ); 147 $this->assertEquals( array( $setting->id, '123abc', $this->manager ), $this->captured_customize_post_value_set_actions[1]['args'] ); 148 149 $unsanitized = $this->manager->unsanitized_post_values(); 150 $this->assertArrayHasKey( $setting->id, $unsanitized ); 151 152 $this->assertEquals( '123abc', $unsanitized[ $setting->id ] ); 153 $this->assertEquals( 123, $setting->post_value() ); 154 } 155 156 /** 157 * Sanitize a value for Tests_WP_Customize_Manager::test_set_post_value(). 158 * 159 * @see Tests_WP_Customize_Manager::test_set_post_value() 160 * 161 * @param mixed $value Value. 162 * @return int Value. 163 */ 164 function sanitize_foo_for_test_set_post_value( $value ) { 165 return intval( $value ); 166 } 167 168 /** 169 * Store data coming from customize_post_value_set action calls. 170 * 171 * @see Tests_WP_Customize_Manager::capture_customize_post_value_set_actions() 172 * @var array 173 */ 174 protected $captured_customize_post_value_set_actions = array(); 175 176 /** 177 * Capture the actions fired when calling WP_Customize_Manager::set_post_value(). 178 * 179 * @see Tests_WP_Customize_Manager::test_set_post_value() 180 */ 181 function capture_customize_post_value_set_actions() { 182 $action = current_action(); 183 $args = func_get_args(); 184 $this->captured_customize_post_value_set_actions[] = compact( 'action', 'args' ); 185 } 186 187 /** 130 188 * Test the WP_Customize_Manager::add_dynamic_settings() method. 131 189 * … … 133 191 */ 134 192 function test_add_dynamic_settings() { 135 $manager = $this-> instantiate();193 $manager = $this->manager; 136 194 $setting_ids = array( 'foo', 'bar' ); 137 195 $manager->add_setting( 'foo', array( 'default' => 'foo_default' ) ); … … 163 221 add_action( 'customize_register', array( $this, 'action_customize_register_for_dynamic_settings' ) ); 164 222 165 $manager = $this-> instantiate();223 $manager = $this->manager; 166 224 $manager->add_setting( 'foo', array( 'default' => 'foo_default' ) ); 167 225
Note: See TracChangeset
for help on using the changeset viewer.