-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3897dd0
commit 07866d9
Showing
3 changed files
with
95 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
use Vendidero\Germanized\Shipments\Tests\Helpers\ShipmentHelper; | ||
use Vendidero\Germanized\Shipments\Tests\Helpers\PackagingHelper; | ||
|
||
/** | ||
* Class WC_Tests_Install. | ||
* @package WooCommerce\Tests\Util | ||
*/ | ||
class Install extends \Vendidero\Germanized\Shipments\Tests\Framework\UnitTestCase { | ||
|
||
public function update() { | ||
update_option( 'woocommerce_gzd_shipments_version', ( (float) \Vendidero\Germanized\Shipments\Package::get_version() - 1 ) ); | ||
update_option( 'woocommerce_gzd_shipments_db_version', \Vendidero\Germanized\Shipments\Package::get_version() ); | ||
\Vendidero\Germanized\Shipments\Package::check_version(); | ||
|
||
$this->assertTrue( did_action( 'woocommerce_gzd_shipments_updated' ) === 1 ); | ||
} | ||
|
||
public function test_install() { | ||
// clean existing install first | ||
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { | ||
define( 'WP_UNINSTALL_PLUGIN', true ); | ||
define( 'WC_GZD_SHIPMENTS_REMOVE_ALL_DATA', true ); | ||
} | ||
|
||
include( dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) . '/uninstall.php' ); | ||
|
||
\Vendidero\Germanized\Shipments\Install::install(); | ||
|
||
$this->assertTrue( get_option( 'woocommerce_gzd_shipments_version' ) === \Vendidero\Germanized\Shipments\Package::get_version() ); | ||
$this->assertEquals( 'yes', get_option( 'woocommerce_gzd_shipments_enable_auto_packing' ) ); | ||
|
||
// Check if Tables are installed | ||
global $wpdb; | ||
|
||
// Shipments | ||
$table_name = $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}woocommerce_gzd_shipments'" ); | ||
$this->assertEquals( "{$wpdb->prefix}woocommerce_gzd_shipments", $table_name ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { | ||
exit; | ||
} | ||
|
||
global $wpdb, $wp_version; | ||
|
||
if ( defined( 'WC_GZD_SHIPMENTS_REMOVE_ALL_DATA' ) && true === WC_GZD_SHIPMENTS_REMOVE_ALL_DATA ) { | ||
// Delete options. | ||
$wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE 'woocommerce_gzd_shipments\_%';" ); | ||
|
||
$meta_keys = array( | ||
'_shipping_length', | ||
'_shipping_width', | ||
'_shipping_height', | ||
'_hs_code', | ||
'_manufacture_country', | ||
'_customs_description', | ||
'_is_non_returnable', | ||
'_date_shipped', | ||
'_return_request_key', | ||
'_pickup_location_customer_number', | ||
'_pickup_location_code' | ||
); | ||
|
||
// Delete gzd meta data | ||
$wpdb->query( "DELETE meta FROM {$wpdb->postmeta} meta WHERE meta.meta_key IN ('" . join( "','", $meta_keys ) . "');" ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared | ||
|
||
// Remove Tables | ||
$custom_tables = array( | ||
"{$wpdb->prefix}woocommerce_gzd_shipping_providermeta", | ||
"{$wpdb->prefix}woocommerce_gzd_shipping_provider", | ||
"{$wpdb->prefix}woocommerce_gzd_packagingmeta", | ||
"{$wpdb->prefix}woocommerce_gzd_packaging", | ||
"{$wpdb->prefix}woocommerce_gzd_shipment_labelmeta", | ||
"{$wpdb->prefix}woocommerce_gzd_shipment_labels", | ||
"{$wpdb->prefix}woocommerce_gzd_shipmentmeta", | ||
"{$wpdb->prefix}woocommerce_gzd_shipments", | ||
"{$wpdb->prefix}woocommerce_gzd_shipment_itemmeta", | ||
"{$wpdb->prefix}woocommerce_gzd_shipment_items", | ||
); | ||
|
||
foreach ( $custom_tables as $table ) { | ||
$result = $wpdb->query( 'DROP TABLE IF EXISTS ' . $table ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared | ||
} | ||
|
||
// Clear any cached data that has been removed | ||
wp_cache_flush(); | ||
} |