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
191 lines (160 loc) · 5.29 KB
/
template.php
File metadata and controls
191 lines (160 loc) · 5.29 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
<?php
/**
* @group comment
*/
class Tests_Comment_Template extends WP_UnitTestCase {
/**
* Shared post ID.
*
* @var int
*/
public static $post_id;
/**
* Set up shared fixtures.
*
* @param WP_UnitTest_Factory $factory Unit test factory.
*/
public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
self::$post_id = self::factory()->post->create();
}
function test_get_comments_number() {
$post_id = self::$post_id;
$this->assertSame( 0, get_comments_number( 0 ) );
$this->assertSame( '0', get_comments_number( $post_id ) );
$this->assertSame( '0', get_comments_number( get_post( $post_id ) ) );
self::factory()->comment->create_post_comments( $post_id, 12 );
$this->assertSame( '12', get_comments_number( $post_id ) );
$this->assertSame( '12', get_comments_number( get_post( $post_id ) ) );
}
function test_get_comments_number_without_arg() {
$post_id = self::$post_id;
$permalink = get_permalink( $post_id );
$this->go_to( $permalink );
$this->assertSame( '0', get_comments_number() );
self::factory()->comment->create_post_comments( $post_id, 12 );
$this->go_to( $permalink );
$this->assertSame( '12', get_comments_number() );
}
/**
* @ticket 48772
*/
function test_get_comments_number_text_with_post_id() {
$post_id = self::$post_id;
$this->factory->comment->create_post_comments( $post_id, 6 );
$comments_number_text = get_comments_number_text( false, false, false, $post_id );
$this->assertSame( sprintf( _n( '%s Comment', '%s Comments', 6 ), '6' ), $comments_number_text );
ob_start();
comments_number( false, false, false, $post_id );
$comments_number_text = ob_get_clean();
$this->assertSame( sprintf( _n( '%s Comment', '%s Comments', 6 ), '6' ), $comments_number_text );
}
/**
* @ticket 13651
*/
function test_get_comments_number_text_declension_with_default_args() {
$post_id = self::$post_id;
$permalink = get_permalink( $post_id );
$this->go_to( $permalink );
$this->assertSame( __( 'No Comments' ), get_comments_number_text() );
$this->factory->comment->create_post_comments( $post_id, 1 );
$this->go_to( $permalink );
$this->assertSame( __( '1 Comment' ), get_comments_number_text() );
$this->factory->comment->create_post_comments( $post_id, 1 );
$this->go_to( $permalink );
$this->assertSame( sprintf( _n( '%s Comment', '%s Comments', 2 ), '2' ), get_comments_number_text() );
}
/**
* @ticket 13651
* @dataProvider data_get_comments_number_text_declension
*/
function test_get_comments_number_text_declension_with_custom_args( $number, $input, $output ) {
$post_id = self::$post_id;
$permalink = get_permalink( $post_id );
$this->factory->comment->create_post_comments( $post_id, $number );
$this->go_to( $permalink );
add_filter( 'gettext_with_context', array( $this, '_enable_comment_number_declension' ), 10, 4 );
$this->assertSame( $output, get_comments_number_text( false, false, $input ) );
remove_filter( 'gettext_with_context', array( $this, '_enable_comment_number_declension' ), 10, 4 );
}
function _enable_comment_number_declension( $translation, $text, $context, $domain ) {
if ( 'Comment number declension: on or off' === $context ) {
$translation = 'on';
}
return $translation;
}
/**
* Data provider for test_get_comments_number_text_declension_with_custom_args().
*
* @return array {
* @type array {
* @type int $comments_number The number of comments passed to get_comments_number_text().
* @type string $input Custom text for comments number, e.g. '%s Comments'.
* @type string $output The expected output with the correct plural form of '%s Comments'.
* }
* }
*/
function data_get_comments_number_text_declension() {
return array(
array(
2,
'Comments (%)',
sprintf( _n( '%s Comment', '%s Comments', 2 ), '2' ),
),
array(
2,
'2 Comments',
'2 Comments',
),
array(
2,
'2 Comments<span class="screen-reader-text"> on Hello world!</span>',
'2 Comments<span class="screen-reader-text"> on Hello world!</span>',
),
array(
2,
'2 Comments<span class="screen-reader-text"> on Hello % world!</span>',
'2 Comments<span class="screen-reader-text"> on Hello 2 world!</span>', // See #WP37103.
),
array(
2,
__( '% Comments', 'twentyten' ),
sprintf( _n( '%s Comment', '%s Comments', 2 ), '2' ),
),
array(
2,
_x( '%', 'comments number', 'twentyeleven' ),
'2',
),
array(
2,
__( '<b>%</b> Replies', 'twentyeleven' ),
sprintf( _n( '%s Comment', '%s Comments', 2 ), '<b>2</b>' ),
),
array(
2,
__( '% <span class="reply">comments →</span>', 'twentyeleven' ),
sprintf( '2 <span class="reply">%s →</span>', trim( sprintf( _n( '%s Comment', '%s Comments', 2 ), '' ) ) ),
),
array(
2,
__( '% Replies', 'twentytwelve' ),
sprintf( _n( '%s Comment', '%s Comments', 2 ), '2' ),
),
array(
2,
__( 'View all % comments', 'twentythirteen' ),
sprintf( _n( '%s Comment', '%s Comments', 2 ), '2' ),
),
array(
2,
__( '% Comments', 'twentyfourteen' ),
sprintf( _n( '%s Comment', '%s Comments', 2 ), '2' ),
),
array(
2,
__( '% Comments', 'twentyfifteen' ),
sprintf( _n( '%s Comment', '%s Comments', 2 ), '2' ),
),
);
}
}