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
87 changes: 0 additions & 87 deletions classes/class-install.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +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' ) );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kidunot89 I think removing this now makes the Travis checks fail because the table for the plugin is not created on the first run https://travis-ci.com/github/xwp/stream/jobs/468947527#L511


// Install the plugin.
add_action( 'wp_stream_before_db_notices', array( $this, 'check' ) );

Copy link
Contributor Author

@kidunot89 kidunot89 Jan 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kasparsd Removing this may have broken CI. The tests are still passing locally tho. Any ideas what's going on with Travis-CI?

register_activation_hook( $this->plugin->locations['plugin'], array( $this, 'check' ) );
}

Expand Down Expand Up @@ -137,87 +131,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 <strong>%s</strong>',
_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. "<a href="https://foo.com/wp-admin/">") */
__( 'Please %1$suninstall%2$s the Stream plugin and activate it again.', 'stream' ),
'<a href="' . network_admin_url( 'plugins.php#stream' ) . '">',
'</a>'
);
} elseif ( current_user_can( 'activate_plugins' ) ) {
$uninstall_message = sprintf(
/* translators: %#$s: HTML Link tags (e.g. "<a href="https://foo.com/wp-admin/">") */
__( 'Please %1$suninstall%2$s the Stream plugin and activate it again.', 'stream' ),
'<a href="' . admin_url( 'plugins.php#stream' ) . '">',
'</a>'
);
}

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.
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
31 changes: 31 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,49 @@ 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';
}

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
Expand Down
13 changes: 0 additions & 13 deletions tests/tests/connectors/test-class-connector-edd.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down