- Timestamp:
- 03/15/2024 12:10:49 PM (6 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/interactivity-api/wpInteractivityAPI.php
r57649 r57841 237 237 } 238 238 239 239 /** 240 * Tests that empty state objects are pruned from printed data. 241 * 242 * @ticket 60761 243 * 244 * @covers ::print_client_interactivity_data 245 */ 246 public function test_state_not_printed_when_empty_array() { 247 $this->interactivity->state( 'pluginWithEmptyState_prune', array() ); 248 $this->interactivity->state( 'pluginWithState_include', array( 'value' => 'excellent' ) ); 249 $printed_script = get_echo( array( $this->interactivity, 'print_client_interactivity_data' ) ); 250 $expected = <<<'SCRIPT_TAG' 251 <script type="application/json" id="wp-interactivity-data"> 252 {"state":{"pluginWithState_include":{"value":"excellent"}}} 253 </script> 254 255 SCRIPT_TAG; 256 257 $this->assertSame( $expected, $printed_script ); 258 } 259 260 /** 261 * Tests that data consisting of only empty state objects is not printed. 262 * 263 * @ticket 60761 264 * 265 * @covers ::print_client_interactivity_data 266 */ 267 public function test_state_not_printed_when_only_empty_arrays() { 268 $this->interactivity->state( 'pluginWithEmptyState_prune', array() ); 269 $printed_script = get_echo( array( $this->interactivity, 'print_client_interactivity_data' ) ); 270 $this->assertSame( '', $printed_script ); 271 } 272 273 /** 274 * Tests that nested empty state objects are printed correctly. 275 * 276 * @ticket 60761 277 * 278 * @covers ::print_client_interactivity_data 279 */ 280 public function test_state_printed_correctly_with_nested_empty_array() { 281 $this->interactivity->state( 'myPlugin', array( 'emptyArray' => array() ) ); 282 $printed_script = get_echo( array( $this->interactivity, 'print_client_interactivity_data' ) ); 283 $expected = <<<'SCRIPT_TAG' 284 <script type="application/json" id="wp-interactivity-data"> 285 {"state":{"myPlugin":{"emptyArray":[]}}} 286 </script> 287 288 SCRIPT_TAG; 289 290 $this->assertSame( $expected, $printed_script ); 291 } 292 293 /** 294 * Tests that empty config objects are pruned from printed data. 295 * 296 * @ticket 60761 297 * 298 * @covers ::print_client_interactivity_data 299 */ 300 public function test_config_not_printed_when_empty_array() { 301 $this->interactivity->config( 'pluginWithEmptyConfig_prune', array() ); 302 $this->interactivity->config( 'pluginWithConfig_include', array( 'value' => 'excellent' ) ); 303 $printed_script = get_echo( array( $this->interactivity, 'print_client_interactivity_data' ) ); 304 $expected = <<<'SCRIPT_TAG' 305 <script type="application/json" id="wp-interactivity-data"> 306 {"config":{"pluginWithConfig_include":{"value":"excellent"}}} 307 </script> 308 309 SCRIPT_TAG; 310 311 $this->assertSame( $expected, $printed_script ); 312 } 313 314 /** 315 * Tests that data consisting of only empty config objects is not printed. 316 * 317 * @ticket 60761 318 * 319 * @covers ::print_client_interactivity_data 320 */ 321 public function test_config_not_printed_when_only_empty_arrays() { 322 $this->interactivity->config( 'pluginWithEmptyConfig_prune', array() ); 323 $printed_script = get_echo( array( $this->interactivity, 'print_client_interactivity_data' ) ); 324 $this->assertSame( '', $printed_script ); 325 } 326 327 /** 328 * Tests that nested empty config objects are printed correctly. 329 * 330 * @ticket 60761 331 * 332 * @covers ::print_client_interactivity_data 333 */ 334 public function test_config_printed_correctly_with_nested_empty_array() { 335 $this->interactivity->config( 'myPlugin', array( 'emptyArray' => array() ) ); 336 $printed_script = get_echo( array( $this->interactivity, 'print_client_interactivity_data' ) ); 337 $expected = <<<'SCRIPT_TAG' 338 <script type="application/json" id="wp-interactivity-data"> 339 {"config":{"myPlugin":{"emptyArray":[]}}} 340 </script> 341 342 SCRIPT_TAG; 343 344 $this->assertSame( $expected, $printed_script ); 345 } 240 346 241 347 /**
Note: See TracChangeset
for help on using the changeset viewer.