forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeneral.php
More file actions
157 lines (128 loc) · 4.35 KB
/
general.php
File metadata and controls
157 lines (128 loc) · 4.35 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
<?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
*/
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();
}
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;
}
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 );
}
function _remove_site_icon() {
delete_option( 'site_icon' );
}
function _insert_attachment() {
$filename = DIR_TESTDATA . '/images/test-image.jpg';
$contents = file_get_contents( $filename );
$upload = wp_upload_bits( basename( $filename ), null, $contents );
$type = '';
if ( ! empty( $upload['type'] ) ) {
$type = $upload['type'];
} else {
$mime = wp_check_filetype( $upload['file'] );
if ( $mime ) {
$type = $mime['type'];
}
}
$attachment = array(
'post_title' => basename( $upload['file'] ),
'post_content' => $upload['url'],
'post_type' => 'attachment',
'post_mime_type' => $type,
'guid' => $upload['url'],
);
// Save the data
$this->site_icon_url = $upload['url'];
$this->site_icon_id = wp_insert_attachment( $attachment, $upload['file'] );
wp_update_attachment_metadata( $this->site_icon_id, wp_generate_attachment_metadata( $this->site_icon_id, $upload['file'] ) );
}
}