Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions package-lock.json

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

8 changes: 4 additions & 4 deletions tests/tests/connectors/test-class-connector-acf.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public function test_callback_save_post() {
$this->update_acf_field();

// Check callback test action.
$this->assertGreaterThan( 0, did_action( 'wp_stream_test_callback_save_post' ) );
$this->assertGreaterThan( 0, did_action( $this->action_prefix . 'callback_save_post' ) );

// 'acf/update_field_group' is called at the end of "acf_update_field()".
$this->assertSame( 1, did_action( 'acf/update_field_group' ) );
Expand Down Expand Up @@ -185,7 +185,7 @@ public function test_callback_post_updated() {
$this->update_acf_field_group( $field_group );

// Check callback test action.
$this->assertGreaterThan( 0, did_action( 'wp_stream_test_callback_post_updated' ) );
$this->assertGreaterThan( 0, did_action( $this->action_prefix . 'callback_post_updated' ) );

// 'acf/update_field_group' is called at the end of "acf_update_field()".
$this->assertSame( 2, did_action( 'acf/update_field_group' ) );
Expand Down Expand Up @@ -289,7 +289,7 @@ public function test_check_meta_values() {
update_field( 'test_field', 'Yes sir!', "user_{$user_id}" );

// Check callback test actions.
$this->assertGreaterThan( 0, did_action( 'wp_stream_test_callback_added_post_meta' ) );
$this->assertGreaterThan( 0, did_action( 'wp_stream_test_callback_updated_post_meta' ) );
$this->assertGreaterThan( 0, did_action( $this->action_prefix . 'callback_added_post_meta' ) );
$this->assertGreaterThan( 0, did_action( $this->action_prefix . 'callback_updated_post_meta' ) );
}
}
48 changes: 27 additions & 21 deletions tests/tests/connectors/test-class-connector-edd.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ class Test_WP_Stream_Connector_EDD extends WP_StreamTestCase {
* Runs before all tests
*/
public static function wpSetUpBeforeClass() {
global $wpdb;

$suppress = $wpdb->suppress_errors();

edd_install();

$wpdb->suppress_errors( $suppress );
}

/**
Expand All @@ -28,7 +34,7 @@ public function setUp() {

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

$this->mock->register();
Expand Down Expand Up @@ -117,7 +123,7 @@ public function test_check() {
$this->mock->expects( $this->exactly( 3 ) )
->method( 'log' )
->withConsecutive(
[
array(
$this->equalTo( __( '"%s" setting updated', 'stream' ) ),
$this->equalTo(
array(
Expand All @@ -131,8 +137,8 @@ public function test_check() {
$this->equalTo( null ),
$this->equalTo( 'settings' ),
$this->equalTo( 'updated' )
],
[
),
array(
$this->equalTo( __( '"%s" setting updated', 'stream' ) ),
$this->equalTo(
array(
Expand All @@ -146,8 +152,8 @@ public function test_check() {
$this->equalTo( null ),
$this->equalTo( 'settings' ),
$this->equalTo( 'updated' )
],
[
),
array(
$this->equalTo( __( '"%s" setting updated', 'stream' ) ),
$this->equalTo(
array(
Expand All @@ -161,7 +167,7 @@ public function test_check() {
$this->equalTo( null ),
$this->equalTo( 'settings' ),
$this->equalTo( 'updated' )
]
)
);

// Update option to trigger callback.
Expand All @@ -170,8 +176,8 @@ public function test_check() {
edd_update_option( 'thousands_separator' );

// Check callback test action.
$this->assertGreaterThan( 0, did_action( 'wp_stream_test_callback_add_option' ) );
$this->assertGreaterThan( 0, did_action( 'wp_stream_test_callback_update_option' ) );
$this->assertGreaterThan( 0, did_action( $this->action_prefix . 'callback_add_option' ) );
$this->assertGreaterThan( 0, did_action( $this->action_prefix . 'callback_update_option' ) );
}

public function test_log_override() {
Expand Down Expand Up @@ -214,10 +220,10 @@ public function test_callback_edd_pre_update_discount_status() {
)
),
$this->equalTo(
[
array(
'post_id' => $post_id,
'status' => 'inactive',
]
)
),
$this->equalTo( $post_id ),
$this->equalTo( 'discounts' ),
Expand All @@ -228,50 +234,50 @@ public function test_callback_edd_pre_update_discount_status() {
$discount->update_status( 'inactive' );

// Check callback test action.
$this->assertGreaterThan( 0, did_action( 'wp_stream_test_callback_edd_pre_update_discount_status' ) );
$this->assertGreaterThan( 0, did_action( $this->action_prefix . 'callback_edd_pre_update_discount_status' ) );
}

public function test_settings_transport_callbacks() {
// Expected log calls.
$this->mock->expects( $this->exactly( 2 ) )
->method( 'log' )
->withConsecutive(
[
array(
$this->equalTo( __( 'Imported Settings', 'stream' ) ),
$this->equalTo( array() ),
$this->equalTo( null ),
$this->equalTo( 'settings' ),
$this->equalTo( 'imported' ),
],
[
),
array(
$this->equalTo( __( 'Exported Settings', 'stream' ) ),
$this->equalTo( array() ),
$this->equalTo( null ),
$this->equalTo( 'settings' ),
$this->equalTo( 'exported' ),
]
)
);

// Manually trigger callbacks.
do_action( 'edd_import_settings' );
do_action( 'edd_export_settings' );

// Check callback test action.
$this->assertGreaterThan( 0, did_action( 'wp_stream_test_callback_edd_import_settings' ) );
$this->assertGreaterThan( 0, did_action( 'wp_stream_test_callback_edd_export_settings' ) );
$this->assertGreaterThan( 0, did_action( $this->action_prefix . 'callback_edd_import_settings' ) );
$this->assertGreaterThan( 0, did_action( $this->action_prefix . 'callback_edd_export_settings' ) );
}

public function test_meta() {
// Create and authenticate user.
$user_id = self::factory()->user->create( [ 'role' => 'administrator' ] );
$user_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
\wp_set_current_user( $user_id );

// Expected log calls.
$this->mock->expects( $this->once() )
->method( 'log' )
->with(
$this->equalTo( __( 'User API Key created', 'stream' ) ),
$this->equalTo( [ 'meta_value' => 1 ] ),
$this->equalTo( array( 'meta_value' => 1 ) ),
$this->equalTo( $user_id ),
$this->equalTo( 'api_keys' ),
'created'
Expand All @@ -282,6 +288,6 @@ public function test_meta() {
\edd_update_user_api_key( $user_id );

// Check callback test action.
$this->assertGreaterThan( 0, did_action( 'wp_stream_test_callback_add_user_meta' ) );
$this->assertGreaterThan( 0, did_action( $this->action_prefix . 'callback_add_user_meta' ) );
}
}
8 changes: 4 additions & 4 deletions tests/tests/connectors/test-class-connector-taxonomies.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function( $subject ) {
wp_insert_term( 'test', 'category' );

// Check callback test action.
$this->assertGreaterThan( 0, did_action( 'wp_stream_test_callback_created_term' ) );
$this->assertGreaterThan( 0, did_action( $this->action_prefix . 'callback_created_term' ) );
}

public function test_callback_delete_term() {
Expand Down Expand Up @@ -93,7 +93,7 @@ public function test_callback_delete_term() {
wp_delete_term( $term_data['term_id'], 'category' );

// Check callback test action.
$this->assertGreaterThan( 0, did_action( 'wp_stream_test_callback_delete_term' ) );
$this->assertGreaterThan( 0, did_action( $this->action_prefix . 'callback_delete_term' ) );
}

public function test_callback_edited_term() {
Expand Down Expand Up @@ -137,7 +137,7 @@ public function test_callback_edited_term() {
);

// Check callback test action.
$this->assertGreaterThan( 0, did_action( 'wp_stream_test_callback_edit_term' ) );
$this->assertGreaterThan( 0, did_action( 'wp_stream_test_callback_edited_term' ) );
$this->assertGreaterThan( 0, did_action( $this->action_prefix . 'callback_edit_term' ) );
$this->assertGreaterThan( 0, did_action( $this->action_prefix . 'callback_edited_term' ) );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function test_callback_switch_to_user() {
\switch_to_user( $user_id );

// Check callback test action.
$this->assertGreaterThan( 0, did_action( 'wp_stream_test_callback_switch_to_user' ) );
$this->assertGreaterThan( 0, did_action( $this->action_prefix . 'callback_switch_to_user' ) );
}

public function test_callback_switch_back_user() {
Expand Down Expand Up @@ -131,7 +131,7 @@ public function test_callback_switch_back_user() {
\switch_to_user( $old_user_id, false, false );

// Check callback test action.
$this->assertGreaterThan( 0, did_action( 'wp_stream_test_callback_switch_back_user' ) );
$this->assertGreaterThan( 0, did_action( $this->action_prefix . 'callback_switch_back_user' ) );
}

public function test_callback_switch_off_user() {
Expand Down Expand Up @@ -160,6 +160,6 @@ public function test_callback_switch_off_user() {
\switch_off_user();

// Check callback test action.
$this->assertGreaterThan( 0, did_action( 'wp_stream_test_callback_switch_off_user' ) );
$this->assertGreaterThan( 0, did_action( $this->action_prefix . 'callback_switch_off_user' ) );
}
}