Test Failed
Push — develop ( fd928b...40893b )
by Remco
04:14
created

GatewayTest::pre_http_request()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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