diff --git a/includes/class-wc-install.php b/includes/class-wc-install.php index 8d5d047446e..56f664b8d17 100644 --- a/includes/class-wc-install.php +++ b/includes/class-wc-install.php @@ -2,8 +2,6 @@ /** * Installation related functions and actions. * - * @author WooThemes - * @category Admin * @package WooCommerce/Classes * @version 3.0.0 */ @@ -141,7 +139,7 @@ class WC_Install { * This check is done on all requests and runs if the versions do not match. */ public static function check_version() { - if ( ! defined( 'IFRAME_REQUEST' ) && get_option( 'woocommerce_version' ) !== WC()->version ) { + if ( ! defined( 'IFRAME_REQUEST' ) && version_compare( get_option( 'woocommerce_version' ), WC()->version, '<' ) ) { self::install(); do_action( 'woocommerce_updated' ); } diff --git a/tests/unit-tests/util/install.php b/tests/unit-tests/util/install.php index 0c43017b89b..7637adb00fa 100644 --- a/tests/unit-tests/util/install.php +++ b/tests/unit-tests/util/install.php @@ -11,16 +11,22 @@ class WC_Tests_Install extends WC_Unit_Test_Case { */ public function test_check_version() { update_option( 'woocommerce_version', ( (float) WC()->version - 1 ) ); - update_option( 'woocommerce_db_version', WC()->version ); WC_Install::check_version(); $this->assertTrue( did_action( 'woocommerce_updated' ) === 1 ); update_option( 'woocommerce_version', WC()->version ); - update_option( 'woocommerce_db_version', WC()->version ); WC_Install::check_version(); $this->assertTrue( did_action( 'woocommerce_updated' ) === 1 ); + + update_option( 'woocommerce_version', (float) WC()->version + 1 ); + WC_Install::check_version(); + + $this->assertTrue( + did_action( 'woocommerce_updated' ) === 1, + 'WC_Install::check_version() should not call install routine when the WC version stored in the database is bigger than the version in the code as downgrades are not supported.' + ); } /** @@ -33,12 +39,12 @@ class WC_Tests_Install extends WC_Unit_Test_Case { define( 'WC_REMOVE_ALL_DATA', true ); } - include( dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) . '/uninstall.php' ); + include dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) . '/uninstall.php'; delete_transient( 'wc_installing' ); WC_Install::install(); - $this->assertEquals( WC()->version, get_option( 'woocommerce_version' ), print_r( array( 'Stored version' => get_option( 'woocommerce_version' ), 'WC Version' => WC()->version ), true ) ); + $this->assertEquals( WC()->version, get_option( 'woocommerce_version' ) ); } /** @@ -87,7 +93,7 @@ class WC_Tests_Install extends WC_Unit_Test_Case { define( 'WP_UNINSTALL_PLUGIN', true ); define( 'WC_REMOVE_ALL_DATA', true ); } - include( dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) . '/uninstall.php' ); + include dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) . '/uninstall.php'; WC_Install::create_roles();