Skip to content

Commit

Permalink
Updated test
Browse files Browse the repository at this point in the history
  • Loading branch information
Aashish committed Aug 3, 2023
1 parent f523da2 commit 3757090
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 32 deletions.
14 changes: 7 additions & 7 deletions includes/gateway/class-omise-payment-installment.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ public function payment_fields()
parent::payment_fields();

$currency = get_woocommerce_currency();
$cart_total = $this->getTotalAmount();

global $wp;
$cart_total = $this->getTotalAmount($wp);

$capabilities = $this->backend->capabilities();
$installmentMinLimit = $capabilities->getInstallmentMinLimit();

Expand All @@ -87,13 +90,10 @@ public function payment_fields()
/**
* Get the total amount of an order
*/
public function getTotalAmount()
public function getTotalAmount($wp)
{
// if it's order pay page for admin then get the order total
global $wp;

if ( isset($wp->query_vars['order-pay']) && absint($wp->query_vars['order-pay']) > 0 ) {
$order_id = absint($wp->query_vars['order-pay']); // The order ID
if ( isset($wp->query_vars['order-pay']) && (int)$wp->query_vars['order-pay'] > 0 ) {
$order_id = (int)$wp->query_vars['order-pay']; // The order ID

$order = wc_get_order( $order_id ); // Get the WC_Order Object instance
return $order->total;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,14 @@

class Omise_Payment_Installment_Test extends TestCase
{
private $wp;

public function setUp(): void
{
$offsite = Mockery::mock('overload:Omise_Payment_Offsite');
$offsite->shouldReceive('init_settings');
$offsite->shouldReceive('get_option');

if (!function_exists('wc_get_order')) {
function wc_get_order($orderId) {
$class = new stdClass();
$class->total = 999999;
return $class;
}
}

if (!function_exists('WC')) {
function WC() {
$class = new stdClass();
$class->cart = new stdClass();
$class->cart->total = 999999;
return $class;
}
}

if (!isset($_GLOBALS['wp'])) {
$wp = new stdClass();
$wp->query_vars = ['order-pay' => 11];
}

if (!function_exists('wp_kses')) {
function wp_kses() {}
}
Expand All @@ -42,6 +22,8 @@ function add_action() {}
}

require_once __DIR__ . '/../../../../includes/gateway/class-omise-payment-installment.php';

$this->wp = new stdClass();
}

/**
Expand All @@ -55,11 +37,44 @@ public function tearDown(): void
/**
* @test
*/
public function getTotalAmount()
public function getTotalAmountFromAdminOrderpage()
{
$totalAmount = 999999;

if (!function_exists('wc_get_order')) {
function wc_get_order($orderId) {
$class = new stdClass();
$class->total = 999999;
return $class;
}
}

$this->wp->query_vars = ['order-pay' => 11];
$installment = new Omise_Payment_Installment();
$total = $installment->getTotalAmount($this->wp);

$this->assertEquals($total, $totalAmount);
}

/**
* @test
*/
public function getTotalAmountCart()
{
$totalAmount = 999999;

if (!function_exists('WC')) {
function WC() {
$class = new stdClass();
$class->cart = new stdClass();
$class->cart->total = 999999;
return $class;
}
}

$installment = new Omise_Payment_Installment();
$total = $installment->getTotalAmount();
$total = $installment->getTotalAmount($this->wp);

$this->assertEquals($total, 999999);
$this->assertEquals($total, $totalAmount);
}
}

0 comments on commit 3757090

Please sign in to comment.