Changeset 58264 for trunk/tests/phpunit/tests/theme/wpThemeJsonResolver.php
- Timestamp:
- 05/31/2024 05:47:23 AM (6 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/theme/wpThemeJsonResolver.php
r58262 r58264 1024 1024 1025 1025 /** 1026 * Tests that get_style_variations returns all variations, including parent theme variations if the theme is a child, 1027 * and that the child variation overwrites the parent variation of the same name. 1026 * Tests that `get_style_variations` returns all the appropriate variations, 1027 * including parent variations if the theme is a child, and that the child 1028 * variation overwrites the parent variation of the same name. 1029 * 1030 * Note: This covers both theme and block style variations. 1028 1031 * 1029 1032 * @ticket 57545 1033 * @ticket 61312 1030 1034 * 1031 1035 * @covers WP_Theme_JSON_Resolver::get_style_variations 1032 */ 1033 public function test_get_style_variations_returns_all_variations() { 1034 // Switch to a child theme. 1035 switch_theme( 'block-theme-child' ); 1036 * 1037 * @dataProvider data_get_style_variations 1038 * 1039 * @param string $theme Name of the theme to use. 1040 * @param string $scope Scope to filter variations by e.g. theme vs block. 1041 * @param array $expected_variations Collection of expected variations. 1042 */ 1043 public function test_get_style_variations( $theme, $scope, $expected_variations ) { 1044 switch_theme( $theme ); 1036 1045 wp_set_current_user( self::$administrator_id ); 1037 1046 1038 $actual_settings = WP_Theme_JSON_Resolver::get_style_variations(); 1039 $expected_settings = array( 1040 array( 1041 'version' => WP_Theme_JSON::LATEST_SCHEMA, 1042 'title' => 'variation-a', 1043 'settings' => array( 1044 'blocks' => array( 1045 'core/paragraph' => array( 1047 $actual_variations = WP_Theme_JSON_Resolver::get_style_variations( $scope ); 1048 1049 wp_recursive_ksort( $actual_variations ); 1050 wp_recursive_ksort( $expected_variations ); 1051 1052 $this->assertSame( $expected_variations, $actual_variations ); 1053 } 1054 1055 /** 1056 * Data provider for test_get_style_variations 1057 * 1058 * @return array 1059 */ 1060 public function data_get_style_variations() { 1061 return array( 1062 // @ticket 57545 1063 'theme_style_variations' => array( 1064 'theme' => 'block-theme-child', 1065 'scope' => 'theme', 1066 'expected_variations' => array( 1067 array( 1068 'version' => WP_Theme_JSON::LATEST_SCHEMA, 1069 'title' => 'variation-a', 1070 'settings' => array( 1071 'blocks' => array( 1072 'core/paragraph' => array( 1073 'color' => array( 1074 'palette' => array( 1075 'theme' => array( 1076 array( 1077 'slug' => 'dark', 1078 'name' => 'Dark', 1079 'color' => '#010101', 1080 ), 1081 ), 1082 ), 1083 ), 1084 ), 1085 ), 1086 ), 1087 ), 1088 array( 1089 'version' => WP_Theme_JSON::LATEST_SCHEMA, 1090 'title' => 'variation-b', 1091 'settings' => array( 1092 'blocks' => array( 1093 'core/post-title' => array( 1094 'color' => array( 1095 'palette' => array( 1096 'theme' => array( 1097 array( 1098 'slug' => 'dark', 1099 'name' => 'Dark', 1100 'color' => '#010101', 1101 ), 1102 ), 1103 ), 1104 ), 1105 ), 1106 ), 1107 ), 1108 ), 1109 array( 1110 'version' => WP_Theme_JSON::LATEST_SCHEMA, 1111 'title' => 'Block theme variation', 1112 'settings' => array( 1046 1113 'color' => array( 1047 1114 'palette' => array( 1048 1115 'theme' => array( 1049 1116 array( 1050 'slug' => ' dark',1051 'name' => ' Dark',1052 'color' => '# 010101',1117 'slug' => 'foreground', 1118 'name' => 'Foreground', 1119 'color' => '#3F67C6', 1053 1120 ), 1054 1121 ), … … 1056 1123 ), 1057 1124 ), 1058 ), 1059 ), 1060 ), 1061 array( 1062 'version' => WP_Theme_JSON::LATEST_SCHEMA, 1063 'title' => 'variation-b', 1064 'settings' => array( 1065 'blocks' => array( 1066 'core/post-title' => array( 1067 'color' => array( 1068 'palette' => array( 1069 'theme' => array( 1070 array( 1071 'slug' => 'dark', 1072 'name' => 'Dark', 1073 'color' => '#010101', 1074 ), 1125 'styles' => array( 1126 'blocks' => array( 1127 'core/post-title' => array( 1128 'typography' => array( 1129 'fontWeight' => '700', 1075 1130 ), 1076 1131 ), … … 1080 1135 ), 1081 1136 ), 1082 array( 1083 'version' => WP_Theme_JSON::LATEST_SCHEMA, 1084 'title' => 'Block theme variation', 1085 'settings' => array( 1086 'color' => array( 1087 'palette' => array( 1088 'theme' => array( 1089 array( 1090 'slug' => 'foreground', 1091 'name' => 'Foreground', 1092 'color' => '#3F67C6', 1093 ), 1094 ), 1095 ), 1096 ), 1097 ), 1098 'styles' => array( 1099 'blocks' => array( 1100 'core/post-title' => array( 1101 'typography' => array( 1102 'fontWeight' => '700', 1103 ), 1104 ), 1105 ), 1106 ), 1107 ), 1108 ); 1109 1110 wp_recursive_ksort( $actual_settings ); 1111 wp_recursive_ksort( $expected_settings ); 1112 1113 $this->assertSame( 1114 $expected_settings, 1115 $actual_settings 1137 'block_style_variations' => array( 1138 'theme' => 'block-theme-child-with-block-style-variations', 1139 'scope' => 'block', 1140 'expected_variations' => array( 1141 array( 1142 'blockTypes' => array( 'core/group', 'core/columns', 'core/media-text' ), 1143 'version' => 3, 1144 'title' => 'block-style-variation-a', 1145 'styles' => array( 1146 'color' => array( 1147 'background' => 'darkcyan', 1148 'text' => 'aliceblue', 1149 ), 1150 ), 1151 ), 1152 array( 1153 'blockTypes' => array( 'core/group', 'core/columns' ), 1154 'version' => 3, 1155 'title' => 'block-style-variation-b', 1156 'styles' => array( 1157 'color' => array( 1158 'background' => 'midnightblue', 1159 'text' => 'lightblue', 1160 ), 1161 ), 1162 ), 1163 ), 1164 ), 1116 1165 ); 1117 1166 }
Note: See TracChangeset
for help on using the changeset viewer.