[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @group activity 5 */ 6 class BP_Tests_Activity_Filters extends BP_UnitTestCase { 7 /** 8 * @group mentions 9 * @group bp_activity_at_name_filter 10 */ 11 public function test_bp_activity_at_name_filter() { 12 $u1 = self::factory()->user->create( array( 13 'user_login' => 'foobarbaz', 14 'user_nicename' => 'foobarbaz', 15 ) ); 16 17 $u2 = self::factory()->user->create( array( 18 'user_login' => 'foo2', 19 'user_nicename' => 'foo2', 20 ) ); 21 22 $u1_mention_name = bp_activity_get_user_mentionname( $u1 ); 23 $u1_domain = bp_core_get_user_domain( $u1 ); 24 $u2_mention_name = bp_activity_get_user_mentionname( $u2 ); 25 $u2_domain = bp_core_get_user_domain( $u2 ); 26 27 // mentions normal text should be replaced 28 $at_name_in_text = sprintf( 'Hello @%s', $u1_mention_name ); 29 $at_name_in_text_final = "Hello <a class='bp-suggestions-mention' href='" . $u1_domain . "' rel='nofollow'>@$u1_mention_name</a>"; 30 $this->assertEquals( $at_name_in_text_final, bp_activity_at_name_filter( $at_name_in_text ) ); 31 32 // mentions inside links sholudn't be replaced 33 // inside href 34 $at_name_in_mailto = sprintf( "Send messages to <a href='mail@%s.com'>Foo Bar Baz</a>", $u1_mention_name ); 35 $at_name_in_mailto_final = sprintf( "Send messages to <a href='mail@%s.com'>Foo Bar Baz</a>", $u1_mention_name ); 36 $this->assertEquals( $at_name_in_mailto_final, bp_activity_at_name_filter( $at_name_in_mailto ) ); 37 38 // inside linked text 39 $at_name_in_link = sprintf( '<a href="https://twitter.com/%1$s">@%1$s</a>', $u1_mention_name ); 40 $at_name_in_link_final = sprintf( '<a href="https://twitter.com/%1$s">@%1$s</a>', $u1_mention_name ); 41 $this->assertEquals( $at_name_in_link_final, bp_activity_at_name_filter( $at_name_in_link ) ); 42 43 // Don't link non-existent users 44 $text = "Don't link @non @existent @users"; 45 $this->assertSame( $text, bp_activity_at_name_filter( $text ) ); 46 47 // Don't link the domain name of the site 48 preg_match( '|https?://([^/]+)|', home_url(), $matches ); 49 if ( ! empty( $matches[1] ) ) { 50 $text = $matches[1] . " Don't link the domain name " . $matches[1]; 51 } 52 $this->assertSame( $text, bp_activity_at_name_filter( $text ) ); 53 54 // Multiples 55 $at_name_in_mailto = sprintf( "Send messages to @%s <a href='mail@%s.com'>Foo Bar Baz</a>. Please CC <a href='http://twitter.com/foo2'>@foo2</a>.", $u1_mention_name, $u1_mention_name, $u2_mention_name, $u2_mention_name ); 56 $at_name_in_mailto_final = sprintf( 'Send messages to <a class=\'bp-suggestions-mention\' href=\'%s\' rel=\'nofollow\'>@%s</a> <a href=\'mail@%s.com\'>Foo Bar Baz</a>. Please CC <a href=\'http://twitter.com/%s\'>@%s</a>.', $u1_domain, $u1_mention_name, $u1_mention_name, $u2_mention_name, $u2_mention_name ); 57 $this->assertEquals( $at_name_in_mailto_final, bp_activity_at_name_filter( $at_name_in_mailto ) ); 58 } 59 60 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Dec 22 01:00:54 2024 | Cross-referenced by PHPXref 0.7.1 |