-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathtest-theme-utils.php
65 lines (54 loc) · 2.09 KB
/
test-theme-utils.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?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
* Inserter: no
*/
?>
<!-- wp:template-part {"slug":"header-minimal","tagName":"header"} /-->
';
$updated_pattern_string = CBT_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 = CBT_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 = CBT_Theme_Utils::replace_namespace( $code_string, 'oldslug', sanitize_title( 'New Slug' ), 'OldSlug', 'New Slug' );
$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 );
}
}