Skip to content

Commit a786491

Browse files
Tests: Cover allowed_tags().
Verify: - Default HTML entity-encoded allowed tags output from `$allowedtags`. - Custom allowed tags and attributes formatting. - Empty `$allowedtags` handling. Developed in #15316. Props devmuhib, huzaifaalmesbah. See #66757. git-svn-id: https://develop.svn.wordpress.org/trunk@65793 602fd350-edb4-49c9-b593-d223f7449a82
1 parent f470162 commit a786491

1 file changed

Lines changed: 79 additions & 0 deletions

File tree

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
3+
/**
4+
* Tests for the `allowed_tags()` function.
5+
*
6+
* @group general
7+
* @group formatting
8+
*
9+
* @covers ::allowed_tags
10+
*/
11+
class Tests_General_AllowedTags extends WP_UnitTestCase {
12+
13+
/**
14+
* Original allowed tags.
15+
*
16+
* @var array
17+
*/
18+
private $original_allowedtags;
19+
20+
public function set_up() {
21+
global $allowedtags;
22+
23+
parent::set_up();
24+
25+
$this->original_allowedtags = $allowedtags;
26+
}
27+
28+
public function tear_down() {
29+
global $allowedtags;
30+
31+
$allowedtags = $this->original_allowedtags;
32+
33+
parent::tear_down();
34+
}
35+
36+
/**
37+
* Tests that allowed_tags() returns encoded string of default allowed tags.
38+
*
39+
* @ticket 65819
40+
*/
41+
public function test_allowed_tags_default() {
42+
$expected = '&lt;a href=&quot;&quot; title=&quot;&quot;&gt; &lt;abbr title=&quot;&quot;&gt; &lt;acronym title=&quot;&quot;&gt; &lt;b&gt; &lt;blockquote cite=&quot;&quot;&gt; &lt;cite&gt; &lt;code&gt; &lt;del datetime=&quot;&quot;&gt; &lt;em&gt; &lt;i&gt; &lt;q cite=&quot;&quot;&gt; &lt;s&gt; &lt;strike&gt; &lt;strong&gt; ';
43+
$this->assertSame( $expected, allowed_tags() );
44+
}
45+
46+
/**
47+
* Tests that allowed_tags() formats custom tags and attributes correctly.
48+
*
49+
* @ticket 65819
50+
*/
51+
public function test_allowed_tags_custom() {
52+
global $allowedtags;
53+
54+
$allowedtags = array(
55+
'em' => array(),
56+
'strong' => array( 'class' => true ),
57+
'span' => array(
58+
'class' => true,
59+
'id' => true,
60+
),
61+
);
62+
63+
$expected = '&lt;em&gt; &lt;strong class=&quot;&quot;&gt; &lt;span class=&quot;&quot; id=&quot;&quot;&gt; ';
64+
$this->assertSame( $expected, allowed_tags() );
65+
}
66+
67+
/**
68+
* Tests that allowed_tags() returns an empty string when the `$allowedtags` global is empty.
69+
*
70+
* @ticket 65819
71+
*/
72+
public function test_allowed_tags_empty() {
73+
global $allowedtags;
74+
75+
$allowedtags = array();
76+
77+
$this->assertSame( '', allowed_tags() );
78+
}
79+
}

0 commit comments

Comments
 (0)