2019-06-13 21:40:02 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Plugin Version Tests
|
|
|
|
*
|
2020-08-11 19:18:47 +00:00
|
|
|
* @package WooCommerce\Admin\Tests\Reports
|
2019-06-13 21:40:02 +00:00
|
|
|
* @since 3.6.4
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Plugin Version Tests Class
|
|
|
|
*
|
2020-08-11 19:18:47 +00:00
|
|
|
* @package WooCommerce\Admin\Tests\Reports
|
2019-06-13 21:40:02 +00:00
|
|
|
* @since 3.6.4
|
|
|
|
*/
|
|
|
|
class WC_Admin_Tests_Plugin_Version extends WP_UnitTestCase {
|
|
|
|
/**
|
|
|
|
* Ensure that all version numbers match.
|
|
|
|
*/
|
|
|
|
public function test_version_numbers() {
|
|
|
|
// Get package.json version.
|
|
|
|
$package_json = file_get_contents( 'package.json' );
|
|
|
|
$package = json_decode( $package_json );
|
|
|
|
|
|
|
|
// Get main plugin file header version.
|
|
|
|
$plugin = get_file_data( 'woocommerce-admin.php', array( 'Version' => 'Version' ) );
|
|
|
|
|
|
|
|
// Get plugin DB version.
|
|
|
|
$db_version = defined( 'WC_ADMIN_VERSION_NUMBER' ) ? constant( 'WC_ADMIN_VERSION_NUMBER' ) : false;
|
|
|
|
|
|
|
|
// Compare all versions to the package.json value.
|
|
|
|
$this->assertEquals( $package->version, $plugin['Version'], 'Plugin header version does not match package.json' );
|
|
|
|
$this->assertEquals( $package->version, $db_version, 'DB version constant does not match package.json' );
|
|
|
|
}
|
2020-07-16 16:08:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Ensure that a DB version callback is defined when there are updates.
|
|
|
|
*/
|
|
|
|
public function test_db_update_callbacks() {
|
|
|
|
$all_callbacks = \Automattic\WooCommerce\Admin\Install::get_db_update_callbacks();
|
|
|
|
|
|
|
|
foreach ( $all_callbacks as $version => $version_callbacks ) {
|
|
|
|
// Verify all callbacks have been defined.
|
|
|
|
foreach ( $version_callbacks as $version_callback ) {
|
|
|
|
$this->assertTrue( function_exists( $version_callback ), "Callback {$version_callback}() is not defined." );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify there is a version update callback for each version.
|
|
|
|
$version_string = str_replace( '.', '', $version );
|
|
|
|
$expected_callback = "wc_admin_update_{$version_string}_db_version";
|
|
|
|
|
|
|
|
$this->assertContains( $expected_callback, $version_callbacks, "Expected DB update callback {$expected_callback}() was not found." );
|
|
|
|
}
|
|
|
|
}
|
2019-06-13 21:40:02 +00:00
|
|
|
}
|