2020-01-28 22:33:53 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Contains tests for the COD Payment Gateway.
|
2020-02-04 23:50:23 +00:00
|
|
|
*
|
2020-08-05 16:36:24 +00:00
|
|
|
* @package WooCommerce\Tests\PaymentGateways
|
2020-01-28 22:33:53 +00:00
|
|
|
*/
|
|
|
|
|
2020-02-04 23:50:23 +00:00
|
|
|
use Automattic\Jetpack\Constants;
|
|
|
|
|
2020-01-28 22:33:53 +00:00
|
|
|
/**
|
|
|
|
* Class WC_Tests_Payment_Gateway_COD
|
|
|
|
*/
|
|
|
|
class WC_Tests_Payment_Gateway_COD extends WC_Unit_Test_Case {
|
|
|
|
|
2020-02-04 23:50:23 +00:00
|
|
|
/**
|
|
|
|
* Clean up after each test.
|
|
|
|
*/
|
|
|
|
public function tearDown() {
|
|
|
|
parent::tearDown();
|
|
|
|
|
|
|
|
Constants::clear_constants();
|
|
|
|
}
|
2020-01-28 22:33:53 +00:00
|
|
|
/**
|
|
|
|
* Make sure that the options for the "enable_for_methods" setting are not loaded by default.
|
|
|
|
*/
|
|
|
|
public function test_method_options_not_loaded_universally() {
|
|
|
|
$gateway = new WC_Gateway_COD();
|
|
|
|
|
|
|
|
$form_fields = $gateway->get_form_fields();
|
|
|
|
|
|
|
|
$this->assertArrayHasKey( 'enable_for_methods', $form_fields );
|
|
|
|
$this->assertEmpty( $form_fields['enable_for_methods']['options'] );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Make sure that the options for the "enable_for_methods" setting are loaded on the admin page.
|
|
|
|
*/
|
|
|
|
public function test_method_options_loaded_for_admin_page() {
|
2020-02-04 23:50:23 +00:00
|
|
|
set_current_screen( 'woocommerce_page_wc-settings' );
|
2020-02-06 20:29:01 +00:00
|
|
|
$_REQUEST['page'] = 'wc-settings';
|
|
|
|
$_REQUEST['tab'] = 'checkout';
|
|
|
|
$_REQUEST['section'] = 'cod';
|
2020-01-28 22:33:53 +00:00
|
|
|
|
|
|
|
$gateway = new WC_Gateway_COD();
|
|
|
|
|
|
|
|
$form_fields = $gateway->get_form_fields();
|
|
|
|
|
2020-02-06 20:29:01 +00:00
|
|
|
// Clean up!
|
2020-02-04 23:50:23 +00:00
|
|
|
$GLOBALS['current_screen'] = null; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
|
2020-02-06 20:29:01 +00:00
|
|
|
unset( $_REQUEST['page'] );
|
|
|
|
unset( $_REQUEST['tab'] );
|
|
|
|
unset( $_REQUEST['section'] );
|
2020-02-04 23:50:23 +00:00
|
|
|
|
2020-01-28 22:33:53 +00:00
|
|
|
$this->assertArrayHasKey( 'enable_for_methods', $form_fields );
|
|
|
|
$this->assertNotEmpty( $form_fields['enable_for_methods']['options'] );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Make sure that the options for the "enable_for_methods" setting are not loaded for API requests that don't need it.
|
|
|
|
*/
|
|
|
|
public function test_method_options_not_loaded_for_incorrect_api() {
|
2020-02-04 23:50:23 +00:00
|
|
|
Constants::set_constant( 'REST_REQUEST', true );
|
2020-01-28 22:33:53 +00:00
|
|
|
$GLOBALS['wp']->query_vars['rest_route'] = '/wc/v2/products';
|
|
|
|
|
|
|
|
$gateway = new WC_Gateway_COD();
|
|
|
|
|
|
|
|
$form_fields = $gateway->get_form_fields();
|
|
|
|
|
|
|
|
$this->assertArrayHasKey( 'enable_for_methods', $form_fields );
|
|
|
|
$this->assertEmpty( $form_fields['enable_for_methods']['options'] );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Make sure that the options for the "enable_for_methods" setting are loaded for API requests that need it.
|
|
|
|
*/
|
|
|
|
public function test_method_options_loaded_for_correct_api() {
|
2020-02-04 23:50:23 +00:00
|
|
|
Constants::set_constant( 'REST_REQUEST', true );
|
2020-01-28 22:33:53 +00:00
|
|
|
$GLOBALS['wp']->query_vars['rest_route'] = '/wc/v2/payment_gateways';
|
|
|
|
|
|
|
|
$gateway = new WC_Gateway_COD();
|
|
|
|
|
|
|
|
$form_fields = $gateway->get_form_fields();
|
|
|
|
|
|
|
|
$this->assertArrayHasKey( 'enable_for_methods', $form_fields );
|
|
|
|
$this->assertNotEmpty( $form_fields['enable_for_methods']['options'] );
|
|
|
|
}
|
|
|
|
}
|