1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Pronamic\WordPress\Pay\Gateways\MultiSafepay; |
4
|
|
|
|
5
|
|
|
use WP_Http; |
6
|
|
|
use WP_UnitTestCase; |
7
|
|
|
use Pronamic\WordPress\Pay\Gateways\MultiSafepay\MultiSafepay; |
8
|
|
|
use Pronamic\WordPress\Pay\Gateways\MultiSafepay\Config; |
9
|
|
|
|
10
|
|
|
class GatewaysTest extends WP_UnitTestCase { |
11
|
|
|
/** |
12
|
|
|
* Pre HTTP request |
13
|
|
|
* |
14
|
|
|
* @link https://github.com/WordPress/WordPress/blob/3.9.1/wp-includes/class-http.php#L150-L164 |
15
|
|
|
* @return string |
16
|
|
|
*/ |
17
|
|
|
public function pre_http_request( $preempt, $request, $url ) { |
18
|
|
|
$response = file_get_contents( dirname( dirname( __FILE__ ) ) . '/Mock/gateways-response.http' ); |
19
|
|
|
|
20
|
|
|
$processed_response = WP_Http::processResponse( $response ); |
21
|
|
|
|
22
|
|
|
$processed_headers = WP_Http::processHeaders( $processed_response['headers'], $url ); |
23
|
|
|
|
24
|
|
|
$processed_headers['body'] = $processed_response['body']; |
25
|
|
|
|
26
|
|
|
return $processed_headers; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function http_api_debug( $response, $context, $class, $args, $url ) { |
|
|
|
|
30
|
|
|
|
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function test_init() { |
34
|
|
|
// Mock HTTP request |
35
|
|
|
//add_action( 'http_api_debug', array( $this, 'http_api_debug' ), 10, 5 ); |
36
|
|
|
add_filter( 'pre_http_request', array( $this, 'pre_http_request' ), 10, 3 ); |
37
|
|
|
|
38
|
|
|
// Config |
39
|
|
|
$config = new Config(); |
40
|
|
|
|
41
|
|
|
$config->mode = getenv( 'MULTISAFEPAY_MODE' ); |
42
|
|
|
$config->account_id = getenv( 'MULTISAFEPAY_ACCOUNT_ID' ); |
43
|
|
|
$config->site_id = getenv( 'MULTISAFEPAY_SITE_ID' ); |
44
|
|
|
$config->site_code = getenv( 'MULTISAFEPAY_SECURE_CODE' ); |
45
|
|
|
|
46
|
|
|
if ( Gateway::MODE_TEST === $config->mode ) { |
47
|
|
|
$config->api_url = MultiSafepay::API_TEST_URL; |
48
|
|
|
} else { |
49
|
|
|
$config->api_url = MultiSafepay::API_PRODUCTION_URL; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
// Client |
53
|
|
|
$client = new Client(); |
54
|
|
|
|
55
|
|
|
$client->api_url = $config->api_url; |
56
|
|
|
|
57
|
|
|
// Merchant |
58
|
|
|
$merchant = new Merchant(); |
59
|
|
|
|
60
|
|
|
$merchant->account = $config->account_id; |
61
|
|
|
$merchant->site_id = $config->site_id; |
62
|
|
|
$merchant->site_secure_code = $config->site_code; |
63
|
|
|
|
64
|
|
|
// Customer |
65
|
|
|
$customer = new Customer(); |
66
|
|
|
|
67
|
|
|
$customer->locale = get_locale(); |
68
|
|
|
|
69
|
|
|
// Gateways |
70
|
|
|
$gateways = $client->get_gateways( $merchant, $customer ); |
71
|
|
|
|
72
|
|
|
$expected = array( |
73
|
|
|
'VISA' => 'Visa', |
74
|
|
|
'GIROPAY' => 'Giropay', |
75
|
|
|
'PAYAFTER' => 'Pay After Delivery', |
76
|
|
|
'IDEAL' => 'iDEAL', |
77
|
|
|
'DIRECTBANK' => 'SOFORT Banking', |
78
|
|
|
'BANKTRANS' => 'Wire Transfer', |
79
|
|
|
'MASTERCARD' => 'MasterCard', |
80
|
|
|
); |
81
|
|
|
|
82
|
|
|
$this->assertEquals( $expected, $gateways ); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.