created_post_ids as $post_id ) { wp_delete_post( $post_id, true ); } $this->created_post_ids = array(); foreach ( $this->temp_files as $file ) { if ( file_exists( $file ) ) { unlink( $file ); } } $this->temp_files = array(); parent::tear_down(); } /** * Tests that template parts strip the "theme" attribute from nested template parts when exported. */ public function test_template_part_nested_template_part_theme_attribute_is_removed() { if ( ! class_exists( 'ZipArchive' ) ) { $this->markTestSkipped( 'ZipArchive is required.' ); } $current_theme = get_stylesheet(); $template_part_id = wp_insert_post( array( 'post_type' => 'wp_template_part', 'post_status' => 'publish', 'post_title' => 'Test Template Part With Nested Part', 'post_name' => 'test-nested-part', 'post_content' => '
', ), true ); $this->assertNotWPError( $template_part_id ); $this->created_post_ids[] = $template_part_id; wp_set_post_terms( $template_part_id, array( $current_theme ), 'wp_theme' ); wp_set_post_terms( $template_part_id, array( 'header' ), 'wp_template_part_area' ); $filename = gutenberg_generate_block_templates_export_file(); $this->assertNotWPError( $filename ); $this->assertFileExists( $filename ); $this->temp_files[] = $filename; $zip = new ZipArchive(); $this->assertTrue( $zip->open( $filename ) ); $part_content = $zip->getFromName( 'parts/test-nested-part.html' ); $zip->close(); $this->assertNotEmpty( $part_content ); $this->assertStringNotContainsString( '"theme":', $part_content ); $this->assertStringContainsString( '', $part_content ); } /** * Tests that templates still strip the "theme" attribute from nested template parts when exported. */ public function test_template_nested_template_part_theme_attribute_is_removed() { if ( ! class_exists( 'ZipArchive' ) ) { $this->markTestSkipped( 'ZipArchive is required.' ); } $current_theme = get_stylesheet(); $template_id = wp_insert_post( array( 'post_type' => 'wp_template', 'post_status' => 'publish', 'post_title' => 'Test Template With Nested Part', 'post_name' => 'test-nested-template', 'post_content' => '', ), true ); $this->assertNotWPError( $template_id ); $this->created_post_ids[] = $template_id; wp_set_post_terms( $template_id, array( $current_theme ), 'wp_theme' ); $filename = gutenberg_generate_block_templates_export_file(); $this->assertNotWPError( $filename ); $this->assertFileExists( $filename ); $this->temp_files[] = $filename; $zip = new ZipArchive(); $this->assertTrue( $zip->open( $filename ) ); $template_content = $zip->getFromName( 'templates/test-nested-template.html' ); $zip->close(); $this->assertNotEmpty( $template_content ); $this->assertStringNotContainsString( '"theme":', $template_content ); $this->assertStringContainsString( '', $template_content ); } }