setIsMetadataEditorOpen( false ) }
+ />
+ ) }
>
);
};
diff --git a/src/resolvers.js b/src/resolvers.js
index 41308384..446669a6 100644
--- a/src/resolvers.js
+++ b/src/resolvers.js
@@ -1,4 +1,5 @@
import apiFetch from '@wordpress/api-fetch';
+import { downloadFile } from './utils';
export async function fetchThemeJson() {
const fetchOptions = {
@@ -25,3 +26,38 @@ export async function fetchThemeJson() {
// @todo: handle error
}
}
+
+export async function postCreateThemeVariation( name ) {
+ return apiFetch( {
+ path: '/create-block-theme/v1/create-variation',
+ method: 'POST',
+ data: { name },
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ } );
+}
+
+export async function postUpdateThemeMetadata( theme ) {
+ return apiFetch( {
+ path: '/create-block-theme/v1/update',
+ method: 'POST',
+ data: theme,
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ } );
+}
+
+export async function downloadExportedTheme() {
+ return apiFetch( {
+ path: '/create-block-theme/v1/export',
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ parse: false,
+ } ).then( ( response ) => {
+ downloadFile( response );
+ } );
+}
diff --git a/tests/test-theme-create-theme.php b/tests/test-theme-create-theme.php
deleted file mode 100644
index 5eb1a474..00000000
--- a/tests/test-theme-create-theme.php
+++ /dev/null
@@ -1,55 +0,0 @@
-class_instance = new Create_Block_Theme_Admin();
- }
-
- /**
- * Test if the class exists.
- */
- public function test_theme_instance() {
- $class_name = get_class( $this->class_instance->theme );
- $expected = 'WP_Theme';
-
- $this->assertEquals( $expected, $class_name );
- }
-
- /**
- * Test if the export_child_theme correctly creates a child theme.
- */
- public function test_export_child_theme() {
- $create_block_theme_admin = $this->getMockBuilder( 'Create_Block_Theme_Admin' )
- ->setMethods( array( 'download_file' ) )
- ->getMock();
-
- // Stub download_file method to avoid sending headers.
- $create_block_theme_admin->method( 'download_file' )
- ->willReturn( true );
-
- $theme_name = 'twentytwentythree';
- $expected_child_theme_name = 'twentytwentythree-child';
-
- switch_theme( $theme_name );
- $current_theme = wp_get_theme();
-
- $filename = $create_block_theme_admin->export_child_theme( $current_theme );
-
- // check that the zip file exists in the temp dir.
- $this->assertFileExists( $filename );
-
- // check that it contains a valid WordPress theme.
- $zip = new ZipArchive();
- $zip->open( $filename );
- $zip->extractTo( get_theme_root() . '/' . $expected_child_theme_name );
- $zip->close();
-
- $child_theme = wp_get_theme( $expected_child_theme_name );
- $this->assertTrue( $child_theme->exists() );
- }
-}
diff --git a/tests/test-theme-templates.php b/tests/test-theme-templates.php
index 2e924071..f2bf99ec 100644
--- a/tests/test-theme-templates.php
+++ b/tests/test-theme-templates.php
@@ -4,13 +4,26 @@
*/
class Test_Create_Block_Theme_Templates extends WP_UnitTestCase {
+ /**
+ * Ensure that the string in a template is replaced with the appropraite PHP code
+ */
public function test_paragraphs_are_localized() {
$template = new stdClass();
$template->content = 'This is text to localize
';
$new_template = Theme_Templates::escape_text_in_template( $template );
- $this->assertStringContainsString( 'This is text to localize', $new_template->content );
+ $this->assertStringContainsString( "", $new_template->content );
$this->assertStringNotContainsString( 'This is text to localize
', $new_template->content );
+ }
+ /**
+ * Ensure that escape_text_in_template is not called when the localizeText flag is set to false
+ */
+ public function test_paragraphs_are_not_localized() {
+ $template = new stdClass();
+ $template->slug = 'test-template';
+ $template->content = 'This is text to not localize
';
+ $new_template = Theme_Templates::prepare_template_for_export( $template, null, array( 'localizeText' => false ) );
+ $this->assertStringContainsString( 'This is text to not localize
', $new_template->content );
}
public function test_paragraphs_in_groups_are_localized() {
@@ -76,6 +89,14 @@ public function test_eliminate_nav_block_ref_in_nested_block() {
$this->assertStringContainsString( '', $new_template->content );
}
+ public function test_not_eliminate_nav_block_ref() {
+ $template = new stdClass();
+ $template->slug = 'test-template';
+ $template->content = '';
+ $new_template = Theme_Templates::prepare_template_for_export( $template, null, array( 'removeNavRefs' => false ) );
+ $this->assertStringContainsString( '', $new_template->content );
+ }
+
public function test_eliminate_id_from_image() {
$template = new stdClass();
$template->content = '