Changeset 55172 for trunk/tests/phpunit/tests/theme/wpThemeJson.php
- Timestamp:
- 02/01/2023 01:41:16 PM (4 years ago)
- File:
-
- 1 edited
-
trunk/tests/phpunit/tests/theme/wpThemeJson.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/theme/wpThemeJson.php
r55146 r55172 3597 3597 3598 3598 /** 3599 * @ticket 57583 3600 * 3601 * @dataProvider data_sanitize_for_block_with_style_variations 3602 * 3603 * @param array $theme_json_variations Theme.json variations to test. 3604 * @param array $expected_sanitized Expected results after sanitizing. 3605 */ 3606 public function test_sanitize_for_block_with_style_variations( $theme_json_variations, $expected_sanitized ) { 3607 $theme_json = new WP_Theme_JSON( 3608 array( 3609 'version' => 2, 3610 'styles' => array( 3611 'blocks' => array( 3612 'core/quote' => $theme_json_variations, 3613 ), 3614 ), 3615 ) 3616 ); 3617 3618 // Validate structure is sanitized. 3619 $sanitized_theme_json = $theme_json->get_raw_data(); 3620 $this->assertIsArray( $sanitized_theme_json, 'Sanitized theme.json is not an array data type' ); 3621 $this->assertArrayHasKey( 'styles', $sanitized_theme_json, 'Sanitized theme.json does not have an "styles" key' ); 3622 $this->assertSameSetsWithIndex( $expected_sanitized, $sanitized_theme_json['styles'], 'Sanitized theme.json styles does not match' ); 3623 } 3624 3625 /** 3626 * Data provider. 3627 * 3628 * @return array 3629 */ 3630 public function data_sanitize_for_block_with_style_variations() { 3631 return array( 3632 '1 variation with 1 invalid property' => array( 3633 'theme_json_variations' => array( 3634 'variations' => array( 3635 'plain' => array( 3636 'color' => array( 3637 'background' => 'hotpink', 3638 ), 3639 ), 3640 ), 3641 ), 3642 'expected_sanitized' => array( 3643 'blocks' => array( 3644 'core/quote' => array( 3645 'variations' => array( 3646 'plain' => array( 3647 'color' => array( 3648 'background' => 'hotpink', 3649 ), 3650 ), 3651 ), 3652 ), 3653 ), 3654 ), 3655 ), 3656 '1 variation with 2 invalid properties' => array( 3657 'theme_json_variations' => array( 3658 'variations' => array( 3659 'plain' => array( 3660 'color' => array( 3661 'background' => 'hotpink', 3662 ), 3663 'invalidProperty1' => 'value1', 3664 'invalidProperty2' => 'value2', 3665 ), 3666 ), 3667 ), 3668 'expected_sanitized' => array( 3669 'blocks' => array( 3670 'core/quote' => array( 3671 'variations' => array( 3672 'plain' => array( 3673 'color' => array( 3674 'background' => 'hotpink', 3675 ), 3676 ), 3677 ), 3678 ), 3679 ), 3680 ), 3681 ), 3682 '2 variations with 1 invalid property' => array( 3683 'theme_json_variations' => array( 3684 'variations' => array( 3685 'plain' => array( 3686 'color' => array( 3687 'background' => 'hotpink', 3688 ), 3689 'invalidProperty1' => 'value1', 3690 ), 3691 'basic' => array( 3692 'color' => array( 3693 'background' => '#ffffff', 3694 'text' => '#000000', 3695 ), 3696 'foo' => 'bar', 3697 ), 3698 ), 3699 ), 3700 'expected_sanitized' => array( 3701 'blocks' => array( 3702 'core/quote' => array( 3703 'variations' => array( 3704 'plain' => array( 3705 'color' => array( 3706 'background' => 'hotpink', 3707 ), 3708 ), 3709 'basic' => array( 3710 'color' => array( 3711 'background' => '#ffffff', 3712 'text' => '#000000', 3713 ), 3714 ), 3715 ), 3716 ), 3717 ), 3718 ), 3719 ), 3720 ); 3721 } 3722 3723 /** 3724 * @ticket 57583 3725 * 3726 * @dataProvider data_sanitize_with_invalid_style_variation 3727 * 3728 * @param array $theme_json_variations The theme.json variations to test. 3729 */ 3730 public function test_sanitize_with_invalid_style_variation( $theme_json_variations ) { 3731 $theme_json = new WP_Theme_JSON( 3732 array( 3733 'version' => 2, 3734 'styles' => array( 3735 'blocks' => array( 3736 'core/quote' => $theme_json_variations, 3737 ), 3738 ), 3739 ) 3740 ); 3741 3742 // Validate structure is sanitized. 3743 $sanitized_theme_json = $theme_json->get_raw_data(); 3744 $this->assertIsArray( $sanitized_theme_json, 'Sanitized theme.json is not an array data type' ); 3745 $this->assertArrayNotHasKey( 'styles', $sanitized_theme_json, 'Sanitized theme.json should not have a "styles" key' ); 3746 3747 } 3748 3749 /** 3750 * Data provider. 3751 * 3752 * @return array 3753 */ 3754 public function data_sanitize_with_invalid_style_variation() { 3755 return array( 3756 'empty string variation' => array( 3757 array( 3758 'variations' => '', 3759 ), 3760 ), 3761 'boolean variation' => array( 3762 array( 3763 'variations' => false, 3764 ), 3765 ), 3766 ); 3767 } 3768 3769 /** 3770 * @ticket 57583 3771 * 3772 * @dataProvider data_get_styles_for_block_with_style_variations 3773 * 3774 * @param array $theme_json_variations Theme.json variations to test. 3775 * @param string $metadata_variations Style variations to test. 3776 * @param string $expected Expected results for styling. 3777 */ 3778 public function test_get_styles_for_block_with_style_variations( $theme_json_variations, $metadata_variations, $expected ) { 3779 $theme_json = new WP_Theme_JSON( 3780 array( 3781 'version' => 2, 3782 'styles' => array( 3783 'blocks' => array( 3784 'core/quote' => $theme_json_variations, 3785 ), 3786 ), 3787 ) 3788 ); 3789 3790 // Validate styles are generated properly. 3791 $metadata = array( 3792 'path' => array( 'styles', 'blocks', 'core/quote' ), 3793 'selector' => '.wp-block-quote', 3794 'variations' => $metadata_variations, 3795 ); 3796 $actual_styles = $theme_json->get_styles_for_block( $metadata ); 3797 $this->assertSame( $expected, $actual_styles ); 3798 } 3799 3800 /** 3801 * Data provider. 3802 * 3803 * @return array 3804 */ 3805 public function data_get_styles_for_block_with_style_variations() { 3806 $plain = array( 3807 'metadata' => array( 3808 'path' => array( 'styles', 'blocks', 'core/quote', 'variations', 'plain' ), 3809 'selector' => '.is-style-plain.is-style-plain.wp-block-quote', 3810 ), 3811 'styles' => '.is-style-plain.is-style-plain.wp-block-quote{background-color: hotpink;}', 3812 ); 3813 $basic = array( 3814 'metadata' => array( 3815 'path' => array( 'styles', 'blocks', 'core/quote', 'variations', 'basic' ), 3816 'selector' => '.is-style-basic.is-style-basic.wp-block-quote', 3817 ), 3818 'styles' => '.is-style-basic.is-style-basic.wp-block-quote{background-color: #ffffff;color: #000000;}', 3819 ); 3820 3821 return array( 3822 '1 variation with 1 invalid property' => array( 3823 'theme_json_variations' => array( 3824 'variations' => array( 3825 'plain' => array( 3826 'color' => array( 3827 'background' => 'hotpink', 3828 ), 3829 ), 3830 ), 3831 ), 3832 'metadata_variation' => array( $plain['metadata'] ), 3833 'expected' => $plain['styles'], 3834 ), 3835 '1 variation with 2 invalid properties' => array( 3836 'theme_json_variations' => array( 3837 'variations' => array( 3838 'plain' => array( 3839 'color' => array( 3840 'background' => 'hotpink', 3841 ), 3842 'invalidProperty1' => 'value1', 3843 'invalidProperty2' => 'value2', 3844 ), 3845 ), 3846 ), 3847 'metadata_variation' => array( $plain['metadata'] ), 3848 'expected' => $plain['styles'], 3849 ), 3850 '2 variations with 1 invalid property' => array( 3851 'theme_json_variations' => array( 3852 'variations' => array( 3853 'plain' => array( 3854 'color' => array( 3855 'background' => 'hotpink', 3856 ), 3857 'invalidProperty1' => 'value1', 3858 ), 3859 'basic' => array( 3860 'color' => array( 3861 'background' => '#ffffff', 3862 'text' => '#000000', 3863 ), 3864 'foo' => 'bar', 3865 ), 3866 ), 3867 ), 3868 'metadata_variation' => array( $plain['metadata'], $basic['metadata'] ), 3869 'expected_styles' => $plain['styles'] . $basic['styles'], 3870 ), 3871 '2 variations with multiple invalid properties' => array( 3872 'theme_json_variations' => array( 3873 'variations' => array( 3874 'plain' => array( 3875 'color' => array( 3876 'background' => 'hotpink', 3877 ), 3878 'invalidProperty1' => 'value1', 3879 'invalidProperty2' => 'value2', 3880 ), 3881 'basic' => array( 3882 'foo' => 'foo', 3883 'color' => array( 3884 'background' => '#ffffff', 3885 'text' => '#000000', 3886 ), 3887 'bar' => 'bar', 3888 'baz' => 'baz', 3889 ), 3890 ), 3891 ), 3892 'metadata_variation' => array( $plain['metadata'], $basic['metadata'] ), 3893 'expected_styles' => $plain['styles'] . $basic['styles'], 3894 ), 3895 ); 3896 } 3897 3898 /** 3599 3899 * @ticket 56611 3600 3900 */
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)