Skip to content

Commit 946b01f

Browse files
committed
Tests: Cover _wp_add_global_attributes().
Test merging global attributes into an existing attribute array, expanding `true` to global attributes, and preserving other values. Developed in: #14744 Props shailu25. See #65819. git-svn-id: https://develop.svn.wordpress.org/trunk@64771 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 102603a commit 946b01f

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
/**
4+
* Tests for _wp_add_global_attributes().
5+
*
6+
* @group kses
7+
*
8+
* @covers ::_wp_add_global_attributes
9+
*/
10+
class Tests_Kses_wpAddGlobalAttributes extends WP_UnitTestCase {
11+
12+
/**
13+
* @ticket 65819
14+
*/
15+
public function test_merges_global_attributes_into_array() {
16+
$result = _wp_add_global_attributes(
17+
array(
18+
'href' => true,
19+
)
20+
);
21+
22+
$this->assertTrue( $result['href'] );
23+
$this->assertTrue( $result['class'] );
24+
$this->assertTrue( $result['id'] );
25+
$this->assertTrue( $result['style'] );
26+
$this->assertTrue( $result['data-*'] );
27+
$this->assertTrue( $result['aria-label'] );
28+
}
29+
30+
/**
31+
* @ticket 65819
32+
*/
33+
public function test_true_value_becomes_globals_only() {
34+
$result = _wp_add_global_attributes( true );
35+
36+
$this->assertIsArray( $result );
37+
$this->assertTrue( $result['class'] );
38+
$this->assertArrayNotHasKey( 'href', $result );
39+
}
40+
41+
/**
42+
* @ticket 65819
43+
*/
44+
public function test_non_array_non_true_value_is_returned_unchanged() {
45+
$this->assertFalse( _wp_add_global_attributes( false ) );
46+
$this->assertSame( 'keep', _wp_add_global_attributes( 'keep' ) );
47+
}
48+
}

0 commit comments

Comments
 (0)