2021-03-25 05:21:03 +00:00
|
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Install tests
|
|
|
|
|
*
|
|
|
|
|
* @package WooCommerce\Admin\Tests
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
use \Automattic\WooCommerce\Admin\Install;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tests for \Automattic\WooCommerce\Admin\Install class.
|
|
|
|
|
*/
|
|
|
|
|
class WC_Admin_Tests_Install extends WP_UnitTestCase {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Integration test for database table creation.
|
|
|
|
|
*
|
|
|
|
|
* @group database
|
|
|
|
|
*/
|
2021-03-30 23:43:34 +00:00
|
|
|
|
public function test_create_tables() {
|
2021-03-25 05:21:03 +00:00
|
|
|
|
global $wpdb;
|
|
|
|
|
|
2021-03-30 23:43:34 +00:00
|
|
|
|
// Remove the Test Suite’s use of temporary tables https://wordpress.stackexchange.com/a/220308.
|
2021-03-26 13:52:54 +00:00
|
|
|
|
remove_filter( 'query', array( $this, '_create_temporary_tables' ) );
|
|
|
|
|
remove_filter( 'query', array( $this, '_drop_temporary_tables' ) );
|
|
|
|
|
|
|
|
|
|
// List of tables created by Install::create_tables.
|
2021-03-25 05:21:03 +00:00
|
|
|
|
$tables = array(
|
|
|
|
|
"{$wpdb->prefix}wc_order_stats",
|
|
|
|
|
"{$wpdb->prefix}wc_order_product_lookup",
|
|
|
|
|
"{$wpdb->prefix}wc_order_tax_lookup",
|
|
|
|
|
"{$wpdb->prefix}wc_order_coupon_lookup",
|
|
|
|
|
"{$wpdb->prefix}wc_admin_notes",
|
|
|
|
|
"{$wpdb->prefix}wc_admin_note_actions",
|
|
|
|
|
"{$wpdb->prefix}wc_customer_lookup",
|
2021-03-30 23:43:34 +00:00
|
|
|
|
"{$wpdb->prefix}wc_category_lookup",
|
2021-03-25 05:21:03 +00:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Remove any existing tables in the environment.
|
2021-03-26 13:52:54 +00:00
|
|
|
|
$query = 'DROP TABLE IF EXISTS ' . implode( ',', $tables );
|
2021-03-30 23:43:34 +00:00
|
|
|
|
$wpdb->query( $query ); // phpcs:ignore.
|
2021-03-25 05:21:03 +00:00
|
|
|
|
|
|
|
|
|
// Try to create the tables.
|
|
|
|
|
Install::create_tables();
|
|
|
|
|
$result = $wpdb->get_col( "SHOW TABLES LIKE '{$wpdb->prefix}%'" );
|
|
|
|
|
|
|
|
|
|
// Check all the tables exist.
|
|
|
|
|
foreach ( $tables as $table ) {
|
|
|
|
|
$this->assertContains( $table, $result );
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-16 19:01:04 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test missed DB version number update.
|
|
|
|
|
* See: https:// github.com/woocommerce/woocommerce-admin/issues/5058
|
|
|
|
|
*/
|
|
|
|
|
public function test_missed_version_number_update() {
|
|
|
|
|
$old_version = '1.6.0'; // This should get updated to later versions as we add more migrations.
|
|
|
|
|
|
|
|
|
|
// Simulate an upgrade from an older version.
|
|
|
|
|
update_option( Install::VERSION_OPTION, '1.6.0' );
|
|
|
|
|
Install::install();
|
|
|
|
|
WC_Helper_Queue::run_all_pending();
|
|
|
|
|
|
|
|
|
|
// Simulate a collision/failure in version updating.
|
|
|
|
|
update_option( Install::VERSION_OPTION, '1.6.0' );
|
|
|
|
|
|
|
|
|
|
// The next update check should force update the skipped version number.
|
|
|
|
|
Install::install();
|
|
|
|
|
$this->assertTrue( version_compare( $old_version, get_option( Install::VERSION_OPTION ), '<' ) );
|
|
|
|
|
|
|
|
|
|
// The following update check should bump the version to the current (no migrations left).
|
|
|
|
|
Install::install();
|
|
|
|
|
$this->assertEquals( get_option( Install::VERSION_OPTION ), WC_ADMIN_VERSION_NUMBER );
|
|
|
|
|
}
|
2021-03-25 05:21:03 +00:00
|
|
|
|
}
|