2022-12-09 11:59:24 +01:00
|
|
|
<?php
|
|
|
|
class Test_Activitypub_Mention extends ActivityPub_TestCase_Cache_HTTP {
|
|
|
|
public static $users = array(
|
|
|
|
'username@example.org' => array(
|
2023-06-23 14:54:29 +02:00
|
|
|
'id' => 'https://example.org/users/username',
|
2023-01-27 16:50:04 +01:00
|
|
|
'url' => 'https://example.org/users/username',
|
|
|
|
'name' => 'username',
|
2022-12-09 11:59:24 +01:00
|
|
|
),
|
|
|
|
);
|
|
|
|
/**
|
|
|
|
* @dataProvider the_content_provider
|
|
|
|
*/
|
|
|
|
public function test_the_content( $content, $content_with_mention ) {
|
|
|
|
add_filter( 'pre_get_remote_metadata_by_actor', array( get_called_class(), 'pre_get_remote_metadata_by_actor' ), 10, 2 );
|
|
|
|
$content = \Activitypub\Mention::the_content( $content );
|
|
|
|
remove_filter( 'pre_get_remote_metadata_by_actor', array( get_called_class(), 'pre_get_remote_metadata_by_actor' ) );
|
|
|
|
|
|
|
|
$this->assertEquals( $content_with_mention, $content );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function the_content_provider() {
|
2023-01-27 16:50:04 +01:00
|
|
|
$code = 'hallo <code>@username@example.org</code> test';
|
2023-01-27 16:55:52 +01:00
|
|
|
$pre = <<<ENDPRE
|
|
|
|
<pre>
|
|
|
|
Please don't mention @username@example.org
|
|
|
|
here.
|
|
|
|
</pre>
|
|
|
|
ENDPRE;
|
2022-12-09 11:59:24 +01:00
|
|
|
return array(
|
2022-12-09 13:39:48 +01:00
|
|
|
array( 'hallo @username@example.org test', 'hallo <a rel="mention" class="u-url mention" href="https://example.org/users/username">@<span>username</span></a> test' ),
|
|
|
|
array( 'hallo @pfefferle@notiz.blog test', 'hallo <a rel="mention" class="u-url mention" href="https://notiz.blog/author/matthias-pfefferle/">@<span>pfefferle</span></a> test' ),
|
2022-12-13 11:34:07 +01:00
|
|
|
array( 'hallo <a rel="mention" class="u-url mention" href="https://notiz.blog/author/matthias-pfefferle/">@<span>pfefferle</span>@notiz.blog</a> test', 'hallo <a rel="mention" class="u-url mention" href="https://notiz.blog/author/matthias-pfefferle/">@<span>pfefferle</span>@notiz.blog</a> test' ),
|
|
|
|
array( 'hallo <a rel="mention" class="u-url mention" href="https://notiz.blog/author/matthias-pfefferle/">@pfefferle@notiz.blog</a> test', 'hallo <a rel="mention" class="u-url mention" href="https://notiz.blog/author/matthias-pfefferle/">@pfefferle@notiz.blog</a> test' ),
|
|
|
|
array( 'hallo <a rel="mention" class="u-url mention" href="https://notiz.blog/@pfefferle/">@pfefferle@notiz.blog</a> test', 'hallo <a rel="mention" class="u-url mention" href="https://notiz.blog/@pfefferle/">@pfefferle@notiz.blog</a> test' ),
|
2023-04-26 10:08:22 +02:00
|
|
|
array( 'hallo <img src="abc" alt="https://notiz.blog/@pfefferle/" title="@pfefferle@notiz.blog"/> test', 'hallo <img src="abc" alt="https://notiz.blog/@pfefferle/" title="@pfefferle@notiz.blog"/> test' ),
|
2023-09-21 17:03:57 +02:00
|
|
|
array( '<!-- @pfefferle@notiz.blog -->', '<!-- @pfefferle@notiz.blog -->' ),
|
2023-01-27 16:50:04 +01:00
|
|
|
array( $code, $code ),
|
2023-01-27 16:55:52 +01:00
|
|
|
array( $pre, $pre ),
|
2022-12-09 11:59:24 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function pre_get_remote_metadata_by_actor( $pre, $actor ) {
|
|
|
|
$actor = ltrim( $actor, '@' );
|
|
|
|
if ( isset( self::$users[ $actor ] ) ) {
|
|
|
|
return self::$users[ $actor ];
|
|
|
|
}
|
|
|
|
return $pre;
|
|
|
|
}
|
|
|
|
}
|