@@ -8456,4 +8456,113 @@ public function data_prepend_to_selector() {
84568456 ),
84578457 );
84588458 }
8459+
8460+ /**
8461+ * Tests that block custom CSS uses the css feature selector when defined
8462+ * in block metadata selectors config.
8463+ *
8464+ * @ticket 64695
8465+ */
8466+ public function test_get_styles_for_block_custom_css_uses_css_feature_selector () {
8467+ $ theme_json = new WP_Theme_JSON (
8468+ array (
8469+ 'version ' => WP_Theme_JSON::LATEST_SCHEMA ,
8470+ 'styles ' => array (
8471+ 'blocks ' => array (
8472+ 'core/paragraph ' => array (
8473+ 'css ' => 'color:red; ' ,
8474+ ),
8475+ ),
8476+ ),
8477+ )
8478+ );
8479+
8480+ $ paragraph_node = array (
8481+ 'name ' => 'core/paragraph ' ,
8482+ 'path ' => array ( 'styles ' , 'blocks ' , 'core/paragraph ' ),
8483+ 'selector ' => 'p ' ,
8484+ 'selectors ' => array (
8485+ 'root ' => 'p ' ,
8486+ 'css ' => '.custom-p ' ,
8487+ ),
8488+ );
8489+
8490+ $ this ->assertSame (
8491+ ':root :where(.custom-p){color:red;} ' ,
8492+ $ theme_json ->get_styles_for_block ( $ paragraph_node )
8493+ );
8494+ }
8495+
8496+ /**
8497+ * Tests that block custom CSS falls back to the root selector when no
8498+ * css feature selector is defined in block metadata selectors config.
8499+ *
8500+ * @ticket 64695
8501+ */
8502+ public function test_get_styles_for_block_custom_css_falls_back_to_root_selector () {
8503+ $ theme_json = new WP_Theme_JSON (
8504+ array (
8505+ 'version ' => WP_Theme_JSON::LATEST_SCHEMA ,
8506+ 'styles ' => array (
8507+ 'blocks ' => array (
8508+ 'core/paragraph ' => array (
8509+ 'css ' => 'color:red; ' ,
8510+ ),
8511+ ),
8512+ ),
8513+ )
8514+ );
8515+
8516+ $ paragraph_node = array (
8517+ 'name ' => 'core/paragraph ' ,
8518+ 'path ' => array ( 'styles ' , 'blocks ' , 'core/paragraph ' ),
8519+ 'selector ' => 'p ' ,
8520+ 'selectors ' => array (
8521+ 'root ' => 'p ' ,
8522+ ),
8523+ );
8524+
8525+ $ this ->assertSame (
8526+ ':root :where(p){color:red;} ' ,
8527+ $ theme_json ->get_styles_for_block ( $ paragraph_node )
8528+ );
8529+ }
8530+
8531+ /**
8532+ * Tests that block custom CSS uses the css feature selector when defined
8533+ * as an object with a root subkey in block metadata selectors config.
8534+ *
8535+ * @ticket 64695
8536+ */
8537+ public function test_get_styles_for_block_custom_css_uses_css_feature_selector_object_form () {
8538+ $ theme_json = new WP_Theme_JSON (
8539+ array (
8540+ 'version ' => WP_Theme_JSON::LATEST_SCHEMA ,
8541+ 'styles ' => array (
8542+ 'blocks ' => array (
8543+ 'core/paragraph ' => array (
8544+ 'css ' => 'color:red; ' ,
8545+ ),
8546+ ),
8547+ ),
8548+ )
8549+ );
8550+
8551+ $ paragraph_node = array (
8552+ 'name ' => 'core/paragraph ' ,
8553+ 'path ' => array ( 'styles ' , 'blocks ' , 'core/paragraph ' ),
8554+ 'selector ' => 'p ' ,
8555+ 'selectors ' => array (
8556+ 'root ' => 'p ' ,
8557+ 'css ' => array (
8558+ 'root ' => '.custom-p ' ,
8559+ ),
8560+ ),
8561+ );
8562+
8563+ $ this ->assertSame (
8564+ ':root :where(.custom-p){color:red;} ' ,
8565+ $ theme_json ->get_styles_for_block ( $ paragraph_node )
8566+ );
8567+ }
84598568}
0 commit comments