forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfiltering.php
More file actions
115 lines (88 loc) · 2.5 KB
/
filtering.php
File metadata and controls
115 lines (88 loc) · 2.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
<?php
/**
* Save and fetch posts to make sure content is properly filtered.
*
* These tests don't care what code is responsible for filtering
* or how it is called, just that it happens when a post is saved.
*
* @group post
* @group formatting
*/
class Tests_Post_Filtering extends WP_UnitTestCase {
function setUp() {
parent::setUp();
update_option( 'use_balanceTags', 1 );
kses_init_filters();
}
function tearDown() {
kses_remove_filters();
parent::tearDown();
}
// A simple test to make sure unclosed tags are fixed.
function test_post_content_unknown_tag() {
$content = <<<EOF
<foobar>no such tag</foobar>
EOF;
$expected = <<<EOF
no such tag
EOF;
$id = self::factory()->post->create( array( 'post_content' => $content ) );
$post = get_post( $id );
$this->assertSame( $expected, $post->post_content );
}
// A simple test to make sure unbalanced tags are fixed.
function test_post_content_unbalanced_tag() {
$content = <<<EOF
<i>italics
EOF;
$expected = <<<EOF
<i>italics</i>
EOF;
$id = self::factory()->post->create( array( 'post_content' => $content ) );
$post = get_post( $id );
$this->assertSame( $expected, $post->post_content );
}
// Test KSES filtering of disallowed attribute.
function test_post_content_disallowed_attr() {
$content = <<<EOF
<img src='foo' width='500' href='shlorp' />
EOF;
$expected = <<<EOF
<img src='foo' width='500' />
EOF;
$id = self::factory()->post->create( array( 'post_content' => $content ) );
$post = get_post( $id );
$this->assertSame( $expected, $post->post_content );
}
/**
* test kses bug. xhtml does not require space before closing empty element
*
* @ticket 12394
*/
function test_post_content_xhtml_empty_elem() {
$content = <<<EOF
<img src='foo' width='500' height='300'/>
EOF;
$expected = <<<EOF
<img src='foo' width='500' height='300' />
EOF;
$id = self::factory()->post->create( array( 'post_content' => $content ) );
$post = get_post( $id );
$this->assertSame( $expected, $post->post_content );
}
// Make sure unbalanced tags are untouched when the balance option is off.
function test_post_content_nobalance_nextpage_more() {
update_option( 'use_balanceTags', 0 );
$content = <<<EOF
<em>some text<!--nextpage-->
that's continued after the jump</em>
<!--more-->
<p>and the next page
<!--nextpage-->
breaks the graf</p>
EOF;
$id = self::factory()->post->create( array( 'post_content' => $content ) );
$post = get_post( $id );
$this->assertSame( $content, $post->post_content );
}
}