diff --git a/.dev/tests/phpunit/includes/test-coblocks-block-assets.php b/.dev/tests/phpunit/includes/test-coblocks-block-assets.php index fce2bd001ce..e7c312a6bb1 100644 --- a/.dev/tests/phpunit/includes/test-coblocks-block-assets.php +++ b/.dev/tests/phpunit/includes/test-coblocks-block-assets.php @@ -419,4 +419,181 @@ public function test_typography_styles_loaded_with_core_quote_block() { $this->assertContains( 'coblocks-animation', $wp_styles->queue ); $this->assertContains( 'coblocks-extensions', $wp_styles->queue ); } + + /** + * Test extension styles loaded with core image block. + */ + public function test_extension_styles_loaded_with_core_image_block() { + global $post, $wp_styles; + unset( $GLOBALS['current_screen'] ); + + // core/image + $post_id = wp_insert_post( + array( + 'post_author' => 1, + 'post_content' => '', + 'post_title' => 'Core Image Block', + 'post_status' => 'publish', + ) + ); + + $this->go_to( "/?p={$post_id}" ); + $post = get_post( $post_id ); + + $this->coblocks_block_assets->block_assets(); + do_action( 'enqueue_block_assets' ); + + // Core blocks should also have coblocks-animation. + $this->assertContains( 'coblocks-extensions', $wp_styles->queue ); + } + + /** + * Test extension styles loaded with core buttons block. + */ + public function test_extension_styles_loaded_with_core_buttons_button_block() { + global $post, $wp_styles; + unset( $GLOBALS['current_screen'] ); + + // core/buttons + $post_id = wp_insert_post( + array( + 'post_author' => 1, + 'post_content' => '', + 'post_title' => 'Core Buttons Block', + 'post_status' => 'publish', + ) + ); + + $this->go_to( "/?p={$post_id}" ); + $post = get_post( $post_id ); + + $this->coblocks_block_assets->block_assets(); + do_action( 'enqueue_block_assets' ); + + // Does not contain for buttons but does contain for inner button block. + $this->assertNotContains( 'coblocks-extensions', $wp_styles->queue ); + + // Now test against inner block core/button. + $post_id = wp_insert_post( + array( + 'post_author' => 1, + 'post_content' => '
', + 'post_title' => 'Core Buttons Block with Button', + 'post_status' => 'publish', + ) + ); + + $this->go_to( "/?p={$post_id}" ); + $post = get_post( $post_id ); + + $this->coblocks_block_assets->block_assets(); + do_action( 'enqueue_block_assets' ); + + // Core blocks should also have coblocks-animation. + $this->assertContains( 'coblocks-extensions', $wp_styles->queue ); + } + + /** + * Test extension styles loaded with core cover block. + */ + public function test_extension_styles_loaded_with_core_cover_block() { + global $post, $wp_styles; + unset( $GLOBALS['current_screen'] ); + + // core/cover + $post_id = wp_insert_post( + array( + 'post_author' => 1, + 'post_content' => '', + 'post_title' => 'Core Cover Block', + 'post_status' => 'publish', + ) + ); + + $this->go_to( "/?p={$post_id}" ); + $post = get_post( $post_id ); + + $this->coblocks_block_assets->block_assets(); + do_action( 'enqueue_block_assets' ); + + $this->assertContains( 'coblocks-extensions', $wp_styles->queue ); + } + + /** + * Test extension styles loaded with core list block. + */ + public function test_extension_styles_loaded_with_core_list_block() { + global $post, $wp_styles; + unset( $GLOBALS['current_screen'] ); + + // core/list + $post_id = wp_insert_post( + array( + 'post_author' => 1, + 'post_content' => '', + 'post_title' => 'Core List Block', + 'post_status' => 'publish', + ) + ); + + $this->go_to( "/?p={$post_id}" ); + $post = get_post( $post_id ); + + $this->coblocks_block_assets->block_assets(); + do_action( 'enqueue_block_assets' ); + + $this->assertContains( 'coblocks-extensions', $wp_styles->queue ); + } + + /** + * Test extension styles loaded with core media text block. + */ + public function test_extension_styles_loaded_with_core_media_text_block() { + global $post, $wp_styles; + unset( $GLOBALS['current_screen'] ); + + // core/media-text + $post_id = wp_insert_post( + array( + 'post_author' => 1, + 'post_content' => '', + 'post_title' => 'Core Media Text Block', + 'post_status' => 'publish', + ) + ); + + $this->go_to( "/?p={$post_id}" ); + $post = get_post( $post_id ); + + $this->coblocks_block_assets->block_assets(); + do_action( 'enqueue_block_assets' ); + + $this->assertContains( 'coblocks-extensions', $wp_styles->queue ); + } + + /** + * Test extension styles are not loaded when unsupported core block is only block. + */ + public function test_extension_styles_not_loaded_with_unsupported_core_block() { + global $post, $wp_styles; + unset( $GLOBALS['current_screen'] ); + + // core/unsupported + $post_id = wp_insert_post( + array( + 'post_author' => 1, + 'post_content' => '', + 'post_title' => 'Core Unsupported Block', + 'post_status' => 'publish', + ) + ); + + $this->go_to( "/?p={$post_id}" ); + $post = get_post( $post_id ); + + $this->coblocks_block_assets->block_assets(); + do_action( 'enqueue_block_assets' ); + + $this->assertNotContains( 'coblocks-extensions', $wp_styles->queue ); + } } diff --git a/.github/workflows/test-e2e-cypress.yml b/.github/workflows/test-e2e-cypress.yml index 5b1b2e3b850..e90348b92e2 100644 --- a/.github/workflows/test-e2e-cypress.yml +++ b/.github/workflows/test-e2e-cypress.yml @@ -45,12 +45,12 @@ jobs: spec_list=() for line in $changed_files; do - if [[ "$line" =~ src/(blocks|extensions|componets).* ]]; then # If changed file is within our tested paths. + if [[ "$line" =~ src/(blocks|extensions|components|block-styles).* ]]; then # If changed file is within our tested paths. changed_path=$(echo $line | cut -d'/' -f3) # Get the main path of the changed file, e.g. author, food-and-drinks, lightbox. found_specs=$(find . -type f -name "*.cypress.js") # Find real spec files. - pattern="/src/(blocks|extensions|components)/${changed_path}/" # Changed files pattern to match against. + pattern="/src/(blocks|extensions|components|block-styles)/${changed_path}/" # Changed files pattern to match against. for spec in $found_specs; do if [[ $spec =~ $pattern ]]; then diff --git a/includes/class-coblocks-block-assets.php b/includes/class-coblocks-block-assets.php index 07ee52a4695..314cd3f6ce2 100644 --- a/includes/class-coblocks-block-assets.php +++ b/includes/class-coblocks-block-assets.php @@ -641,6 +641,7 @@ public function has_coblocks_block( WP_Post $post_object ) { array_filter( array( false !== strpos( $post_object->post_content, '