forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththumbnails.php
More file actions
179 lines (127 loc) · 4.88 KB
/
thumbnails.php
File metadata and controls
179 lines (127 loc) · 4.88 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
<?php
/**
* @group post
* @group media
*/
class Tests_Post_Thumbnail_Template extends WP_UnitTestCase {
protected static $post;
protected static $attachment_id;
public static function wpSetUpBeforeClass( $factory ) {
self::$post = $factory->post->create_and_get();
$file = DIR_TESTDATA . '/images/canola.jpg';
self::$attachment_id = $factory->attachment->create_upload_object( $file, self::$post->ID, array(
'post_mime_type' => 'image/jpeg',
) );
}
public static function wpTearDownAfterClass() {
wp_delete_post( self::$post->ID, true );
wp_delete_attachment( self::$attachment_id, true );
}
function test_has_post_thumbnail() {
$this->assertFalse( has_post_thumbnail( self::$post ) );
$this->assertFalse( has_post_thumbnail( self::$post->ID ) );
$this->assertFalse( has_post_thumbnail() );
$GLOBALS['post'] = self::$post;
$this->assertFalse( has_post_thumbnail() );
unset( $GLOBALS['post'] );
set_post_thumbnail( self::$post, self::$attachment_id );
$this->assertTrue( has_post_thumbnail( self::$post ) );
$this->assertTrue( has_post_thumbnail( self::$post->ID ) );
$this->assertFalse( has_post_thumbnail() );
$GLOBALS['post'] = self::$post;
$this->assertTrue( has_post_thumbnail() );
}
function test_get_post_thumbnail_id() {
$this->assertEmpty( get_post_thumbnail_id( self::$post ) );
$this->assertEmpty( get_post_thumbnail_id( self::$post->ID ) );
$this->assertEmpty( get_post_thumbnail_id() );
set_post_thumbnail( self::$post, self::$attachment_id );
$this->assertEquals( self::$attachment_id, get_post_thumbnail_id( self::$post ) );
$this->assertEquals( self::$attachment_id, get_post_thumbnail_id( self::$post->ID ) );
$GLOBALS['post'] = self::$post;
$this->assertEquals( self::$attachment_id, get_post_thumbnail_id() );
}
function test_update_post_thumbnail_cache() {
set_post_thumbnail( self::$post, self::$attachment_id );
$WP_Query = new WP_Query( array(
'post_type' => 'any',
'post__in' => array( self::$post->ID ),
'orderby' => 'post__in',
) );
$this->assertFalse( $WP_Query->thumbnails_cached );
update_post_thumbnail_cache( $WP_Query );
$this->assertTrue( $WP_Query->thumbnails_cached );
}
function test_get_the_post_thumbnail() {
$this->assertEquals( '', get_the_post_thumbnail() );
$this->assertEquals( '', get_the_post_thumbnail( self::$post ) );
set_post_thumbnail( self::$post, self::$attachment_id );
$expected = wp_get_attachment_image( self::$attachment_id, 'post-thumbnail', false, array(
'class' => 'attachment-post-thumbnail size-post-thumbnail wp-post-image'
) );
$this->assertEquals( $expected, get_the_post_thumbnail( self::$post ) );
$GLOBALS['post'] = self::$post;
$this->assertEquals( $expected, get_the_post_thumbnail() );
}
function test_the_post_thumbnail() {
ob_start();
the_post_thumbnail();
$actual = ob_get_clean();
$this->assertEquals( '', $actual );
$GLOBALS['post'] = self::$post;
ob_start();
the_post_thumbnail();
$actual = ob_get_clean();
$this->assertEquals( '', $actual );
set_post_thumbnail( self::$post, self::$attachment_id );
$expected = wp_get_attachment_image( self::$attachment_id, 'post-thumbnail', false, array(
'class' => 'attachment-post-thumbnail size-post-thumbnail wp-post-image'
) );
ob_start();
the_post_thumbnail();
$actual = ob_get_clean();
$this->assertEquals( $expected, $actual );
}
/**
* @ticket 33070
*/
function test_get_the_post_thumbnail_url() {
$this->assertFalse( has_post_thumbnail( self::$post ) );
$this->assertFalse( get_the_post_thumbnail_url() );
$this->assertFalse( get_the_post_thumbnail_url( self::$post ) );
set_post_thumbnail( self::$post, self::$attachment_id );
$this->assertFalse( get_the_post_thumbnail_url() );
$this->assertEquals( wp_get_attachment_url( self::$attachment_id ), get_the_post_thumbnail_url( self::$post ) );
$GLOBALS['post'] = self::$post;
$this->assertEquals( wp_get_attachment_url( self::$attachment_id ), get_the_post_thumbnail_url() );
}
/**
* @ticket 33070
*/
function test_get_the_post_thumbnail_url_with_invalid_post() {
set_post_thumbnail( self::$post, self::$attachment_id );
$this->assertTrue( false !== get_the_post_thumbnail_url( self::$post->ID ) );
$deleted = wp_delete_post( self::$post->ID, true );
$this->assertNotEmpty( $deleted );
$this->assertFalse( get_the_post_thumbnail_url( self::$post->ID ) );
}
/**
* @ticket 33070
*/
function test_the_post_thumbnail_url() {
$GLOBALS['post'] = self::$post;
ob_start();
the_post_thumbnail_url();
$actual = ob_get_clean();
$this->assertEmpty( $actual );
ob_start();
the_post_thumbnail_url();
$actual = ob_get_clean();
$this->assertEmpty( $actual );
set_post_thumbnail( self::$post, self::$attachment_id );
ob_start();
the_post_thumbnail_url();
$actual = ob_get_clean();
$this->assertEquals( wp_get_attachment_url( self::$attachment_id ), $actual );
}
}