From 5c3058f5deedcc3659a4ed39ac6c361b00a19732 Mon Sep 17 00:00:00 2001 From: Geoff Taylor Date: Mon, 5 Oct 2020 14:32:25 -0400 Subject: [PATCH] some connector test cleaned up. --- package-lock.json | 14 +++--- .../connectors/test-class-connector-acf.php | 8 ++-- .../connectors/test-class-connector-edd.php | 48 +++++++++++-------- .../test-class-connector-taxonomies.php | 8 ++-- .../test-class-connector-user-switching.php | 6 +-- 5 files changed, 46 insertions(+), 38 deletions(-) diff --git a/package-lock.json b/package-lock.json index b201376ba..2849f0faf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -287,6 +287,14 @@ "globals": "^12.0.0", "prettier": "npm:wp-prettier@2.0.5", "requireindex": "^1.2.0" + }, + "dependencies": { + "prettier": { + "version": "npm:wp-prettier@2.0.5", + "resolved": "https://registry.npmjs.org/wp-prettier/-/wp-prettier-2.0.5.tgz", + "integrity": "sha512-5GCgdeevIXwR3cW4Qj5XWC5MO1iSCz8+IPn0mMw6awAt/PBiey8yyO7MhePRsaMqghJAhg6Q3QLYWSnUHWkG6A==", + "dev": true + } } }, "@wordpress/prettier-config": { @@ -3514,12 +3522,6 @@ "integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==", "dev": true }, - "prettier": { - "version": "npm:wp-prettier@2.0.5", - "resolved": "https://registry.npmjs.org/wp-prettier/-/wp-prettier-2.0.5.tgz", - "integrity": "sha512-5GCgdeevIXwR3cW4Qj5XWC5MO1iSCz8+IPn0mMw6awAt/PBiey8yyO7MhePRsaMqghJAhg6Q3QLYWSnUHWkG6A==", - "dev": true - }, "prettier-linter-helpers": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz", diff --git a/tests/tests/connectors/test-class-connector-acf.php b/tests/tests/connectors/test-class-connector-acf.php index 8259544ef..f2de880f0 100644 --- a/tests/tests/connectors/test-class-connector-acf.php +++ b/tests/tests/connectors/test-class-connector-acf.php @@ -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' ) ); @@ -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' ) ); @@ -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' ) ); } } diff --git a/tests/tests/connectors/test-class-connector-edd.php b/tests/tests/connectors/test-class-connector-edd.php index bb457995f..25b2fb89f 100644 --- a/tests/tests/connectors/test-class-connector-edd.php +++ b/tests/tests/connectors/test-class-connector-edd.php @@ -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 ); } /** @@ -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(); @@ -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( @@ -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( @@ -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( @@ -161,7 +167,7 @@ public function test_check() { $this->equalTo( null ), $this->equalTo( 'settings' ), $this->equalTo( 'updated' ) - ] + ) ); // Update option to trigger callback. @@ -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() { @@ -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' ), @@ -228,7 +234,7 @@ 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() { @@ -236,20 +242,20 @@ public function test_settings_transport_callbacks() { $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. @@ -257,13 +263,13 @@ public function test_settings_transport_callbacks() { 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. @@ -271,7 +277,7 @@ public function test_meta() { ->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' @@ -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' ) ); } } diff --git a/tests/tests/connectors/test-class-connector-taxonomies.php b/tests/tests/connectors/test-class-connector-taxonomies.php index 2a4ee5383..fa7267381 100644 --- a/tests/tests/connectors/test-class-connector-taxonomies.php +++ b/tests/tests/connectors/test-class-connector-taxonomies.php @@ -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() { @@ -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() { @@ -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' ) ); } } diff --git a/tests/tests/connectors/test-class-connector-user-switching.php b/tests/tests/connectors/test-class-connector-user-switching.php index 04f6b8944..4368e0334 100644 --- a/tests/tests/connectors/test-class-connector-user-switching.php +++ b/tests/tests/connectors/test-class-connector-user-switching.php @@ -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() { @@ -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() { @@ -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' ) ); } }