Changeset 58739
- Timestamp:
- 07/16/2024 06:37:46 PM (4 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/interactivity-api/wpInteractivityAPIFunctions.php
r58738 r58739 355 355 * @ticket 60356 356 356 * 357 * @covers wp_interactivity_data_wp_context 358 */ 359 public function test_wp_interactivity_data_wp_context_with_different_arrays() { 360 $this->assertSame( 'data-wp-context=\'{}\'', wp_interactivity_data_wp_context( array() ) ); 361 $this->assertSame( 362 'data-wp-context=\'{"a":1,"b":"2","c":true}\'', 363 wp_interactivity_data_wp_context( 364 array( 357 * @covers wp_interactivity_data_wp_context 358 * @dataProvider data_wp_interactivity_data_wp_context_with_different_arrays 359 * 360 * @param array $context Context to encode. 361 * @param string $expected Expected function output. 362 */ 363 public function test_wp_interactivity_data_wp_context_with_different_arrays( $context, $expected ) { 364 $this->assertSame( $expected, wp_interactivity_data_wp_context( $context ) ); 365 } 366 367 /** 368 * Data provider. 369 * 370 * @return array 371 */ 372 public function data_wp_interactivity_data_wp_context_with_different_arrays() { 373 return array( 374 'empty array' => array( 375 'context' => array(), 376 'expected' => 'data-wp-context=\'{}\'', 377 ), 378 'associative array with mixed values' => array( 379 'context' => array( 365 380 'a' => 1, 366 381 'b' => '2', 367 382 'c' => true, 368 ) 369 ) 370 ); 371 $this->assertSame( 372 'data-wp-context=\'{"a":[1,2]}\'', 373 wp_interactivity_data_wp_context( array( 'a' => array( 1, 2 ) ) ) 374 ); 375 $this->assertSame( 376 'data-wp-context=\'[1,2]\'', 377 wp_interactivity_data_wp_context( array( 1, 2 ) ) 383 ), 384 'expected' => 'data-wp-context=\'{"a":1,"b":"2","c":true}\'', 385 ), 386 'associative array with nested array as value' => array( 387 'context' => array( 'a' => array( 1, 2 ) ), 388 'expected' => 'data-wp-context=\'{"a":[1,2]}\'', 389 ), 390 'array without keys, integer values' => array( 391 'context' => array( 1, 2 ), 392 'expected' => 'data-wp-context=\'[1,2]\'', 393 ), 378 394 ); 379 395 } … … 385 401 * @ticket 60356 386 402 * 387 * @covers wp_interactivity_data_wp_context 388 */ 389 public function test_wp_interactivity_data_wp_context_with_different_arrays_and_a_namespace() { 390 $this->assertSame( 'data-wp-context=\'myPlugin::{}\'', wp_interactivity_data_wp_context( array(), 'myPlugin' ) ); 391 $this->assertSame( 392 'data-wp-context=\'myPlugin::{"a":1,"b":"2","c":true}\'', 393 wp_interactivity_data_wp_context( 394 array( 403 * @covers wp_interactivity_data_wp_context 404 * @dataProvider data_wp_interactivity_data_wp_context_with_different_arrays_and_a_namespace 405 * 406 * @param array $context Context to encode. 407 * @param string $store Store namespace. 408 * @param string $expected Expected function output. 409 */ 410 public function test_wp_interactivity_data_wp_context_with_different_arrays_and_a_namespace( $context, $store, $expected ) { 411 $this->assertSame( $expected, wp_interactivity_data_wp_context( $context, $store ) ); 412 } 413 414 /** 415 * Data provider. 416 * 417 * @return array 418 */ 419 public function data_wp_interactivity_data_wp_context_with_different_arrays_and_a_namespace() { 420 return array( 421 'empty array' => array( 422 'context' => array(), 423 'store' => 'myPlugin', 424 'expected' => 'data-wp-context=\'myPlugin::{}\'', 425 ), 426 'associative array with mixed values' => array( 427 'context' => array( 395 428 'a' => 1, 396 429 'b' => '2', 397 430 'c' => true, 398 431 ), 399 'myPlugin' 400 ) 401 ); 402 $this->assertSame( 403 'data-wp-context=\'myPlugin::{"a":[1,2]}\'', 404 wp_interactivity_data_wp_context( array( 'a' => array( 1, 2 ) ), 'myPlugin' ) 405 ); 406 $this->assertSame( 407 'data-wp-context=\'myPlugin::[1,2]\'', 408 wp_interactivity_data_wp_context( array( 1, 2 ), 'myPlugin' ) 432 'store' => 'myPlugin', 433 'expected' => 'data-wp-context=\'myPlugin::{"a":1,"b":"2","c":true}\'', 434 ), 435 'associative array with nested array as value' => array( 436 'context' => array( 'a' => array( 1, 2 ) ), 437 'store' => 'myPlugin', 438 'expected' => 'data-wp-context=\'myPlugin::{"a":[1,2]}\'', 439 ), 440 'array without keys, integer values' => array( 441 'context' => array( 1, 2 ), 442 'store' => 'myPlugin', 443 'expected' => 'data-wp-context=\'myPlugin::[1,2]\'', 444 ), 409 445 ); 410 446 } … … 418 454 * @ticket 60356 419 455 * 420 * @covers wp_interactivity_data_wp_context 421 */ 422 public function test_wp_interactivity_data_wp_context_with_json_flags() { 423 $this->assertSame( 'data-wp-context=\'{"tag":"\u003Cfoo\u003E"}\'', wp_interactivity_data_wp_context( array( 'tag' => '<foo>' ) ) ); 424 $this->assertSame( 'data-wp-context=\'{"apos":"\u0027bar\u0027"}\'', wp_interactivity_data_wp_context( array( 'apos' => "'bar'" ) ) ); 425 $this->assertSame( 'data-wp-context=\'{"quot":"\u0022baz\u0022"}\'', wp_interactivity_data_wp_context( array( 'quot' => '"baz"' ) ) ); 426 $this->assertSame( 'data-wp-context=\'{"amp":"T\u0026T"}\'', wp_interactivity_data_wp_context( array( 'amp' => 'T&T' ) ) ); 456 * @covers wp_interactivity_data_wp_context 457 * @dataProvider data_wp_interactivity_data_wp_context_with_json_flags 458 * 459 * @param array $context Context to encode. 460 * @param string $expected Expected function output. 461 */ 462 public function test_wp_interactivity_data_wp_context_with_json_flags( $context, $expected ) { 463 $this->assertSame( $expected, wp_interactivity_data_wp_context( $context ) ); 464 } 465 466 /** 467 * Data provider. 468 * 469 * @return array 470 */ 471 public function data_wp_interactivity_data_wp_context_with_json_flags() { 472 return array( 473 'value contains <> brackets' => array( 474 'context' => array( 'tag' => '<foo>' ), 475 'expected' => 'data-wp-context=\'{"tag":"\u003Cfoo\u003E"}\'', 476 ), 477 'value contains single quote chars' => array( 478 'context' => array( 'apos' => "'bar'" ), 479 'expected' => 'data-wp-context=\'{"apos":"\u0027bar\u0027"}\'', 480 ), 481 'value contains double quote chars' => array( 482 'context' => array( 'quot' => '"baz"' ), 483 'expected' => 'data-wp-context=\'{"quot":"\u0022baz\u0022"}\'', 484 ), 485 'value contains & ampersand' => array( 486 'context' => array( 'amp' => 'T&T' ), 487 'expected' => 'data-wp-context=\'{"amp":"T\u0026T"}\'', 488 ), 489 ); 427 490 } 428 491
Note: See TracChangeset
for help on using the changeset viewer.