Skip to content

Commit

Permalink
fix unittests
Browse files Browse the repository at this point in the history
pfefferle committed Jan 20, 2025
1 parent bb41713 commit aa88405
Showing 3 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion includes/class-comment.php
Original file line number Diff line number Diff line change
@@ -229,7 +229,7 @@ public static function should_be_federated( $comment ) {
return false;
}

if ( is_single_user() && \user_can( $user_id, 'publish_posts' ) ) {
if ( is_single_user() && \user_can( $user_id, 'activitypub' ) ) {
// On a single user site, comments by users with the `publish_posts` capability will be federated as the blog user.
$user_id = Actors::BLOG_USER_ID;
}
12 changes: 12 additions & 0 deletions tests/includes/class-test-comment.php
Original file line number Diff line number Diff line change
@@ -293,6 +293,9 @@ public function ability_to_federate_comment() {
'comment_content' => 'This is a sent comment.',
'comment_author_url' => 'https://example.com',
'comment_author_email' => '',
'comment_meta' => array(
'activitypub_status' => 'pending',
),
),
'expected' => array(
'was_sent' => true,
@@ -362,6 +365,9 @@ public function ability_to_federate_threaded_comment() {
'comment_content' => 'This is another comment.',
'comment_author_url' => 'https://example.com',
'comment_author_email' => '',
'comment_meta' => array(
'activitypub_status' => 'pending',
),
),
'expected' => array(
'was_sent' => false,
@@ -386,6 +392,9 @@ public function ability_to_federate_threaded_comment() {
'comment_content' => 'This is yet another comment.',
'comment_author_url' => 'https://example.com',
'comment_author_email' => '',
'comment_meta' => array(
'activitypub_status' => 'pending',
),
),
'expected' => array(
'was_sent' => true,
@@ -440,6 +449,9 @@ public function ability_to_federate_threaded_comment() {
'comment_content' => 'This is a parent comment that should not be possible.',
'comment_author_url' => 'https://example.com',
'comment_author_email' => '',
'comment_meta' => array(
'activitypub_status' => 'federated',
),
),
'comment' => array(
'comment_type' => 'comment',
24 changes: 24 additions & 0 deletions tests/includes/transformer/class-test-factory.php
Original file line number Diff line number Diff line change
@@ -42,6 +42,13 @@ class Test_Factory extends WP_UnitTestCase {
*/
protected static $comment_id;

/**
* Test user ID.
*
* @var int
*/
protected static $user_id;

/**
* Create fake data before tests run.
*
@@ -58,10 +65,20 @@ public static function wpSetUpBeforeClass( $factory ) {
)
);

self::$user_id = $factory->user->create(
array(
'role' => 'administrator',
)
);

// Create test comment.
self::$comment_id = $factory->comment->create(
array(
'comment_post_ID' => self::$post_id,
'user_id' => self::$user_id,
'comment_meta' => array(
'activitypub_status' => 'pending',
),
)
);
}
@@ -73,6 +90,7 @@ public static function wpTearDownAfterClass() {
wp_delete_post( self::$post_id, true );
wp_delete_post( self::$attachment_id, true );
wp_delete_comment( self::$comment_id, true );
wp_delete_user( self::$user_id, true );
}

/**
@@ -104,10 +122,16 @@ public function test_get_transformer_post() {
* @covers ::get_transformer
*/
public function test_get_transformer_attachment() {
// Allow attachment to be federated.
\add_post_type_support( 'attachment', 'activitypub' );

$attachment = get_post( self::$attachment_id );
$transformer = Factory::get_transformer( $attachment );

$this->assertInstanceOf( Attachment::class, $transformer );

// Remove support for attachment.
\remove_post_type_support( 'attachment', 'activitypub' );
}

/**

0 comments on commit aa88405

Please sign in to comment.