From d980f23bf3f4d960ae4141ae6e337c436062b26c Mon Sep 17 00:00:00 2001 From: Geoff Taylor Date: Fri, 27 Nov 2020 11:57:50 -0500 Subject: [PATCH 1/3] "Install::verify_db()" removed. --- classes/class-install.php | 84 ------------------- .../connectors/test-class-connector-edd.php | 1 - 2 files changed, 85 deletions(-) diff --git a/classes/class-install.php b/classes/class-install.php index 778485ce5..76b556e4a 100644 --- a/classes/class-install.php +++ b/classes/class-install.php @@ -71,9 +71,6 @@ public function __construct( $plugin ) { $this->db_version = $this->get_db_version(); $this->stream_url = self_admin_url( $this->plugin->admin->admin_parent_page . '&page=' . $this->plugin->admin->settings_page_slug ); - // Check DB and display an admin notice if there are tables missing. - add_action( 'init', array( $this, 'verify_db' ) ); - // Install the plugin. add_action( 'wp_stream_before_db_notices', array( $this, 'check' ) ); @@ -137,87 +134,6 @@ public function check() { $this->update_db_option(); } - /** - * Verify that the required DB tables exists - * - * @return void - */ - public function verify_db() { - /** - * Filter will halt install() if set to true - * - * @param bool - * - * @return bool - */ - if ( apply_filters( 'wp_stream_no_tables', false ) ) { - return; - } - - if ( ! function_exists( 'is_plugin_active_for_network' ) ) { - require_once ABSPATH . '/wp-admin/includes/plugin.php'; - } - - /** - * Fires before admin notices are triggered for missing database tables. - */ - do_action( 'wp_stream_before_db_notices' ); - - global $wpdb; - - $database_message = ''; - $uninstall_message = ''; - - // Check if all needed DB is present. - $missing_tables = array(); - - foreach ( $this->plugin->db->get_table_names() as $table_name ) { - $table_search = $wpdb->get_var( - $wpdb->prepare( 'SHOW TABLES LIKE %s', $table_name ) - ); - if ( $table_search !== $table_name ) { - $missing_tables[] = $table_name; - } - } - - if ( $missing_tables ) { - $database_message .= sprintf( - '%s %s', - _n( - 'The following table is not present in the WordPress database:', - 'The following tables are not present in the WordPress database:', - count( $missing_tables ), - 'stream' - ), - esc_html( implode( ', ', $missing_tables ) ) - ); - } - - if ( $this->plugin->is_network_activated() && current_user_can( 'manage_network_plugins' ) ) { - $uninstall_message = sprintf( - /* translators: %#$s: HTML Link tags (e.g. "") */ - __( 'Please %1$suninstall%2$s the Stream plugin and activate it again.', 'stream' ), - '', - '' - ); - } elseif ( current_user_can( 'activate_plugins' ) ) { - $uninstall_message = sprintf( - /* translators: %#$s: HTML Link tags (e.g. "") */ - __( 'Please %1$suninstall%2$s the Stream plugin and activate it again.', 'stream' ), - '', - '' - ); - } - - if ( ! empty( $database_message ) ) { - $this->plugin->admin->notice( $database_message ); - - if ( ! empty( $uninstall_message ) ) { - $this->plugin->admin->notice( $uninstall_message ); - } - } - } - /** * Register a routine to be called when stream or a stream connector has been updated * It works by comparing the current version with the version previously stored in the database. diff --git a/tests/tests/connectors/test-class-connector-edd.php b/tests/tests/connectors/test-class-connector-edd.php index ac90deea7..5cacbceb5 100644 --- a/tests/tests/connectors/test-class-connector-edd.php +++ b/tests/tests/connectors/test-class-connector-edd.php @@ -178,7 +178,6 @@ public function test_check() { edd_update_option( 'thousands_separator' ); // Check callback test action. - $this->assertGreaterThan( 0, did_action( $this->action_prefix . 'callback_add_option' ) ); $this->assertGreaterThan( 0, did_action( $this->action_prefix . 'callback_update_option' ) ); } From 7a76b572f5b22f31d45fcaf9a3fcb33fc9ae2fd1 Mon Sep 17 00:00:00 2001 From: Geoff Taylor Date: Tue, 5 Jan 2021 17:32:55 -0500 Subject: [PATCH 2/3] "wp_stream_before_db_notices" action callback removed. --- classes/class-install.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/classes/class-install.php b/classes/class-install.php index 76b556e4a..5d5761c30 100644 --- a/classes/class-install.php +++ b/classes/class-install.php @@ -71,9 +71,6 @@ public function __construct( $plugin ) { $this->db_version = $this->get_db_version(); $this->stream_url = self_admin_url( $this->plugin->admin->admin_parent_page . '&page=' . $this->plugin->admin->settings_page_slug ); - // Install the plugin. - add_action( 'wp_stream_before_db_notices', array( $this, 'check' ) ); - register_activation_hook( $this->plugin->locations['plugin'], array( $this, 'check' ) ); } From c98fad971bb68fce1213f6d3f96e872359199ad8 Mon Sep 17 00:00:00 2001 From: Geoff Taylor Date: Fri, 15 Jan 2021 20:58:38 -0500 Subject: [PATCH 3/3] test bootstrap file updated --- package.json | 4 +-- tests/bootstrap.php | 31 +++++++++++++++++++ .../connectors/test-class-connector-edd.php | 14 +-------- 3 files changed, 34 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 789e0d2bf..4557f2d8d 100644 --- a/package.json +++ b/package.json @@ -46,8 +46,8 @@ "build-containers": "docker-compose --file docker-compose.build.yml build", "push-containers": "docker-compose --file docker-compose.build.yml push", "stop-all": "docker stop $(docker ps -a -q)", - "cli": "docker-compose run --rm --user $(id -u) wordpress xwp_wait db_phpunit:3306 -t 60 --", - "vcli": "vagrant ssh -- docker-compose -f /vagrant/docker-compose.yml run --rm --user $(id -u) wordpress xwp_wait db_phpunit:3306 -t 60 --", + "cli": "docker-compose run --rm --user $(id -u) wordpress xwp_wait db_phpunit:3306 -s -t 300 --", + "vcli": "vagrant ssh -- docker-compose -f /vagrant/docker-compose.yml run --rm --user $(id -u) wordpress xwp_wait db_phpunit:3306 -s -t 300 --", "phpunit": "npm run cli -- composer test --working-dir=wp-content/plugins/stream-src", "phpunit-multisite": "npm run cli -- composer test-multisite --working-dir=wp-content/plugins/stream-src", "vphpunit": "npm run vcli -- composer test --working-dir=wp-content/plugins/stream-src", diff --git a/tests/bootstrap.php b/tests/bootstrap.php index fc523560c..3c9110625 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -44,8 +44,13 @@ function xwp_filter_active_plugins_for_phpunit( $active_plugins ) { function() { // Manually load the plugin. require dirname( __DIR__ ) . '/stream.php'; + + // Install database. + $plugin = wp_stream_get_instance(); + $plugin->install->check(); } ); + function xwp_manually_load_mercator() { define( 'MERCATOR_SKIP_CHECKS', true ); require WPMU_PLUGIN_DIR . '/mercator/mercator.php'; @@ -53,9 +58,35 @@ function xwp_manually_load_mercator() { tests_add_filter( 'muplugins_loaded', 'xwp_manually_load_mercator' ); +function xwp_install_edd() { + // Install Easy Digital Downloads + edd_install(); + + global $current_user, $edd_options; + + $edd_options = get_option( 'edd_settings' ); + + $current_user = new WP_User(1); + $current_user->set_role('administrator'); + wp_update_user( array( 'ID' => 1, 'first_name' => 'Admin', 'last_name' => 'User' ) ); + add_filter( 'edd_log_email_errors', '__return_false' ); + + add_filter( + 'pre_http_request', + function( $status = false, $args = array(), $url = '') { + return new WP_Error( 'no_reqs_in_unit_tests', __( 'HTTP Requests disabled for unit tests', 'easy-digital-downloads' ) ); + } + ); +} + // @see https://core.trac.wordpress.org/browser/trunk/tests/phpunit/includes/bootstrap.php require $_tests_dir . '/includes/bootstrap.php'; +define( 'EDD_USE_PHP_SESSIONS', false ); +define( 'WP_USE_THEMES', false ); +activate_plugin( 'easy-digital-downloads/easy-digital-downloads.php' ); +xwp_install_edd(); + require __DIR__ . '/testcase.php'; // Base class for future tests diff --git a/tests/tests/connectors/test-class-connector-edd.php b/tests/tests/connectors/test-class-connector-edd.php index 5cacbceb5..a9922e82d 100644 --- a/tests/tests/connectors/test-class-connector-edd.php +++ b/tests/tests/connectors/test-class-connector-edd.php @@ -10,19 +10,6 @@ namespace WP_Stream; 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 ); - } - /** * Runs before each test */ @@ -178,6 +165,7 @@ public function test_check() { edd_update_option( 'thousands_separator' ); // Check callback test action. + $this->assertGreaterThan( 0, did_action( $this->action_prefix . 'callback_add_option' ) ); $this->assertGreaterThan( 0, did_action( $this->action_prefix . 'callback_update_option' ) ); }