Skip to content

Commit

Permalink
Added tests for the changes in Alipay+ HK, Kakaopay and TNG. Fix an i…
Browse files Browse the repository at this point in the history
…ssue of 'class Omise_Payment_Creditcard' not found when user tries to deactivate WooCommerce.
  • Loading branch information
Aashish committed Aug 21, 2023
1 parent 10ed5d5 commit e9ea979
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 26 deletions.
3 changes: 2 additions & 1 deletion omise-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public function __construct()
add_action('plugins_loaded', array($this, 'check_dependencies'));
add_action('woocommerce_init', array($this, 'init'));
do_action('omise_initiated');
add_action('admin_notices', [$this, 'embedded_form_notice']);
}

/**
Expand Down Expand Up @@ -111,6 +110,8 @@ public function init()
{
if (!static::$can_initiate) {
add_action('admin_notices', array($this, 'init_error_messages'));
// Moving here because the class used in the function could not be found on uninstall
add_action('admin_notices', [$this, 'embedded_form_notice']);
return;
}

Expand Down
35 changes: 35 additions & 0 deletions tests/unit/includes/gateway/class-omise-offsite-test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

use PHPunit\Framework\TestCase;
use Mockery;

abstract class Offsite_Test extends TestCase
{
public function setUp(): void
{
// Mocking the parent class
$offsite = Mockery::mock('overload:Omise_Payment_Offsite');
$offsite->shouldReceive('init_settings');
$offsite->shouldReceive('get_option');
$offsite->shouldReceive('get_provider');

// mocking WP built-in functions
if (!function_exists('wp_kses')) {
function wp_kses() {}
}

if (!function_exists('add_action')) {
function add_action() {}
}

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

/**
* close mockery after tests are done
*/
public function teardown(): void
{
Mockery::close();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

require_once __DIR__ . '/class-omise-offsite-test.php';

class Omise_Payment_Alipay_Hk_Test extends Offsite_Test
{
public function setUp(): void
{
parent::setUp();
require_once __DIR__ . '/../../../../includes/gateway/class-omise-payment-alipayplus.php';
}

/**
* @test
*/
public function restrictedCountriesHasRequiredCountries()
{
$obj = new Omise_Payment_Alipay_Hk();
$expectedCountries = ['SG', 'TH'];

$this->assertEqualsCanonicalizing($expectedCountries, $obj->restricted_countries);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

require_once __DIR__ . '/class-omise-offsite-test.php';

class Omise_Payment_Kakaopay_Test extends Offsite_Test
{
public function setUp(): void
{
parent::setUp();
require_once __DIR__ . '/../../../../includes/gateway/class-omise-payment-alipayplus.php';
}

/**
* @test
*/
public function restrictedCountriesHasRequiredCountries()
{
$obj = new Omise_Payment_Kakaopay();
$expectedCountries = ['SG', 'TH'];

$this->assertEqualsCanonicalizing($expectedCountries, $obj->restricted_countries);
}
}
Original file line number Diff line number Diff line change
@@ -1,37 +1,15 @@
<?php

use PHPUnit\Framework\TestCase;
use Mockery;
require_once __DIR__ . '/class-omise-offsite-test.php';

class Omise_Payment_Installment_Test extends TestCase
class Omise_Payment_Installment_Test extends Offsite_Test
{
public function setUp(): void
{
// Mocking the parent class
$offsite = Mockery::mock('overload:Omise_Payment_Offsite');
$offsite->shouldReceive('init_settings');
$offsite->shouldReceive('get_option');

// mocking WP built-in functions
if (!function_exists('wp_kses')) {
function wp_kses() {}
}

if (!function_exists('add_action')) {
function add_action() {}
}

parent::setUp();
require_once __DIR__ . '/../../../../includes/gateway/class-omise-payment-installment.php';
}

/**
* close mockery after tests are done
*/
public function teardown(): void
{
Mockery::close();
}

/**
* @test
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

require_once __DIR__ . '/class-omise-offsite-test.php';

class Omise_Payment_TouchNGo_Test extends Offsite_Test
{
public function setUp(): void
{
parent::setUp();
require_once __DIR__ . '/../../../../includes/gateway/class-omise-payment-touch-n-go.php';
}

/**
* @test
*/
public function restrictedCountriesHasRequiredCountries()
{
$obj = new Omise_Payment_TouchNGo();
$expectedCountries = ['SG', 'MY', 'TH'];

$this->assertEqualsCanonicalizing($expectedCountries, $obj->restricted_countries);
}
}

0 comments on commit e9ea979

Please sign in to comment.