GatewayTest::test_init()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 36
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 20
c 2
b 0
f 0
dl 0
loc 36
rs 9.6
cc 3
nc 4
nop 0
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
9
/**
10
 * Title: MultiSafepay gateway test
11
 * Description:
12
 * Copyright: 2005-2021 Pronamic
13
 * Company: Pronamic
14
 *
15
 * @author  Remco Tolsma
16
 * @version 2.0.5
17
 * @since   1.2.0
18
 */
19
class GatewayTest extends WP_UnitTestCase {
20
	/**
21
	 * Pre HTTP request
22
	 *
23
	 * @link https://github.com/WordPress/WordPress/blob/3.9.1/wp-includes/class-http.php#L150-L164
24
	 * @return string
25
	 */
26
	public function pre_http_request( $preempt, $request, $url ) {
27
		$response = file_get_contents( dirname( dirname( __FILE__ ) ) . '/Mock/ideal-issuers-response.http' );
28
29
		$processed_response = WP_Http::processResponse( $response );
30
31
		$processed_headers = WP_Http::processHeaders( $processed_response['headers'], $url );
32
33
		$processed_headers['body'] = $processed_response['body'];
34
35
		return $processed_headers;
36
	}
37
38
	public function test_init() {
39
		// Mock HTTP request
40
		//add_action( 'http_api_debug', array( $this, 'http_api_debug' ), 10, 5 );
41
		add_filter( 'pre_http_request', array( $this, 'pre_http_request' ), 10, 3 );
42
43
		// Other
44
		$config = new Config();
45
46
		$config->mode       = getenv( 'MULTISAFEPAY_MODE' );
47
		$config->account_id = getenv( 'MULTISAFEPAY_ACCOUNT_ID' );
48
		$config->site_id    = getenv( 'MULTISAFEPAY_SITE_ID' );
49
		$config->site_code  = getenv( 'MULTISAFEPAY_SECURE_CODE' );
50
51
		if ( Gateway::MODE_TEST === $config->mode ) {
52
			$config->api_url = MultiSafepay::API_TEST_URL;
53
		} else {
54
			$config->api_url = MultiSafepay::API_PRODUCTION_URL;
55
		}
56
57
		$gateway = new Gateway( $config );
58
59
		try {
60
			$issuers = $gateway->get_issuers();
61
		} catch ( \Exception $e ) {
62
			$issuers = null;
63
		}
64
65
		$expected = array(
66
			array(
67
				'options' => array(
68
					'3151' => 'Test bank',
69
				),
70
			),
71
		);
72
73
		$this->assertEquals( $expected, $issuers );
74
	}
75
}
76