6e7f82bf42
* init * save source id * fix delete and add improve undo * test new functions * add support for threaded comments * some formatting * check if URL is no longer available ...and returns either status 410 or 404. * improve delete handler * improve update handler * `object` and `actor` are already required by the inbox endpoint * fix typo * simplify queries * cosmetics * fix unit tests * schedule delete comments of deleted actor (#575) * schedule delete comments of deleted actor * phpcs --------- Co-authored-by: Django Doucet <django.doucet@webdevstudios.com> * move `get_comments_by_actor` to interactions collection * consistent wording * implement Tombstone * fix follow issue * fix inbox-create * added missing namespace * check if field is set * Fix namespacing issue * update profile and update interaction * fields are already validated by inbox * optimize avatar handling --------- Co-authored-by: Django <mediaformat.ux@gmail.com> Co-authored-by: Django Doucet <django.doucet@webdevstudios.com>
70 lines
2 KiB
PHP
70 lines
2 KiB
PHP
<?php
|
|
class Test_Activitypub_Create_Handler extends WP_UnitTestCase {
|
|
public $user_id;
|
|
public $user_url;
|
|
public $post_id;
|
|
public $post_permalink;
|
|
|
|
public function set_up() {
|
|
$this->user_id = 1;
|
|
$authordata = \get_userdata( $this->user_id );
|
|
$this->user_url = $authordata->user_url;
|
|
|
|
$this->post_id = \wp_insert_post(
|
|
array(
|
|
'post_author' => $this->user_id,
|
|
'post_content' => 'test',
|
|
)
|
|
);
|
|
$this->post_permalink = \get_permalink( $this->post_id );
|
|
|
|
\add_filter( 'pre_get_remote_metadata_by_actor', array( '\Test_Activitypub_Create_Handler', 'get_remote_metadata_by_actor' ), 0, 2 );
|
|
}
|
|
|
|
public static function get_remote_metadata_by_actor( $value, $actor ) {
|
|
return array(
|
|
'name' => 'Example User',
|
|
'icon' => array(
|
|
'url' => 'https://example.com/icon',
|
|
),
|
|
'url' => $actor,
|
|
'id' => 'http://example.org/users/example',
|
|
);
|
|
}
|
|
|
|
public function create_test_object( $id = 'https://example.com/123' ) {
|
|
return array(
|
|
'actor' => $this->user_url,
|
|
'id' => 'https://example.com/id/' . microtime( true ),
|
|
'to' => [ $this->user_url ],
|
|
'cc' => [ 'https://www.w3.org/ns/activitystreams#Public' ],
|
|
'object' => array(
|
|
'id' => $id,
|
|
'url' => 'https://example.com/example',
|
|
'inReplyTo' => $this->post_permalink,
|
|
'content' => 'example',
|
|
),
|
|
);
|
|
}
|
|
|
|
public function test_handle_create_object_unset_rejected() {
|
|
$object = $this->create_test_object();
|
|
unset( $object['object'] );
|
|
$converted = Activitypub\Handler\Create::handle_create( $object, $this->user_id );
|
|
$this->assertNull( $converted );
|
|
}
|
|
|
|
public function test_handle_create_non_public_rejected() {
|
|
$object = $this->create_test_object();
|
|
$object['cc'] = [];
|
|
$converted = Activitypub\Handler\Create::handle_create( $object, $this->user_id );
|
|
$this->assertNull( $converted );
|
|
}
|
|
|
|
public function test_handle_create_no_id_rejected() {
|
|
$object = $this->create_test_object();
|
|
unset( $object['object']['id'] );
|
|
$converted = Activitypub\Handler\Create::handle_create( $object, $this->user_id );
|
|
$this->assertNull( $converted );
|
|
}
|
|
}
|