fix unittests

This commit is contained in:
Matthias Pfefferle 2023-10-06 16:46:01 +02:00
parent 0185e38013
commit e57932b099

View file

@ -1,13 +1,11 @@
<?php <?php
class Test_Inbox extends WP_UnitTestCase { class Test_Inbox extends WP_UnitTestCase {
#[\ReturnTypeWillChange] public $post_permalink;
public $user_url;
var $post_permalink;
var $user_url;
public function setUp() { public function setUp() {
$authordata = \get_userdata( 1 ); $authordata = \get_userdata( 1 );
$this->user_url = $authordata->user_url; $this->user_url = $authordata->user_url;
$post = \wp_insert_post( $post = \wp_insert_post(
array( array(
@ -15,56 +13,56 @@ class Test_Inbox extends WP_UnitTestCase {
'post_content' => 'test', 'post_content' => 'test',
) )
); );
$this->post_permalink = \get_permalink( $post ); $this->post_permalink = \get_permalink( $post );
\add_filter( 'pre_get_remote_metadata_by_actor', array( '\Test_Inbox', 'get_remote_metadata_by_actor' ), 10, 2); \add_filter( 'pre_get_remote_metadata_by_actor', array( '\Test_Inbox', 'get_remote_metadata_by_actor' ), 10, 2 );
} }
public static function get_remote_metadata_by_actor( $value, $actor ) { public static function get_remote_metadata_by_actor( $value, $actor ) {
return array( return array(
"name" => "Example User", 'name' => 'Example User',
"icon" => array( 'icon' => array(
"url" => "https://example.com/icon", 'url' => 'https://example.com/icon',
), ),
); );
} }
public function test_convert_object_to_comment_data_basic() { public function test_convert_object_to_comment_data_basic() {
$inbox = new \Activitypub\Rest\Inbox(); $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 ],
"cc" => [ "https://www.w3.org/ns/activitystreams#Public" ], 'cc' => [ 'https://www.w3.org/ns/activitystreams#Public' ],
"object" => array( 'object' => array(
"id" => "123", 'id' => '123',
"url" => "https://example.com/example", 'url' => 'https://example.com/example',
"inReplyTo" => $this->post_permalink, 'inReplyTo' => $this->post_permalink,
"content" => "example", 'content' => 'example',
), ),
); );
$converted = $inbox->convert_object_to_comment_data($object); $converted = $inbox->convert_object_to_comment_data( $object );
$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'], '' );
$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 );
$this->assertEquals($converted["comment_meta"]["source_id"], "http://123"); $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']['source_url'], 'https://example.com/example' );
$this->assertEquals($converted["comment_meta"]["avatar_url"], "https://example.com/icon"); $this->assertEquals( $converted['comment_meta']['avatar_url'], 'https://example.com/icon' );
$this->assertEquals($converted["comment_meta"]["protocol"], "activitypub"); $this->assertEquals( $converted['comment_meta']['protocol'], 'activitypub' );
} }
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(); $inbox = new \Activitypub\Rest\Inbox();
$object = array( $object = array(
"to" => ["https://example.com/profile/test"], 'to' => array( 'https://example.com/profile/test' ),
"cc" => [], 'cc' => array(),
); );
$converted = $inbox->convert_object_to_comment_data($object); $converted = $inbox->convert_object_to_comment_data( $object );
$this->assertFalse($converted); $this->assertFalse( $converted );
} }
} }