-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added tests to validate replacing theme namespace and refactored to support it * Pass slug to patternize content when cloning theme * Fixed creating of theme slug from name using no -'s to fix namespace swapping issue
- Loading branch information
Showing
5 changed files
with
82 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
/** | ||
* @package Create_Block_Theme | ||
*/ | ||
class Test_Create_Block_Theme_Utils extends WP_UnitTestCase { | ||
|
||
public function test_replace_namespace_in_pattern() { | ||
$pattern_string = '<?php | ||
/** | ||
* Title: index | ||
* Slug: old-slug/index | ||
* Categories: hidden | ||
* Inserter: no | ||
*/ | ||
?> | ||
<!-- wp:template-part {"slug":"header-minimal","tagName":"header"} /--> | ||
'; | ||
|
||
$updated_pattern_string = Theme_Utils::replace_namespace( $pattern_string, 'old-slug', 'new-slug', 'Old Name', 'New Name' ); | ||
$this->assertStringContainsString( 'Slug: new-slug/index', $updated_pattern_string ); | ||
$this->assertStringNotContainsString( 'old-slug', $updated_pattern_string ); | ||
|
||
} | ||
|
||
public function test_replace_namespace_in_code() { | ||
$code_string = "<?php | ||
/** | ||
* old-slug functions and definitions | ||
* | ||
* @package old-slug | ||
* @since old-slug 1.0 | ||
*/ | ||
if ( ! function_exists( 'old_slug_support' ) ) : | ||
function old_slug_support() { | ||
"; | ||
|
||
$updated_code_string = Theme_Utils::replace_namespace( $code_string, 'old-slug', 'new-slug', 'Old Name', 'New Name' ); | ||
$this->assertStringContainsString( '@package new-slug', $updated_code_string ); | ||
$this->assertStringNotContainsString( 'old-slug', $updated_code_string ); | ||
$this->assertStringContainsString( 'function new_slug_support', $updated_code_string ); | ||
$this->assertStringContainsString( "function_exists( 'new_slug_support' )", $updated_code_string ); | ||
} | ||
|
||
public function test_replace_namespace_in_code_with_single_word_slug() { | ||
$code_string = "<?php | ||
/** | ||
* oldslug functions and definitions | ||
* | ||
* @package oldslug | ||
* @since oldslug 1.0 | ||
*/ | ||
if ( ! function_exists( 'oldslug_support' ) ) : | ||
function oldslug_support() { | ||
"; | ||
|
||
$updated_code_string = Theme_Utils::replace_namespace( $code_string, 'oldslug', Theme_Utils::get_theme_slug( 'New Slug' ), 'OldSlug', 'New Slug' ); | ||
$this->assertStringContainsString( '@package newslug', $updated_code_string ); | ||
$this->assertStringNotContainsString( 'old-slug', $updated_code_string ); | ||
$this->assertStringContainsString( 'function newslug_support', $updated_code_string ); | ||
$this->assertStringContainsString( "function_exists( 'newslug_support' )", $updated_code_string ); | ||
} | ||
} |