forked from timber/timber
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-timber-theme.php
157 lines (131 loc) · 4.87 KB
/
test-timber-theme.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php
use Timber\Theme;
class TestTimberTheme extends Timber_UnitTestCase
{
public $theme_slug = 'timber-test-theme';
public function set_up()
{
parent::set_up();
$this->clean_themes_cache();
$theme = wp_get_theme($this->theme_slug);
if (!$theme->exists()) {
$this->markTestSkipped('The ' . $this->theme_slug . ' theme is not available');
}
}
public function tear_down()
{
$this->restore_themes();
switch_theme('default');
parent::tear_down();
}
public function testThemeVersion()
{
switch_theme($this->theme_slug);
$theme = new Timber\Theme();
$this->assertSame('1.0.1', $theme->version);
}
public function testThemeParentWithNoParent()
{
switch_theme($this->theme_slug);
$context = Timber::context();
$theme = $context['site']->theme;
$output = Timber::compile_string('{{ site.theme.parent.slug }}', $context);
$this->assertEquals('timber-test-theme', $output);
}
public function testThemeMods()
{
set_theme_mod('foo', 'bar');
$theme = new Timber\Theme();
$mods = $theme->theme_mods();
$this->assertEquals('bar', $mods['foo']);
$bar = $theme->theme_mod('foo');
$this->assertEquals('bar', $bar);
}
public function testPath()
{
$context = Timber::context();
$theme = $context['site']->theme;
$output = Timber::compile_string('{{site.theme.path}}', $context);
$this->assertEquals('/wp-content/themes/' . $theme->slug, $output);
}
public function testPathWithPort()
{
switch_theme($this->theme_slug);
/* setUp */
update_option('siteurl', 'http://example.org:3000', true);
update_option('home', 'http://example.org:3000', true);
self::setPermalinkStructure();
$old_port = $_SERVER['SERVER_PORT'];
$_SERVER['SERVER_PORT'] = 3000;
if (!isset($_SERVER['SERVER_NAME'])) {
$_SERVER['SERVER_NAME'] = 'example.org';
}
/* test */
$theme = new Timber\Theme();
$this->assertEquals('/wp-content/themes/timber-test-theme', $theme->path());
/* tearDown */
$_SERVER['SERVER_PORT'] = $old_port;
update_option('siteurl', 'http://example.org', true);
update_option('home', 'http://example.org', true);
}
public function testPathOnSubdirectoryInstall()
{
update_option('siteurl', 'http://example.org/wordpress', true);
$context = Timber::context();
$theme = $context['site']->theme;
$output = Timber::compile_string('{{site.theme.path}}', $context);
$this->assertEquals('/wp-content/themes/' . $theme->slug, $output);
}
public function testLink()
{
$context = Timber::context();
$theme = $context['site']->theme;
$output = Timber::compile_string('{{site.theme.link}}', $context);
$this->assertEquals('http://example.org/wp-content/themes/' . $theme->slug, $output);
}
public function testLinkOnSubdirectoryInstall()
{
update_option('siteurl', 'http://example.org/wordpress', true);
$context = Timber::context();
$theme = $context['site']->theme;
$output = Timber::compile_string('{{site.theme.link}}', $context);
$this->assertEquals('http://example.org/wp-content/themes/' . $theme->slug, $output);
}
public function testThemeGet()
{
switch_theme($this->theme_slug);
$context = Timber::context();
$output = Timber::compile_string('{{site.theme.get("Name")}}', $context);
$this->assertEquals('Timber Tests Theme', $output);
}
public function testThemeDisplay()
{
switch_theme($this->theme_slug);
$context = Timber::context();
$output = Timber::compile_string('{{site.theme.display("Description")}}', $context);
$this->assertEquals("Parent Theme", $output);
}
public function testTimberThemeJsonSerialize()
{
switch_theme('timber-test-theme-child');
$theme = new Theme('timber-test-theme-child');
$encoded = json_encode($theme);
$this->assertNotFalse($encoded);
$decoded = json_decode($encoded, true);
$this->assertEquals([
'name' => 'Timber Tests Child Theme',
'parent' => [
'name' => 'Timber Tests Theme',
'parent' => null,
'parent_slug' => null,
'slug' => 'timber-test-theme',
'uri' => 'http://example.org/wp-content/themes/timber-test-theme',
'version' => '1.0.1',
],
'parent_slug' => 'timber-test-theme',
'slug' => 'timber-test-theme-child',
'uri' => 'http://example.org/wp-content/themes/timber-test-theme',
'version' => '1.0.0',
], $decoded);
}
}