forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoutput.php
More file actions
357 lines (284 loc) · 10.1 KB
/
output.php
File metadata and controls
357 lines (284 loc) · 10.1 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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
<?php
/**
* Test the output of post template tags, etc.
*
* @group post
* @group formatting
*/
class Tests_Post_Output extends WP_UnitTestCase {
function setUp() {
parent::setUp();
add_shortcode( 'dumptag', array( $this, '_shortcode_dumptag' ) );
add_shortcode( 'paragraph', array( $this, '_shortcode_paragraph' ) );
}
function tearDown() {
global $shortcode_tags;
unset( $shortcode_tags['dumptag'], $shortcode_tags['paragraph'] );
parent::tearDown();
}
function _shortcode_dumptag( $atts ) {
$out = '';
foreach ( $atts as $k => $v ) {
$out .= "$k = $v\n";
}
return $out;
}
function _shortcode_paragraph( $atts, $content ) {
$processed_atts = shortcode_atts(
array(
'class' => 'graf',
),
$atts
);
return "<p class='{$processed_atts['class']}'>$content</p>\n";
}
function test_the_content() {
$post_content = <<<EOF
<i>This is the excerpt.</i>
<!--more-->
This is the <b>body</b>.
EOF;
$post_id = self::factory()->post->create( compact( 'post_content' ) );
$expected = <<<EOF
<p><i>This is the excerpt.</i><br />
<span id="more-{$post_id}"></span><br />
This is the <b>body</b>.</p>
EOF;
$this->go_to( get_permalink( $post_id ) );
$this->assertTrue( is_single() );
$this->assertTrue( have_posts() );
$this->assertNull( the_post() );
$this->assertSame( strip_ws( $expected ), strip_ws( get_echo( 'the_content' ) ) );
}
function test_the_content_shortcode() {
$post_content = <<<EOF
[dumptag foo="bar" baz="123"]
[dumptag foo=123 baz=bar]
[dumptag http://example.com]
EOF;
$expected = <<<EOF
foo = bar
baz = 123
foo = 123
baz = bar
0 = http://example.com
EOF;
$post_id = self::factory()->post->create( compact( 'post_content' ) );
$this->go_to( get_permalink( $post_id ) );
$this->assertTrue( is_single() );
$this->assertTrue( have_posts() );
$this->assertNull( the_post() );
$this->assertSame( strip_ws( $expected ), strip_ws( get_echo( 'the_content' ) ) );
}
function test_the_content_shortcode_paragraph() {
$post_content = <<<EOF
Graf by itself:
[paragraph]my graf[/paragraph]
[paragraph foo="bar"]another graf with whitespace[/paragraph]
An [paragraph]inline graf[/paragraph], this doesn't make much sense.
A graf with a single EOL first:
[paragraph]blah[/paragraph]
EOF;
$expected = <<<EOF
<p>Graf by itself:</p>
<p class='graf'>my graf</p>
<p class='graf'>another graf with whitespace</p>
<p>An <p class='graf'>inline graf</p>
, this doesn’t make much sense.</p>
<p>A graf with a single EOL first:<br />
<p class='graf'>blah</p>
</p>
EOF;
$post_id = self::factory()->post->create( compact( 'post_content' ) );
$this->go_to( get_permalink( $post_id ) );
$this->assertTrue( is_single() );
$this->assertTrue( have_posts() );
$this->assertNull( the_post() );
$this->assertSame( strip_ws( $expected ), strip_ws( get_echo( 'the_content' ) ) );
}
function test_the_content_attribute_filtering() {
kses_init_filters();
// http://bpr3.org/?p=87
// The title attribute should make it through unfiltered.
$post_content = <<<EOF
<span class="Z3988" title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&rft.aulast=Mariat&rft.aufirst=Denis&rft. au=Denis+Mariat&rft.au=Sead+Taourit&rft.au=G%C3%A9rard+Gu%C3%A9rin& rft.title=Genetics+Selection+Evolution&rft.atitle=&rft.date=2003&rft. volume=35&rft.issue=1&rft.spage=119&rft.epage=133&rft.genre=article& rft.id=info:DOI/10.1051%2Fgse%3A2002039"></span>Mariat, D., Taourit, S., Guérin, G. (2003). . <span style="font-style: italic;">Genetics Selection Evolution, 35</span>(1), 119-133. DOI: <a rev="review" href= "http://dx.doi.org/10.1051/gse:2002039">10.1051/gse:2002039</a>
EOF;
$expected = <<<EOF
<p><span class="Z3988" title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&rft.aulast=Mariat&rft.aufirst=Denis&rft. au=Denis+Mariat&rft.au=Sead+Taourit&rft.au=G%C3%A9rard+Gu%C3%A9rin& rft.title=Genetics+Selection+Evolution&rft.atitle=&rft.date=2003&rft. volume=35&rft.issue=1&rft.spage=119&rft.epage=133&rft.genre=article& rft.id=info:DOI/10.1051%2Fgse%3A2002039"></span>Mariat, D., Taourit, S., Guérin, G. (2003). . <span style="font-style: italic">Genetics Selection Evolution, 35</span>(1), 119-133. DOI: <a rev="review" href="http://dx.doi.org/10.1051/gse:2002039">10.1051/gse:2002039</a></p>
EOF;
$post_id = self::factory()->post->create( compact( 'post_content' ) );
$this->go_to( get_permalink( $post_id ) );
$this->assertTrue( is_single() );
$this->assertTrue( have_posts() );
$this->assertNull( the_post() );
$this->assertSame( strip_ws( $expected ), strip_ws( get_echo( 'the_content' ) ) );
kses_remove_filters();
}
function test_the_content_attribute_value_with_colon() {
kses_init_filters();
// http://bpr3.org/?p=87
// The title attribute should make it through unfiltered.
$post_content = <<<EOF
<span title="My friends: Alice, Bob and Carol">foo</span>
EOF;
$expected = <<<EOF
<p><span title="My friends: Alice, Bob and Carol">foo</span></p>
EOF;
$post_id = self::factory()->post->create( compact( 'post_content' ) );
$this->go_to( get_permalink( $post_id ) );
$this->assertTrue( is_single() );
$this->assertTrue( have_posts() );
$this->assertNull( the_post() );
$this->assertSame( strip_ws( $expected ), strip_ws( get_echo( 'the_content' ) ) );
kses_remove_filters();
}
/**
* Ensure the_content handles a More block on a singular page.
*
* @ticket 46471
*
* @group blocks
*/
public function test_the_content_should_handle_more_block_on_singular() {
$post_content = <<<EOF
<!-- wp:paragraph -->
<p>Teaser part.</p>
<!-- /wp:paragraph -->
<!-- wp:more {"customText":"Read More"} -->
<!--more Read More-->
<!-- /wp:more -->
<!-- wp:paragraph -->
<p>Second block.</p>
<!-- /wp:paragraph -->
EOF;
$post_id = self::factory()->post->create( compact( 'post_content' ) );
$expected_without_teaser = <<<EOF
<span id="more-{$post_id}"></span>
<p>Second block.</p>
EOF;
$expected_with_teaser = <<<EOF
<p>Teaser part.</p>
<span id="more-{$post_id}"></span>
<p>Second block.</p>
EOF;
$this->go_to( get_permalink( $post_id ) );
$this->assertTrue( is_singular() );
$this->assertTrue( have_posts() );
$this->assertNull( the_post() );
// Without the teaser.
$actual = get_echo( 'the_content', array( null, true ) );
$this->assertSame( strip_ws( $expected_without_teaser ), strip_ws( $actual ) );
// With the teaser.
$actual = get_echo( 'the_content', array( null, false ) );
$this->assertSame( strip_ws( $expected_with_teaser ), strip_ws( $actual ) );
}
/**
* Ensure the_content handles a More block when using the noteaser text tag on a singular page.
*
* @ticket 46471
*
* @group blocks
*/
public function test_the_content_should_handle_more_block_when_noteaser_on_singular() {
$post_content = <<<EOF
<!-- wp:paragraph -->
<p>Teaser part.</p>
<!-- /wp:paragraph -->
<!-- wp:more -->
<!--more-->
<!--noteaser-->
<!-- /wp:more -->
<!-- wp:paragraph -->
<p>Second block.</p>
<!-- /wp:paragraph -->
EOF;
$post_id = self::factory()->post->create( compact( 'post_content' ) );
$expected = <<<EOF
<span id="more-{$post_id}"></span>
<!--noteaser-->
<p>Second block.</p>
EOF;
$this->go_to( get_permalink( $post_id ) );
$this->assertTrue( is_singular() );
$this->assertTrue( have_posts() );
$this->assertNull( the_post() );
$actual = get_echo( 'the_content', array( null, true ) );
$this->assertSame( strip_ws( $expected ), strip_ws( $actual ) );
$actual = get_echo( 'the_content', array( null, false ) );
$this->assertSame( strip_ws( $expected ), strip_ws( $actual ) );
}
/**
* Ensure the_content displays the teaser part with a read more link
* for a More block on a non-singular page.
*
* @ticket 46471
*
* @group blocks
*/
public function test_the_content_should_handle_more_block_when_non_singular() {
$post_content = <<<EOF
<!-- wp:paragraph -->
<p>Teaser part.</p>
<!-- /wp:paragraph -->
<!-- wp:more {"customText":"Read More"} -->
<!--more Read More-->
<!-- /wp:more -->
<!-- wp:paragraph -->
<p>Second block.</p>
<!-- /wp:paragraph -->
EOF;
$post_id = self::factory()->post->create( compact( 'post_content' ) );
$expected = <<<EOF
<span id="more-{$post_id}"></span>
<p>Second block.</p>
EOF;
$this->go_to( home_url() );
$this->assertFalse( is_singular() );
$this->assertTrue( have_posts() );
$this->assertNull( the_post() );
foreach ( array( true, false ) as $strip_teaser ) {
$actual = get_echo( 'the_content', array( null, $strip_teaser ) );
$this->assertStringContainsString( 'Teaser part', $actual );
$this->assertStringContainsString( 'Read More</a>', $actual );
$this->assertStringNotContainsString( '<!--more-->', $actual );
$this->assertStringNotContainsString( 'wp:more', $actual );
$this->assertStringNotContainsString( 'wp:paragraph', $actual );
}
}
/**
* Ensure the_content displays the teaser part with a read more link for a More block
* when using the noteaser text tag on a non-singular page.
*
* @ticket 46471
*
* @group blocks
*/
public function test_the_content_should_handle_more_block_when_noteaser_on_non_singular() {
$post_content = <<<EOF
<!-- wp:paragraph -->
<p>Teaser part.</p>
<!-- /wp:paragraph -->
<!-- wp:more -->
<!--more-->
<!--noteaser-->
<!-- /wp:more -->
<!-- wp:paragraph -->
<p>Second block.</p>
<!-- /wp:paragraph -->
EOF;
$post_id = self::factory()->post->create( compact( 'post_content' ) );
$this->go_to( home_url() );
$this->assertFalse( is_singular() );
$this->assertTrue( have_posts() );
$this->assertNull( the_post() );
foreach ( array( true, false ) as $strip_teaser ) {
$actual = get_echo( 'the_content', array( null, $strip_teaser ) );
$this->assertStringContainsString( 'Teaser part', $actual );
$this->assertStringContainsString( '(more…)</span></a>', $actual );
$this->assertStringNotContainsString( '<!--more-->', $actual );
$this->assertStringNotContainsString( '<!--noteaser-->', $actual ); // We placed the noteaser tag below the more tag.
$this->assertStringNotContainsString( 'wp:more', $actual );
$this->assertStringNotContainsString( 'wp:paragraph', $actual );
}
}
}