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
157 lines (133 loc) · 4.5 KB
/
template.php
File metadata and controls
157 lines (133 loc) · 4.5 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
/**
* @group comment
*/
class Tests_Comment_Template extends WP_UnitTestCase {
function test_get_comments_number() {
$post_id = self::factory()->post->create();
$this->assertEquals( 0, get_comments_number( 0 ) );
$this->assertEquals( 0, get_comments_number( $post_id ) );
$this->assertEquals( 0, get_comments_number( get_post( $post_id ) ) );
self::factory()->comment->create_post_comments( $post_id, 12 );
$this->assertEquals( 12, get_comments_number( $post_id ) );
$this->assertEquals( 12, get_comments_number( get_post( $post_id ) ) );
}
function test_get_comments_number_without_arg() {
$post_id = self::factory()->post->create();
$permalink = get_permalink( $post_id );
$this->go_to( $permalink );
$this->assertEquals( 0, get_comments_number() );
self::factory()->comment->create_post_comments( $post_id, 12 );
$this->go_to( $permalink );
$this->assertEquals( 12, get_comments_number() );
}
/**
* @ticket 13651
*/
function test_get_comments_number_text_declension_with_default_args() {
$post_id = $this->factory->post->create();
$permalink = get_permalink( $post_id );
$this->go_to( $permalink );
$this->assertEquals( __( 'No Comments' ), get_comments_number_text() );
$this->factory->comment->create_post_comments( $post_id, 1 );
$this->go_to( $permalink );
$this->assertEquals( __( '1 Comment' ), get_comments_number_text() );
$this->factory->comment->create_post_comments( $post_id, 1 );
$this->go_to( $permalink );
$this->assertEquals( 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 = $this->factory->post->create();
$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->assertEquals( $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' ),
),
);
}
}