Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pfefferle committed Dec 20, 2024
1 parent 9faf36b commit 2ca5b5e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
4 changes: 2 additions & 2 deletions includes/class-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public static function register_settings() {
array(
'type' => 'boolean',
'description' => \__( 'Send notifications via e-mail when a new follower is added.', 'activitypub' ),
'default' => false,
'default' => '0',
)
);
\register_setting(
Expand All @@ -328,7 +328,7 @@ public static function register_settings() {
array(
'type' => 'boolean',
'description' => \__( 'Send notifications via e-mail when a direct message is received.', 'activitypub' ),
'default' => false,
'default' => '0',
)
);

Expand Down
4 changes: 2 additions & 2 deletions includes/class-mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ public static function init() {
\add_filter( 'comment_notification_text', array( self::class, 'comment_notification_text' ), 10, 2 );

// New follower notification.
if ( \get_option( 'activitypub_mailer_new_follower', '0' ) ) {
if ( '1' === \get_option( 'activitypub_mailer_new_follower', '0' ) ) {
\add_action( 'activitypub_notification_follow', array( self::class, 'new_follower' ) );
}

// Direct message notification.
if ( \get_option( 'activitypub_mailer_new_dm', '0' ) ) {
if ( '1' === \get_option( 'activitypub_mailer_new_dm', '0' ) ) {
\add_action( 'activitypub_inbox_create', array( self::class, 'direct_message' ), 10, 2 );
}
}
Expand Down
25 changes: 14 additions & 11 deletions tests/includes/class-test-mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,23 +204,26 @@ function ( $args ) {
* @covers ::init
*/
public function test_init() {
\delete_option( 'activitypub_mailer_new_follower' );
\delete_option( 'activitypub_mailer_new_dm' );

Mailer::init();

$this->assertEquals( 10, has_filter( 'comment_notification_subject', array( Mailer::class, 'comment_notification_subject' ) ) );
$this->assertEquals( 10, has_filter( 'comment_notification_text', array( Mailer::class, 'comment_notification_text' ) ) );
$this->assertEquals( false, has_action( 'activitypub_notification_follow', array( Mailer::class, 'new_follower' ) ) );
$this->assertEquals( false, has_action( 'activitypub_inbox_create', array( Mailer::class, 'direct_message' ) ) );
$this->assertEquals( 10, \has_filter( 'comment_notification_subject', array( Mailer::class, 'comment_notification_subject' ) ) );
$this->assertEquals( 10, \has_filter( 'comment_notification_text', array( Mailer::class, 'comment_notification_text' ) ) );
$this->assertEquals( 10, \has_action( 'activitypub_notification_follow', array( Mailer::class, 'new_follower' ) ) );
$this->assertEquals( 10, \has_action( 'activitypub_inbox_create', array( Mailer::class, 'direct_message' ) ) );

update_option( 'activitypub_mailer_new_follower', '1' );
update_option( 'activitypub_mailer_new_dm', '1' );
\remove_action( 'activitypub_notification_follow', array( Mailer::class, 'new_follower' ) );
\remove_action( 'activitypub_inbox_create', array( Mailer::class, 'direct_message' ) );

Mailer::init();
\update_option( 'activitypub_mailer_new_follower', '0' );
\update_option( 'activitypub_mailer_new_dm', '0' );

$this->assertEquals( 10, has_action( 'activitypub_notification_follow', array( Mailer::class, 'new_follower' ) ) );
$this->assertEquals( 10, has_action( 'activitypub_inbox_create', array( Mailer::class, 'direct_message' ) ) );
Mailer::init();

delete_option( 'activitypub_mailer_new_follower' );
delete_option( 'activitypub_mailer_new_dm' );
$this->assertEquals( false, \has_action( 'activitypub_notification_follow', array( Mailer::class, 'new_follower' ) ) );
$this->assertEquals( false, \has_action( 'activitypub_inbox_create', array( Mailer::class, 'direct_message' ) ) );
}

/**
Expand Down

0 comments on commit 2ca5b5e

Please sign in to comment.