mirrored from git://develop.git.wordpress.org/
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add custom template parameter to get_the_term_list and related tests
- Loading branch information
1 parent
fc96319
commit 3326d35
Showing
2 changed files
with
106 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
/** | ||
* @group taxonomy | ||
* @group term | ||
*/ | ||
class Tests_Term_Template extends WP_UnitTestCase { | ||
protected static $post_id; | ||
protected static $term_id; | ||
protected static $second_term_id; | ||
|
||
public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { | ||
self::$post_id = $factory->post->create(); | ||
self::$term_id = $factory->term->create( | ||
array( | ||
'taxonomy' => 'category', | ||
'name' => 'Test Category', | ||
) | ||
); | ||
self::$second_term_id = $factory->term->create( | ||
array( | ||
'taxonomy' => 'category', | ||
'name' => 'Another Category', | ||
) | ||
); | ||
wp_set_post_terms( self::$post_id, array( self::$term_id, self::$second_term_id ), 'category' ); | ||
} | ||
|
||
/** | ||
* @ticket 30705 | ||
*/ | ||
public function test_get_the_term_list_default_template() { | ||
$list = get_the_term_list( self::$post_id, 'category', '', ', ', '' ); | ||
|
||
$this->assertMatchesRegularExpression( | ||
'/<a href="[^"]*" rel="tag">Test Category<\/a>/', | ||
$list | ||
); | ||
$this->assertMatchesRegularExpression( | ||
'/<a href="[^"]*" rel="tag">Another Category<\/a>/', | ||
$list | ||
); | ||
} | ||
|
||
/** | ||
* @ticket 30705 | ||
*/ | ||
public function test_get_the_term_list_custom_template() { | ||
$custom_template = '<span class="term"><a href="%1$s">%2$s</a></span>'; | ||
$list = get_the_term_list( self::$post_id, 'category', '', ', ', '', $custom_template ); | ||
|
||
$this->assertMatchesRegularExpression( | ||
'/<span class="term"><a href="[^"]*">Test Category<\/a><\/span>/', | ||
$list | ||
); | ||
} | ||
|
||
/** | ||
* @ticket 30705 | ||
*/ | ||
public function test_get_the_term_list_escaping() { | ||
$unsafe_term_id = self::factory()->term->create( | ||
array( | ||
'taxonomy' => 'category', | ||
'name' => 'Test & Category <script>alert("xss")</script>', | ||
) | ||
); | ||
wp_set_post_terms( self::$post_id, array( $unsafe_term_id ), 'category' ); | ||
|
||
$list = get_the_term_list( self::$post_id, 'category', '', ', ', '' ); | ||
|
||
$this->assertStringContainsString( 'Test & Category', $list ); | ||
$this->assertStringNotContainsString( '<script>', $list ); | ||
} | ||
} |