From 07866d9890a8f90c7b3c921d6938ba02460fb69e Mon Sep 17 00:00:00 2001 From: vendidero Date: Wed, 4 Sep 2024 10:48:56 +0200 Subject: [PATCH] Install/uninstall tests. --- src/Order.php | 6 ++++- tests/unit-tests/install.php | 41 ++++++++++++++++++++++++++++++ uninstall.php | 49 ++++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 tests/unit-tests/install.php create mode 100644 uninstall.php diff --git a/src/Order.php b/src/Order.php index eafab34..ec72bc5 100644 --- a/src/Order.php +++ b/src/Order.php @@ -57,6 +57,10 @@ public function get_order() { return $this->order; } + public function get_id() { + return $this->get_order()->get_id(); + } + /** * @return WC_DateTime|null */ @@ -154,7 +158,7 @@ public function get_shipping_status() { } public function supports_third_party_email_transmission() { - $supports_email_transmission = function_exists( 'wc_gzd_order_supports_parcel_delivery_reminder' ) ? wc_gzd_order_supports_parcel_delivery_reminder( $this->get_order() ) : 'yes' === $this->get_order()->get_meta( '_parcel_delivery_opted_in' ); + $supports_email_transmission = 'yes' === $this->get_order()->get_meta( '_parcel_delivery_opted_in' ); /** * Filter to adjust whether the email address may be transmitted to third-parties, e.g. diff --git a/tests/unit-tests/install.php b/tests/unit-tests/install.php new file mode 100644 index 0000000..8638442 --- /dev/null +++ b/tests/unit-tests/install.php @@ -0,0 +1,41 @@ +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 ); + } +} \ No newline at end of file diff --git a/uninstall.php b/uninstall.php new file mode 100644 index 0000000..666851c --- /dev/null +++ b/uninstall.php @@ -0,0 +1,49 @@ +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(); +}