mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-31 06:52:50 +08:00
Add test for renewal handler
This commit is contained in:
parent
9bc9c03053
commit
17cff6bd09
1 changed files with 42 additions and 0 deletions
42
tests/e2e/PHPUnit/PayPalSubscriptionsRenewalTest.php
Normal file
42
tests/e2e/PHPUnit/PayPalSubscriptionsRenewalTest.php
Normal file
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Tests\E2e;
|
||||
|
||||
use WC_Subscriptions_Product;
|
||||
use WooCommerce\PayPalCommerce\PayPalSubscriptions\RenewalHandler;
|
||||
|
||||
class PayPalSubscriptionsRenewalTest extends TestCase
|
||||
{
|
||||
public function test_process()
|
||||
{
|
||||
$c = $this->getContainer();
|
||||
$handler = new RenewalHandler($c->get('woocommerce.logger.woocommerce'));
|
||||
|
||||
$order = wc_create_order();
|
||||
$order->set_customer_id( 1 );
|
||||
$order->save();
|
||||
|
||||
$subscription = wcs_create_subscription(
|
||||
array(
|
||||
'order_id' => $order->get_id(),
|
||||
'status' => 'active',
|
||||
'billing_period' => WC_Subscriptions_Product::get_period( $_ENV['PAYPAL_SUBSCRIPTIONS_PRODUCT_ID'] ),
|
||||
'billing_interval' => WC_Subscriptions_Product::get_interval( $_ENV['PAYPAL_SUBSCRIPTIONS_PRODUCT_ID'] ),
|
||||
'customer_id' => $order->get_customer_id(),
|
||||
)
|
||||
);
|
||||
|
||||
$parent = $subscription->get_related_orders( 'ids', array( 'parent' ) );
|
||||
$this->assertEquals(count($parent), 1);
|
||||
$renewal = $subscription->get_related_orders( 'ids', array( 'renewal' ) );
|
||||
$this->assertEquals(count($renewal), 0);
|
||||
|
||||
$handler->process([$subscription], 'TRANSACTION-ID');
|
||||
$renewal = $subscription->get_related_orders( 'ids', array( 'renewal' ) );
|
||||
$this->assertEquals(count($renewal), 0);
|
||||
|
||||
$handler->process([$subscription], 'TRANSACTION-ID');
|
||||
$renewal = $subscription->get_related_orders( 'ids', array( 'renewal' ) );
|
||||
$this->assertEquals(count($renewal), 1);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue