2023-01-24 06:23:23 +01:00
|
|
|
<?php
|
|
|
|
class Test_Inbox extends WP_UnitTestCase {
|
2023-10-06 16:46:01 +02:00
|
|
|
public $post_permalink;
|
|
|
|
public $user_url;
|
2023-01-24 06:23:23 +01:00
|
|
|
|
2023-10-06 16:50:27 +02:00
|
|
|
public function set_up() {
|
2023-10-06 16:46:01 +02:00
|
|
|
$authordata = \get_userdata( 1 );
|
|
|
|
$this->user_url = $authordata->user_url;
|
2023-01-24 06:23:23 +01:00
|
|
|
|
|
|
|
$post = \wp_insert_post(
|
|
|
|
array(
|
|
|
|
'post_author' => 1,
|
|
|
|
'post_content' => 'test',
|
|
|
|
)
|
|
|
|
);
|
2023-10-06 16:46:01 +02:00
|
|
|
$this->post_permalink = \get_permalink( $post );
|
2023-01-24 06:23:23 +01:00
|
|
|
|
2023-10-06 16:46:01 +02:00
|
|
|
\add_filter( 'pre_get_remote_metadata_by_actor', array( '\Test_Inbox', 'get_remote_metadata_by_actor' ), 10, 2 );
|
2023-01-24 06:23:23 +01:00
|
|
|
}
|
|
|
|
|
2023-01-24 06:34:15 +01:00
|
|
|
public static function get_remote_metadata_by_actor( $value, $actor ) {
|
2023-10-06 16:46:01 +02:00
|
|
|
return array(
|
|
|
|
'name' => 'Example User',
|
|
|
|
'icon' => array(
|
|
|
|
'url' => 'https://example.com/icon',
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2023-01-24 06:23:23 +01:00
|
|
|
|
|
|
|
public function test_convert_object_to_comment_data_basic() {
|
2023-10-06 16:46:01 +02:00
|
|
|
$inbox = new \Activitypub\Rest\Inbox();
|
|
|
|
$object = array(
|
|
|
|
'actor' => $this->user_url,
|
|
|
|
'to' => [ $this->user_url ],
|
|
|
|
'cc' => [ 'https://www.w3.org/ns/activitystreams#Public' ],
|
|
|
|
'object' => array(
|
|
|
|
'id' => '123',
|
|
|
|
'url' => 'https://example.com/example',
|
|
|
|
'inReplyTo' => $this->post_permalink,
|
|
|
|
'content' => 'example',
|
|
|
|
),
|
|
|
|
);
|
|
|
|
$converted = $inbox->convert_object_to_comment_data( $object );
|
2023-01-24 06:23:23 +01:00
|
|
|
|
2023-10-06 16:46:01 +02:00
|
|
|
$this->assertGreaterThan( 1, $converted['comment_post_ID'] );
|
|
|
|
$this->assertEquals( $converted['comment_author'], 'Example User' );
|
|
|
|
$this->assertEquals( $converted['comment_author_url'], 'http://example.org' );
|
|
|
|
$this->assertEquals( $converted['comment_content'], 'example' );
|
|
|
|
$this->assertEquals( $converted['comment_type'], '' );
|
|
|
|
$this->assertEquals( $converted['comment_author_email'], '' );
|
|
|
|
$this->assertEquals( $converted['comment_parent'], 0 );
|
|
|
|
$this->assertArrayHasKey( 'comment_meta', $converted );
|
|
|
|
$this->assertEquals( $converted['comment_meta']['source_id'], 'http://123' );
|
|
|
|
$this->assertEquals( $converted['comment_meta']['source_url'], 'https://example.com/example' );
|
|
|
|
$this->assertEquals( $converted['comment_meta']['avatar_url'], 'https://example.com/icon' );
|
|
|
|
$this->assertEquals( $converted['comment_meta']['protocol'], 'activitypub' );
|
|
|
|
}
|
2023-01-24 06:23:23 +01:00
|
|
|
|
|
|
|
public function test_convert_object_to_comment_data_non_public_rejected() {
|
2023-10-06 16:46:01 +02:00
|
|
|
$inbox = new \Activitypub\Rest\Inbox();
|
|
|
|
$object = array(
|
|
|
|
'to' => array( 'https://example.com/profile/test' ),
|
|
|
|
'cc' => array(),
|
|
|
|
);
|
|
|
|
$converted = $inbox->convert_object_to_comment_data( $object );
|
|
|
|
$this->assertFalse( $converted );
|
|
|
|
}
|
2023-01-24 06:23:23 +01:00
|
|
|
}
|