2022-12-08 21:23:19 +01:00
|
|
|
<?php
|
2023-12-12 17:10:52 +01:00
|
|
|
use DMS\PHPUnitExtensions\ArraySubset\Assert;
|
|
|
|
|
2022-12-08 21:23:19 +01:00
|
|
|
class Test_Activitypub_Activity extends WP_UnitTestCase {
|
|
|
|
public function test_activity_mentions() {
|
|
|
|
$post = \wp_insert_post(
|
|
|
|
array(
|
|
|
|
'post_author' => 1,
|
|
|
|
'post_content' => '@alex hello',
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
add_filter(
|
|
|
|
'activitypub_extract_mentions',
|
2023-12-12 17:10:52 +01:00
|
|
|
function ( $mentions ) {
|
2022-12-09 11:59:11 +01:00
|
|
|
$mentions['@alex'] = 'https://example.com/alex';
|
2022-12-08 21:23:19 +01:00
|
|
|
return $mentions;
|
|
|
|
},
|
2022-12-09 11:59:11 +01:00
|
|
|
10
|
2022-12-08 21:23:19 +01:00
|
|
|
);
|
2023-11-22 13:59:39 +01:00
|
|
|
|
2023-11-20 18:15:54 +01:00
|
|
|
$wp_post = get_post( $post );
|
2023-11-30 08:36:05 +01:00
|
|
|
$activitypub_post = \Activitypub\Transformer\Transformer_Factory::instance()->transform();
|
2022-12-08 21:23:19 +01:00
|
|
|
|
2023-07-03 17:59:42 +02:00
|
|
|
$activitypub_activity = new \Activitypub\Activity\Activity();
|
|
|
|
$activitypub_activity->set_type( 'Create' );
|
|
|
|
$activitypub_activity->set_object( $activitypub_post );
|
2022-12-08 21:23:19 +01:00
|
|
|
|
2023-06-01 08:05:19 +02:00
|
|
|
$this->assertContains( \Activitypub\get_rest_url_by_path( 'users/1/followers' ), $activitypub_activity->get_to() );
|
2022-12-08 21:23:19 +01:00
|
|
|
$this->assertContains( 'https://example.com/alex', $activitypub_activity->get_cc() );
|
|
|
|
|
2022-12-09 11:59:11 +01:00
|
|
|
remove_all_filters( 'activitypub_extract_mentions' );
|
2022-12-08 21:23:19 +01:00
|
|
|
\wp_trash_post( $post );
|
|
|
|
}
|
2023-06-26 11:08:04 +02:00
|
|
|
|
|
|
|
public function test_object_transformation() {
|
|
|
|
$test_array = array(
|
|
|
|
'id' => 'https://example.com/post/123',
|
|
|
|
'type' => 'Note',
|
|
|
|
'content' => 'Hello world!',
|
|
|
|
);
|
|
|
|
|
2023-07-06 14:42:18 +02:00
|
|
|
$object = \Activitypub\Activity\Base_Object::init_from_array( $test_array );
|
2023-06-26 11:08:04 +02:00
|
|
|
|
|
|
|
$this->assertEquals( 'Hello world!', $object->get_content() );
|
|
|
|
$this->assertEquals( $test_array, $object->to_array() );
|
|
|
|
}
|
2023-12-12 17:10:52 +01:00
|
|
|
|
|
|
|
public function test_activity_object() {
|
|
|
|
$test_array = array(
|
|
|
|
'id' => 'https://example.com/post/123',
|
|
|
|
'type' => 'Create',
|
|
|
|
'object' => array(
|
|
|
|
'id' => 'https://example.com/post/123/activity',
|
|
|
|
'type' => 'Note',
|
|
|
|
'content' => 'Hello world!',
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
$activity = \Activitypub\Activity\Activity::init_from_array( $test_array );
|
|
|
|
|
|
|
|
$this->assertEquals( 'Hello world!', $activity->get_object()->get_content() );
|
|
|
|
Assert::assertArraySubset( $test_array, $activity->to_array() );
|
|
|
|
}
|
2022-12-08 21:23:19 +01:00
|
|
|
}
|