wordpress-activitypub/tests/test-class-activitypub-activity.php
Matthias Pfefferle f0c52580ff
Improve AUTHORIZED_FETCH (#728)
* simplify code

* show limited profile informations

* exclude application user

* use actor instead of user

* change JS

* use Application instead of Application_User

* re-add use

* add summary

* Improves comment intent

* remove limited actor json in favour of the application user

---------

Co-authored-by: Django Doucet <mediaformat.ux@gmail.com>
2024-05-03 08:54:06 +02:00

68 lines
2 KiB
PHP

<?php
use DMS\PHPUnitExtensions\ArraySubset\Assert;
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',
function ( $mentions ) {
$mentions['@alex'] = 'https://example.com/alex';
return $mentions;
},
10
);
$activitypub_post = \Activitypub\Transformer\Post::transform( get_post( $post ) )->to_object();
$activitypub_activity = new \Activitypub\Activity\Activity();
$activitypub_activity->set_type( 'Create' );
$activitypub_activity->set_object( $activitypub_post );
$this->assertContains( \Activitypub\get_rest_url_by_path( 'actors/1/followers' ), $activitypub_activity->get_to() );
$this->assertContains( 'https://example.com/alex', $activitypub_activity->get_cc() );
remove_all_filters( 'activitypub_extract_mentions' );
\wp_trash_post( $post );
}
public function test_object_transformation() {
$test_array = array(
'id' => 'https://example.com/post/123',
'type' => 'Note',
'content' => 'Hello world!',
);
$object = \Activitypub\Activity\Base_Object::init_from_array( $test_array );
$this->assertEquals( 'Hello world!', $object->get_content() );
$new_array = $object->to_array();
// Ignore the added json-ld context for now.
unset( $new_array['@context'] );
$this->assertEquals( $test_array, $new_array );
}
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() );
}
}