From bdd9bd877514b584fd398e7a0798d5bb46347cf1 Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Sun, 18 Aug 2019 22:16:59 +0200 Subject: [PATCH] fixed tests --- includes/class-hashtag.php | 11 +++++------ tests/test-class-activitypub-hashtag.php | 1 + 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/includes/class-hashtag.php b/includes/class-hashtag.php index d1f46e1..a50c6c5 100644 --- a/includes/class-hashtag.php +++ b/includes/class-hashtag.php @@ -31,7 +31,7 @@ class Hashtag { */ public static function insert_post( $id, $data ) { if ( preg_match_all( '/' . ACTIVITYPUB_HASHTAGS_REGEXP . '/i', $data->post_content, $match ) ) { - $tags = implode( ', ', $match[2] ); + $tags = implode( ', ', $match[1] ); wp_add_post_tags( $data->post_parent, $tags ); } @@ -59,16 +59,15 @@ class Hashtag { * @return string the final string */ public static function replace_with_links( $result ) { - $tag = $result[2]; - $space = $result[1]; - $tag_object = get_term_by( 'name', $result[2], 'post_tag' ); + $tag = $result[1]; + $tag_object = get_term_by( 'name', $result[1], 'post_tag' ); if ( $tag_object ) { $link = get_term_link( $tag_object, 'post_tag' ); - return "$space"; + return sprintf( '', $link, $tag ); } - return $space . '#' . $tag; + return '#' . $tag; } /** diff --git a/tests/test-class-activitypub-hashtag.php b/tests/test-class-activitypub-hashtag.php index 5eddeef..bfbacbb 100644 --- a/tests/test-class-activitypub-hashtag.php +++ b/tests/test-class-activitypub-hashtag.php @@ -13,6 +13,7 @@ class Test_Activitypub_Hashtag extends WP_UnitTestCase { return [ [ 'test', 'test' ], [ '#test', '#test' ], + [ 'hallo #test test', 'hallo #test test' ], ]; } }