@@ -394,9 +394,9 @@ public function provide_is_wallet_payment_method(): array {
394
394
* @return void
395
395
*/
396
396
public function test_handle_main_stripe_settings () {
397
- WC_Stripe_Helper::update_main_stripe_settings ( [ 'test ' => 'test ' ] );
397
+ WC_Stripe_Helper::update_main_stripe_settings ( [ 'test ' => 'abc ' ] );
398
398
$ current_settings = WC_Stripe_Helper::get_stripe_settings ();
399
- $ this ->assertSame ( [ 'test ' => ' test ' ], $ current_settings );
399
+ $ this ->assertSame ( $ current_settings [ 'test ' ], ' abc ' );
400
400
401
401
WC_Stripe_Helper::delete_main_stripe_settings ();
402
402
$ current_settings = WC_Stripe_Helper::get_stripe_settings ();
@@ -507,4 +507,43 @@ public function test_add_stripe_methods_in_woocommerce_gateway_order() {
507
507
$ this ->assertTrue ( $ gateway_order ['stripe ' ] < $ gateway_order ['stripe_affirm ' ] );
508
508
$ this ->assertTrue ( $ gateway_order ['stripe_affirm ' ] < $ gateway_order ['cheque ' ] );
509
509
}
510
+
511
+ /**
512
+ * Test for `add_mandate_data`.
513
+ *
514
+ * @param string $server_variable_key The key of the server variable to set.
515
+ * @param string $server_variable_value The value to set the server variable to.
516
+ * @param string $expected_ip_address The expected IP address.
517
+ * @dataProvider provider_test_add_mandate_data
518
+ * @return void
519
+ */
520
+ public function test_add_mandate_data ( $ server_variable_key , $ server_variable_value , $ expected_ip_address ) {
521
+ unset( $ _SERVER ['REMOTE_ADDR ' ] );
522
+ unset( $ _SERVER ['HTTP_X_REAL_IP ' ] );
523
+ unset( $ _SERVER ['HTTP_X_FORWARDED_FOR ' ] );
524
+
525
+ $ _SERVER [ $ server_variable_key ] = $ server_variable_value ;
526
+ $ request = WC_Stripe_Helper::add_mandate_data ( [] );
527
+ $ this ->assertTrue ( isset ( $ request ['mandate_data ' ]['customer_acceptance ' ]['online ' ]['ip_address ' ] ) );
528
+ $ ip_address = $ request ['mandate_data ' ]['customer_acceptance ' ]['online ' ]['ip_address ' ];
529
+ $ this ->assertSame ( $ expected_ip_address , $ ip_address );
530
+ }
531
+
532
+ /**
533
+ * Data provider for `test_add_mandate_data`.
534
+ *
535
+ * @return array
536
+ */
537
+ public function provider_test_add_mandate_data () {
538
+ return [
539
+ [ 'REMOTE_ADDR ' , '192.168.1.1 ' , '192.168.1.1 ' ],
540
+ [ 'REMOTE_ADDR ' , '192.168.1.1, 192.168.1.2, 192.168.1.3 ' , '192.168.1.1 ' ],
541
+ [ 'HTTP_X_REAL_IP ' , '192.168.1.1 ' , '192.168.1.1 ' ],
542
+ [ 'HTTP_X_REAL_IP ' , '192.168.1.1, 192.168.1.2, 192.168.1.3 ' , '192.168.1.1 ' ],
543
+ [ 'HTTP_X_FORWARDED_FOR ' , '192.168.1.1, 192.168.1.2, 192.168.1.3 ' , '192.168.1.1 ' ],
544
+ [ 'HTTP_X_FORWARDED_FOR ' , '192.168.1.1 ' , '192.168.1.1 ' ],
545
+ [ 'HTTP_X_REAL_IP ' , 'invalid-ip-address ' , 'invalid-ip-address ' ],
546
+ [ 'HTTP_X_REAL_IP ' , '' , '' ],
547
+ ];
548
+ }
510
549
}
0 commit comments