Skip to content

Commit

Permalink
buddypress connector test updated.
Browse files Browse the repository at this point in the history
  • Loading branch information
kidunot89 committed Dec 15, 2020
1 parent a3181ea commit ec8964e
Show file tree
Hide file tree
Showing 2 changed files with 150 additions and 50 deletions.
22 changes: 11 additions & 11 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

178 changes: 139 additions & 39 deletions tests/tests/connectors/test-class-connector-buddypress.php
Original file line number Diff line number Diff line change
@@ -1,34 +1,58 @@
<?php
/**
* WP Integration Test w/ BuddyPress
*
* Tests for BuddyPress connector class callbacks.
*
* @package WP_Stream
*/
namespace WP_Stream;

class Test_WP_Stream_Connector_BuddyPress extends WP_StreamTestCase {

/**
* Runs before all tests
*/
public static function wpSetUpBeforeClass() {
/**
* Ensure all BuddyPress components are loaded.
*/
delete_option( 'bp-active-components' );
delete_option( 'bp-deactivated-components' );
buddypress();
}

/**
* Run before each test
*/
public function setUp() {
parent::setUp();

// Make partial of Connector_ACF class, with mocked "log" function.
// Make partial of Connector_BuddyPress class, with mocked "log" function.
$this->mock = $this->getMockBuilder( Connector_BuddyPress::class )
->setMethods( [ 'log' ] )
->setMethods( array( 'log' ) )
->getMock();

$this->mock->register();
}

/**
* Run after each test
*/
public function tearDown() {
parent::tearDown();
}

public function test_bbpress_installed_and_activated() {
$this->assertTrue( is_callable( 'buddypress' ) );
buddypress();
}

public function test_option_callbacks() {
// Expected log actions.
$this->mock->expects( $this->atLeastOnce() )
->method( 'log' )
->withConsecutive(
[
array(
/* translators: %s: setting name (e.g. "Group Creation") */
$this->equalTo( _( '"%s" setting updated', 'stream' ) ),
$this->equalTo(
Expand All @@ -43,8 +67,8 @@ public function test_option_callbacks() {
$this->equalTo( null ),
$this->equalTo( 'settings' ),
$this->equalTo( 'updated' )
],
[
),
array(
/* translators: %s: setting name (e.g. "Group Creation") */
$this->equalTo( _( '"%s" setting updated', 'stream' ) ),
$this->equalTo(
Expand All @@ -59,8 +83,8 @@ public function test_option_callbacks() {
$this->equalTo( null ),
$this->equalTo( 'settings' ),
$this->equalTo( 'updated' )
],
[
),
array(
/* translators: %s: setting name (e.g. "Group Creation") */
$this->equalTo( _( '"%s" setting updated', 'stream' ) ),
$this->equalTo(
Expand All @@ -75,58 +99,134 @@ public function test_option_callbacks() {
$this->equalTo( null ),
$this->equalTo( 'settings' ),
$this->equalTo( 'updated' )
],
[
sprintf(
// translators: Placeholder refers to component title (e.g. "Members")
__( '"%1$s" component %2$s', 'stream' ),
'Extended Profiles',
'activated'
),
array(
$this->equalTo(
sprintf(
// translators: Placeholder refers to component title (e.g. "Members")
__( '"%1$s" component %2$s', 'stream' ),
'Extended Profiles',
'activated'
)
),
array(
'option' => 'xprofile',
'option_key' => 'bp-active-components',
'old_value' => null,
'value' => array(
'title' => __( 'Extended Profiles', 'buddypress' ),
'description' => __( 'Customize your community with fully editable profile fields that allow your users to describe themselves.', 'buddypress' )
),
$this->equalTo(
array(
'option' => 'xprofile',
'option_key' => 'bp-active-components',
'old_value' => null,
'value' => array(
'title' => __( 'Extended Profiles', 'buddypress' ),
'description' => __( 'Customize your community with fully editable profile fields that allow your users to describe themselves.', 'buddypress' )
),
)
),
null,
'components',
'activated'
]

$this->equalTo( null ),
$this->equalTo( 'components' ),
$this->equalTo( 'activated' ),
)
);

// Do stuff.
// Modify BuddyPress-related options to trigger callbacks.
add_option( 'bp_restrict_group_creation', false );
update_option( 'bp_restrict_group_creation', true );
delete_option( 'bp_restrict_group_creation' );

bp_update_option( 'bp-active-components', bp_core_get_components( 'all' ) );

// Check that all callback test actions were executed.
$this->assertFalse( 0 === did_action( 'wp_stream_test_callback_add_option' ) );
$this->assertFalse( 0 === did_action( 'wp_stream_test_callback_update_option' ) );
$this->assertFalse( 0 === did_action( 'wp_stream_test_callback_delete_option' ) );
// Check callback test actions.
$this->assertFalse( 0 === did_action( $this->action_prefix . 'callback_add_option' ) );
$this->assertFalse( 0 === did_action( $this->action_prefix . 'callback_update_option' ) );
$this->assertFalse( 0 === did_action( $this->action_prefix . 'callback_delete_option' ) );
}

public function test_activity_callbacks() {
// Expected log actions.
$this->mock->expects( $this->atLeastOnce() )
->method( 'log' );

// Do stuff.
// Create activity for later use.
$activity_id = \bp_activity_add(
array(
'component' => 'testComponent',
'content' => 'Testing testing 123'
)
);

$activity = new \BP_Activity_Activity( $activity_id );

// Expected log actions.
$this->mock->expects( $this->atLeastOnce() )
->method( 'log' )
->withConsecutive(
array(
$this->equalTo(
sprintf(
/* translators: %s an activity title (e.g. "Update") */
__( 'Marked activity "%s" as spam', 'stream' ),
wp_strip_all_tags( $activity->action )
)
),
$this->equalTo(
array(
'id' => $activity->id,
'item_id' => $activity->item_id,
'type' => $activity->type,
'author' => $activity->user_id,
)
),
$this->equalTo( $activity->id ),
$this->equalTo( $activity->component ),
$this->equalTo( 'spammed' ),
),
array(
$this->equalTo(
sprintf(
/* translators: %s: an activity title (e.g. "Update") */
__( 'Unmarked activity "%s" as spam', 'stream' ),
wp_strip_all_tags( $activity->action )
)
),
$this->equalTo(
array(
'id' => $activity->id,
'item_id' => $activity->item_id,
'type' => $activity->type,
'author' => $activity->user_id,
)
),
$this->equalTo( $activity->id ),
$this->equalTo( $activity->component ),
$this->equalTo( 'unspammed' ),
),
array(
$this->equalTo(
sprintf(
/* translators: %s: an activity title (e.g. "Update") */
__( '"%s" activity deleted', 'stream' ),
wp_strip_all_tags( $activity->action )
)
),
$this->equalTo(
array(
'id' => $activity->id,
'item_id' => $activity->item_id,
'type' => $activity->type,
'author' => $activity->user_id,
)
),
$this->equalTo( $activity->id ),
$this->equalTo( $activity->component ),
$this->equalTo( 'deleted' ),
)
);

// Update activity to trigger callbacks.
\bp_activity_mark_as_spam( $activity_id );
\bp_activity_mark_as_ham( $activity_id );
\bp_activity_delete_by_activity_id( $activity_id );

// Check that all callback test actions were executed.
$this->assertFalse( 0 === did_action( 'wp_stream_test_callback_' ) );
// Check callback test actions.
$this->assertFalse( 0 === did_action( $this->action_prefix . 'callback_bp_activity_mark_as_spam' ) );
$this->assertFalse( 0 === did_action( $this->action_prefix . 'callback_bp_activity_mark_as_ham' ) );
$this->assertFalse( 0 === did_action( $this->action_prefix . 'callback_bp_before_activity_delete' ) );
$this->assertFalse( 0 === did_action( $this->action_prefix . 'callback_bp_activity_deleted_activities' ) );
}

public function test_group_action_callbacks() {
Expand Down

0 comments on commit ec8964e

Please sign in to comment.