forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.php
More file actions
195 lines (160 loc) · 4.93 KB
/
template.php
File metadata and controls
195 lines (160 loc) · 4.93 KB
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<?php
/**
* A set of unit tests for functions in wp-includes/general-template.php
*
* @group template
*/
class Tests_General_Template extends WP_UnitTestCase {
public $wp_site_icon;
public $site_icon_id;
public $site_icon_url;
function setUp() {
parent::setUp();
require_once ABSPATH . 'wp-admin/includes/class-wp-site-icon.php';
$this->wp_site_icon = $GLOBALS['wp_site_icon'];
}
/**
* @group site_icon
*/
function test_get_site_icon_url() {
$this->assertEmpty( get_site_icon_url() );
$this->_set_site_icon();
$this->assertEquals( $this->site_icon_url, get_site_icon_url() );
$this->_remove_site_icon();
$this->assertEmpty( get_site_icon_url() );
}
/**
* @group site_icon
*/
function test_site_icon_url() {
$this->expectOutputString( '' );
site_icon_url();
$this->_set_site_icon();
$this->expectOutputString( $this->site_icon_url );
site_icon_url();
$this->_remove_site_icon();
}
/**
* @group site_icon
*/
function test_has_site_icon() {
$this->assertFalse( has_site_icon() );
$this->_set_site_icon();
$this->assertTrue( has_site_icon() );
$this->_remove_site_icon();
$this->assertFalse( has_site_icon() );
}
/**
* @group site_icon
* @group multisite
*/
function test_has_site_icon_returns_true_when_called_for_other_site_with_site_icon_set() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'This test requires multisite.' );
}
$blog_id = $this->factory->blog->create();
switch_to_blog( $blog_id );
$this->_set_site_icon();
restore_current_blog();
$this->assertTrue( has_site_icon( $blog_id ) );
}
/**
* @group site_icon
* @group multisite
*/
function test_has_site_icon_returns_false_when_called_for_other_site_without_site_icon_set() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'This test requires multisite.' );
}
$blog_id = $this->factory->blog->create();
$this->assertFalse( has_site_icon( $blog_id ) );
}
/**
* @group site_icon
*/
function test_wp_site_icon() {
$this->expectOutputString( '' );
wp_site_icon();
$this->_set_site_icon();
$output = array(
sprintf( '<link rel="icon" href="%s" sizes="32x32" />', esc_url( get_site_icon_url( 32 ) ) ),
sprintf( '<link rel="icon" href="%s" sizes="192x192" />', esc_url( get_site_icon_url( 192 ) ) ),
sprintf( '<link rel="apple-touch-icon-precomposed" href="%s" />', esc_url( get_site_icon_url( 180 ) ) ),
sprintf( '<meta name="msapplication-TileImage" content="%s" />', esc_url( get_site_icon_url( 270 ) ) ),
'',
);
$output = implode( "\n", $output );
$this->expectOutputString( $output );
wp_site_icon();
$this->_remove_site_icon();
}
/**
* @group site_icon
*/
function test_wp_site_icon_with_filter() {
$this->expectOutputString( '' );
wp_site_icon();
$this->_set_site_icon();
$output = array(
sprintf( '<link rel="icon" href="%s" sizes="32x32" />', esc_url( get_site_icon_url( 32 ) ) ),
sprintf( '<link rel="icon" href="%s" sizes="192x192" />', esc_url( get_site_icon_url( 192 ) ) ),
sprintf( '<link rel="apple-touch-icon-precomposed" href="%s" />', esc_url( get_site_icon_url( 180 ) ) ),
sprintf( '<meta name="msapplication-TileImage" content="%s" />', esc_url( get_site_icon_url( 270 ) ) ),
sprintf( '<link rel="apple-touch-icon" sizes="150x150" href="%s" />', esc_url( get_site_icon_url( 150 ) ) ),
'',
);
$output = implode( "\n", $output );
$this->expectOutputString( $output );
add_filter( 'site_icon_meta_tags', array( $this, '_custom_site_icon_meta_tag' ) );
wp_site_icon();
remove_filter( 'site_icon_meta_tags', array( $this, '_custom_site_icon_meta_tag' ) );
$this->_remove_site_icon();
}
/**
* Builds and retrieves a custom site icon meta tag.
*
* @since 4.3.0
*
* @param $meta_tags
* @return array
*/
function _custom_site_icon_meta_tag( $meta_tags ) {
$meta_tags[] = sprintf( '<link rel="apple-touch-icon" sizes="150x150" href="%s" />', esc_url( get_site_icon_url( 150 ) ) );
return $meta_tags;
}
/**
* Sets a site icon in options for testing.
*
* @since 4.3.0
*/
function _set_site_icon() {
if ( ! $this->site_icon_id ) {
add_filter( 'intermediate_image_sizes_advanced', array( $this->wp_site_icon, 'additional_sizes' ) );
$this->_insert_attachment();
remove_filter( 'intermediate_image_sizes_advanced', array( $this->wp_site_icon, 'additional_sizes' ) );
}
update_option( 'site_icon', $this->site_icon_id );
}
/**
* Removes the site icon from options.
*
* @since 4.3.0
*/
function _remove_site_icon() {
delete_option( 'site_icon' );
}
/**
* Inserts an attachment for testing site icons.
*
* @since 4.3.0
*/
function _insert_attachment() {
$filename = DIR_TESTDATA . '/images/test-image.jpg';
$contents = file_get_contents( $filename );
$upload = wp_upload_bits( basename( $filename ), null, $contents );
$this->site_icon_url = $upload['url'];
// Save the data
$this->site_icon_id = $this->_make_attachment( $upload );
return $this->site_icon_id;
}
}