-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathMyPaymentMethodsTest.php
More file actions
141 lines (92 loc) · 4.27 KB
/
MyPaymentMethodsTest.php
File metadata and controls
141 lines (92 loc) · 4.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
use SkyVerge\WooCommerce\PluginFramework\v6_0_2\SV_WC_Payment_Gateway_My_Payment_Methods;
use SkyVerge\WooCommerce\PluginFramework\v6_0_2\SV_WC_Payment_Gateway_Plugin;
/**
* Tests for the SV_WC_Payment_Gateway_My_Payment_Methods class.
*
* @see \SkyVerge\WooCommerce\PluginFramework\v6_0_2\SV_WC_Payment_Gateway_My_Payment_Methods
*/
class MyPaymentMethodsTest extends \Codeception\TestCase\WPTestCase {
/** @var \IntegrationTester */
protected $tester;
/** @var \SkyVerge\WooCommerce\GatewayTestPlugin\Plugin instance */
protected $plugin;
protected function _before() {
}
protected function _after() {
}
/** Tests *********************************************************************************************************/
/**
* @see SV_WC_Payment_Gateway_My_Payment_Methods::get_js_handler_class_name.
*/
public function test_get_js_handler_class_name() {
$method = new ReflectionMethod( SV_WC_Payment_Gateway_Plugin::class, 'get_my_payment_methods_instance' );
$method->setAccessible( true );
$payment_methods = $method->invoke( $this->get_plugin() );
$method = new ReflectionMethod( SV_WC_Payment_Gateway_My_Payment_Methods::class, 'get_js_handler_class_name' );
$method->setAccessible( true );
$result = $method->invoke( $payment_methods );
$this->assertNotEmpty( $result );
$this->assertStringContainsString( 'SV_WC_Payment_Methods_Handler', $result );
$this->assertNotEquals( 'SV_WC_Payment_Methods_Handler', $result );
}
/**
* @see SV_WC_Payment_Gateway_My_Payment_Methods::get_js_handler_args.
*/
public function test_get_js_handler_args() {
$method = new ReflectionMethod( SV_WC_Payment_Gateway_Plugin::class, 'get_my_payment_methods_instance' );
$method->setAccessible( true );
$payment_methods = $method->invoke( $this->get_plugin() );
$method = new ReflectionMethod( SV_WC_Payment_Gateway_My_Payment_Methods::class, 'get_js_handler_args' );
$method->setAccessible( true );
$result = $method->invoke( $payment_methods );
$expected_result = [
'id' => $this->get_plugin()->get_id(),
'slug' => $this->get_plugin()->get_id_dasherized(),
'has_core_tokens' => false,
'ajax_url' => admin_url( 'admin-ajax.php' ),
'ajax_nonce' => wp_create_nonce( 'wc_' . $this->get_plugin()->get_id() . '_save_payment_method' ),
'i18n' => [
'edit_button' => esc_html__( 'Edit', 'woocommerce-plugin-framework' ),
'cancel_button' => esc_html__( 'Cancel', 'woocommerce-plugin-framework' ),
'save_error' => esc_html__( 'Oops, there was an error updating your payment method. Please try again.', 'woocommerce-plugin-framework' ),
'delete_ays' => esc_html__( 'Are you sure you want to delete this payment method?', 'woocommerce-plugin-framework' ),
],
];
$this->assertNotEmpty( $result );
// because assertArraySubset is being deprecated
foreach ( $expected_result as $key => $value ) {
$this->assertArrayHasKey( $key, $result );
$this->assertSame( $value, $result[ $key ] );
}
}
/**
* @see SV_WC_Payment_Gateway_My_Payment_Methods::render_js.
*/
public function test_render_js() {
global $wc_queued_js;
// reset queued scripts
$wc_queued_js = '';
$method = new ReflectionMethod( SV_WC_Payment_Gateway_Plugin::class, 'get_my_payment_methods_instance' );
$method->setAccessible( true );
$payment_methods = $method->invoke( $this->get_plugin() );
$property = new ReflectionProperty( SV_WC_Payment_Gateway_My_Payment_Methods::class, 'has_tokens' );
$property->setAccessible( true );
$property->setValue( $payment_methods, true );
$payment_methods->render_js();
$this->assertStringContainsString( 'function load_gateway_test_plugin_payment_methods_handler', $wc_queued_js );
$this->assertStringContainsString( 'window.jQuery( document.body ).on( \'sv_wc_payment_methods_handler_v6_0_2_loaded\', load_gateway_test_plugin_payment_methods_handler );', $wc_queued_js );
}
/** Helper methods ************************************************************************************************/
/**
* Gets the plugin instance.
*
* @return \SkyVerge\WooCommerce\GatewayTestPlugin\Plugin
*/
protected function get_plugin() {
if ( null === $this->plugin ) {
$this->plugin = sv_wc_gateway_test_plugin();
}
return $this->plugin;
}
}