fix tests

This commit is contained in:
Matthias Pfefferle 2023-10-06 17:43:03 +02:00
parent 1a58b69b80
commit 69a0a90b10
2 changed files with 7 additions and 9 deletions

View file

@ -341,7 +341,7 @@ class Inbox {
public static function convert_object_to_comment_data( $object, $user_id ) { public static function convert_object_to_comment_data( $object, $user_id ) {
$object['user_id'] = $user_id; $object['user_id'] = $user_id;
if ( ! isset( $object['object']['inReplyTo'] ) ) { if ( ! isset( $object['object']['inReplyTo'] ) ) {
return; return false;
} }
// check if Activity is public or not // check if Activity is public or not
@ -356,13 +356,13 @@ class Inbox {
// Only handle replies // Only handle replies
if ( ! isset( $object['object']['inReplyTo'] ) ) { if ( ! isset( $object['object']['inReplyTo'] ) ) {
return; return false;
} }
$in_reply_to = $object['object']['inReplyTo']; $in_reply_to = $object['object']['inReplyTo'];
// Comment already exists // Comment already exists
if ( \Activitypub\object_id_to_comment( $id ) ) { if ( \Activitypub\object_id_to_comment( $id ) ) {
return; return false;
} }
$parent_comment = \Activitypub\object_id_to_comment( $in_reply_to ); $parent_comment = \Activitypub\object_id_to_comment( $in_reply_to );
@ -376,7 +376,7 @@ class Inbox {
$comment_post_id = $parent_comment->comment_post_ID; $comment_post_id = $parent_comment->comment_post_ID;
} }
if ( ! $comment_post_id ) { if ( ! $comment_post_id ) {
return; return false;
} }
return array( return array(

View file

@ -28,7 +28,6 @@ class Test_Inbox extends WP_UnitTestCase {
} }
public function test_convert_object_to_comment_data_basic() { public function test_convert_object_to_comment_data_basic() {
$inbox = new \Activitypub\Rest\Inbox();
$object = array( $object = array(
'actor' => $this->user_url, 'actor' => $this->user_url,
'to' => [ $this->user_url ], 'to' => [ $this->user_url ],
@ -40,13 +39,13 @@ class Test_Inbox extends WP_UnitTestCase {
'content' => 'example', 'content' => 'example',
), ),
); );
$converted = $inbox->convert_object_to_comment_data( $object, 1 ); $converted = \Activitypub\Rest\Inbox::convert_object_to_comment_data( $object, 1 );
$this->assertGreaterThan( 1, $converted['comment_post_ID'] ); $this->assertGreaterThan( 1, $converted['comment_post_ID'] );
$this->assertEquals( $converted['comment_author'], 'Example User' ); $this->assertEquals( $converted['comment_author'], 'Example User' );
$this->assertEquals( $converted['comment_author_url'], 'http://example.org' ); $this->assertEquals( $converted['comment_author_url'], 'http://example.org' );
$this->assertEquals( $converted['comment_content'], 'example' ); $this->assertEquals( $converted['comment_content'], 'example' );
$this->assertEquals( $converted['comment_type'], '' ); $this->assertEquals( $converted['comment_type'], 'comment' );
$this->assertEquals( $converted['comment_author_email'], '' ); $this->assertEquals( $converted['comment_author_email'], '' );
$this->assertEquals( $converted['comment_parent'], 0 ); $this->assertEquals( $converted['comment_parent'], 0 );
$this->assertArrayHasKey( 'comment_meta', $converted ); $this->assertArrayHasKey( 'comment_meta', $converted );
@ -57,12 +56,11 @@ class Test_Inbox extends WP_UnitTestCase {
} }
public function test_convert_object_to_comment_data_non_public_rejected() { public function test_convert_object_to_comment_data_non_public_rejected() {
$inbox = new \Activitypub\Rest\Inbox();
$object = array( $object = array(
'to' => array( 'https://example.com/profile/test' ), 'to' => array( 'https://example.com/profile/test' ),
'cc' => array(), 'cc' => array(),
); );
$converted = $inbox->convert_object_to_comment_data( $object, 1 ); $converted = \Activitypub\Rest\Inbox::convert_object_to_comment_data( $object, 1 );
$this->assertFalse( $converted ); $this->assertFalse( $converted );
} }
} }