Fix php unit test "test_deleted_coupons" for wc >= 6.1.0 (https://github.com/woocommerce/woocommerce-admin/pull/8162)
* Fix bin/install-wp-tests.sh for wc >= 6.0.0 * Fix php unit test "test_deleted_coupons" for wc >= 6.1.0 * Update WC_Tests_Reports_Coupons test_populate_and_query test Fix test
This commit is contained in:
parent
161a9d6feb
commit
ae0ea6df2c
|
@ -150,6 +150,11 @@ install_db() {
|
|||
mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA
|
||||
}
|
||||
|
||||
version() {
|
||||
# convert version numbers to digits
|
||||
echo "$@" | awk -F. '{ printf("%03d%03d%03d\n", $1,$2,$3); }';
|
||||
}
|
||||
|
||||
install_deps() {
|
||||
|
||||
# Script Variables
|
||||
|
@ -170,15 +175,25 @@ install_deps() {
|
|||
php wp-cli.phar core install --url="$WP_SITE_URL" --title="Example" --admin_user=admin --admin_password=password --admin_email=info@example.com --path=$WP_CORE_DIR --skip-email
|
||||
|
||||
# Install WooCommerce (latest non-hyphenated (beta, RC) tag)
|
||||
if [[ "$WC_VERSION" == "" || "$WC_VERSION" == "latest" ]]; then
|
||||
LATEST_WC_TAG="$(git ls-remote --tags https://github.com/woocommerce/woocommerce.git | awk '{print $2}' | sed 's/^refs\/tags\///' | grep -E '^[0-9]\.[0-9]\.[0-9]$' | sort -V | tail -n 1)"
|
||||
if [[ "$WC_VERSION" == "latest" ]]; then
|
||||
INSTALL_WC_TAG="$(git ls-remote --tags https://github.com/woocommerce/woocommerce.git | awk '{print $2}' | sed 's/^refs\/tags\///' | grep -E '^[0-9]\.[0-9]\.[0-9]$' | sort -V | tail -n 1)"
|
||||
else
|
||||
LATEST_WC_TAG="$WC_VERSION"
|
||||
INSTALL_WC_TAG="$WC_VERSION"
|
||||
fi
|
||||
cd "wp-content/plugins/"
|
||||
# As zip file does not include tests, we have to get it from git repo.
|
||||
git clone --depth 1 --branch $LATEST_WC_TAG https://github.com/woocommerce/woocommerce.git
|
||||
|
||||
|
||||
# As zip file does not include tests, we have to get it from git repo.
|
||||
git clone --depth 1 --branch $INSTALL_WC_TAG https://github.com/woocommerce/woocommerce.git
|
||||
|
||||
if [ "$(version "$INSTALL_WC_TAG")" -ge "$(version "6.0.0")" ]; then
|
||||
# WooCommerce 6.0.0 introduced a breaking change to the repo structure.
|
||||
# We need to clone and use the correct folder path.
|
||||
mv woocommerce/plugins/woocommerce wp-content/plugins/
|
||||
else
|
||||
mv woocommerce wp-content/plugins/
|
||||
fi
|
||||
|
||||
cd "wp-content/plugins/"
|
||||
# Bring in WooCommerce Core dependencies
|
||||
cd "woocommerce"
|
||||
composer install --no-dev
|
||||
|
|
|
@ -343,46 +343,38 @@ class WC_Tests_Reports_Coupons extends WC_Unit_Test_Case {
|
|||
$coupon_1->set_amount( $coupon_1_amount );
|
||||
$coupon_1->save();
|
||||
|
||||
// Coupon that will be deleted.
|
||||
$coupon_2_amount = 7;
|
||||
// Coupon that will be deleted, but order item will have metadata that will preserve its ID.
|
||||
$coupon_2_amount = 1;
|
||||
$coupon_2 = WC_Helper_Coupon::create_coupon( 'coupon_2' );
|
||||
$coupon_2->set_amount( $coupon_2_amount );
|
||||
$coupon_2->save();
|
||||
|
||||
// Coupon that will be deleted, but order item will have metadata that will preserve its ID.
|
||||
$coupon_3_amount = 1;
|
||||
$coupon_3 = WC_Helper_Coupon::create_coupon( 'coupon_3' );
|
||||
$coupon_3->set_amount( $coupon_3_amount );
|
||||
$coupon_3->save();
|
||||
$coupon_3_id = $coupon_3->get_id();
|
||||
$coupon_2_id = $coupon_2->get_id();
|
||||
|
||||
// Order with coupons.
|
||||
$order = WC_Helper_Order::create_order( 1, $product );
|
||||
$order->set_status( 'completed' );
|
||||
$order->apply_coupon( $coupon_1 );
|
||||
$order->apply_coupon( $coupon_2 );
|
||||
$order->apply_coupon( $coupon_3 );
|
||||
$order->calculate_totals();
|
||||
$order->save();
|
||||
|
||||
// Add coupon_3 metadata to its order item.
|
||||
// Add coupon_2 metadata to its order item.
|
||||
$coupon_items = $order->get_items( 'coupon' );
|
||||
|
||||
// This would normally happen at checkout.
|
||||
foreach ( $coupon_items as $coupon_item ) {
|
||||
if ( 'coupon_3' !== $coupon_item->get_code() ) {
|
||||
if ( 'coupon_2' !== $coupon_item->get_code() ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$coupon_3_data = $coupon_3->get_data();
|
||||
unset( $coupon_3_data['used_by'] );
|
||||
$coupon_item->add_meta_data( 'coupon_data', $coupon_3_data );
|
||||
$coupon_2_data = $coupon_2->get_data();
|
||||
unset( $coupon_2_data['used_by'] );
|
||||
$coupon_item->add_meta_data( 'coupon_data', $coupon_2_data );
|
||||
$coupon_item->save();
|
||||
}
|
||||
|
||||
// Delete the coupons.
|
||||
$coupon_2->delete( true );
|
||||
$coupon_3->delete( true );
|
||||
|
||||
WC_Helper_Queue::run_all_pending();
|
||||
|
||||
|
@ -402,29 +394,22 @@ class WC_Tests_Reports_Coupons extends WC_Unit_Test_Case {
|
|||
'extended_info' => new ArrayObject(),
|
||||
);
|
||||
$coupon_2_response = array(
|
||||
'coupon_id' => -1, // coupon_2 was deleted, so a new ID was created.
|
||||
'coupon_id' => $coupon_2_id, // coupon_2 was deleted, but has metadata containing the ID.
|
||||
'amount' => floatval( $coupon_2_amount ),
|
||||
'orders_count' => 1,
|
||||
'extended_info' => new ArrayObject(),
|
||||
);
|
||||
$coupon_3_response = array(
|
||||
'coupon_id' => $coupon_3_id, // coupon_3 was deleted, but has metadata containing the ID.
|
||||
'amount' => floatval( $coupon_3_amount ),
|
||||
'orders_count' => 1,
|
||||
'extended_info' => new ArrayObject(),
|
||||
);
|
||||
|
||||
// Order by coupon id DESC is the default.
|
||||
$data = $data_store->get_data( $args );
|
||||
$expected_data = (object) array(
|
||||
'total' => 3,
|
||||
'total' => 2,
|
||||
'pages' => 1,
|
||||
'page_no' => 1,
|
||||
'data' => array(
|
||||
// Order is 3, 1, 2 since query is sorted by coupon ID descending.
|
||||
0 => $coupon_3_response,
|
||||
// Order query is sorted by coupon ID descending.
|
||||
0 => $coupon_2_response,
|
||||
1 => $coupon_1_response,
|
||||
2 => $coupon_2_response,
|
||||
),
|
||||
);
|
||||
$this->assertEquals( $expected_data, $data );
|
||||
|
@ -470,7 +455,7 @@ class WC_Tests_Reports_Coupons extends WC_Unit_Test_Case {
|
|||
);
|
||||
|
||||
$coupon_2_response = array(
|
||||
'coupon_id' => -1,
|
||||
'coupon_id' => $coupon_2_id, // coupon_2 was deleted, but has metadata containing the ID.
|
||||
'amount' => floatval( $coupon_2_amount ),
|
||||
'orders_count' => 1,
|
||||
'extended_info' => array(
|
||||
|
@ -483,20 +468,6 @@ class WC_Tests_Reports_Coupons extends WC_Unit_Test_Case {
|
|||
),
|
||||
);
|
||||
|
||||
$coupon_3_response = array(
|
||||
'coupon_id' => $coupon_3_id, // coupon_3 was deleted, but has metadata containing the ID.
|
||||
'amount' => floatval( $coupon_3_amount ),
|
||||
'orders_count' => 1,
|
||||
'extended_info' => array(
|
||||
'code' => '(Deleted)',
|
||||
'date_created' => '',
|
||||
'date_created_gmt' => '',
|
||||
'date_expires' => '',
|
||||
'date_expires_gmt' => '',
|
||||
'discount_type' => 'N/A',
|
||||
),
|
||||
);
|
||||
|
||||
$args = array(
|
||||
'after' => $start_time,
|
||||
'before' => $end_time,
|
||||
|
@ -504,14 +475,13 @@ class WC_Tests_Reports_Coupons extends WC_Unit_Test_Case {
|
|||
);
|
||||
$data = $data_store->get_data( $args );
|
||||
$expected_data = (object) array(
|
||||
'total' => 3,
|
||||
'total' => 2,
|
||||
'pages' => 1,
|
||||
'page_no' => 1,
|
||||
'data' => array(
|
||||
// Order is 3, 1, 2 since query is sorted by coupon ID descending.
|
||||
0 => $coupon_3_response,
|
||||
// Order query is sorted by coupon ID descending.
|
||||
0 => $coupon_2_response,
|
||||
1 => $coupon_1_response,
|
||||
2 => $coupon_2_response,
|
||||
),
|
||||
);
|
||||
$this->assertEquals( $expected_data, $data );
|
||||
|
|
Loading…
Reference in New Issue