Skip to content

Commit a62a147

Browse files
authored
Merge pull request #225 from skyverge/apple-pay
Feature: Apple Pay
2 parents b91b061 + ec537cd commit a62a147

24 files changed

+4856
-189
lines changed

phpunit.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
>
1313
<testsuites>
1414
<testsuite name="unit">
15-
<directory suffix=".php">./tests/unit</directory>
15+
<directory suffix=".php">./tests/unit/</directory>
16+
<directory suffix=".php">./tests/unit/*</directory>
1617
</testsuite>
1718
<testsuite name="integration">
1819
<directory suffix=".php">./tests/integration</directory>

tests/bootstrap.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,19 @@ public function load_framework() {
6969
require_once( $this->framework_dir . '/woocommerce/compatibility/abstract-sv-wc-data-compatibility.php' );
7070
require_once( $this->framework_dir . '/woocommerce/compatibility/class-sv-wc-order-compatibility.php' );
7171

72+
// API
73+
require_once( $this->framework_dir . '/woocommerce/api/interface-sv-wc-api-request.php' );
74+
require_once( $this->framework_dir . '/woocommerce/api/interface-sv-wc-api-response.php' );
75+
require_once( $this->framework_dir . '/woocommerce/api/abstract-sv-wc-api-json-request.php' );
76+
require_once( $this->framework_dir . '/woocommerce/api/abstract-sv-wc-api-json-response.php' );
77+
7278
// payment gateways
7379
require_once( $this->framework_dir . '/woocommerce/payment-gateway/class-sv-wc-payment-gateway-helper.php' );
7480
require_once( $this->framework_dir . '/woocommerce/payment-gateway/payment-tokens/class-sv-wc-payment-gateway-payment-token.php' );
7581
require_once( $this->framework_dir . '/woocommerce/payment-gateway/api/class-sv-wc-payment-gateway-api-response-message-helper.php' );
82+
require_once( $this->framework_dir . '/woocommerce/payment-gateway/apple-pay/api/class-sv-wc-payment-gateway-apple-pay-api-request.php' );
83+
require_once( $this->framework_dir . '/woocommerce/payment-gateway/apple-pay/api/class-sv-wc-payment-gateway-apple-pay-api-response.php' );
84+
require_once( $this->framework_dir . '/woocommerce/payment-gateway/apple-pay/api/class-sv-wc-payment-gateway-apple-pay-payment-response.php' );
7685

7786

7887
echo "Loaded Framework..." . PHP_EOL;
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
namespace SkyVerge\WC_Plugin_Framework\Unit_Tests;
4+
5+
use \WP_Mock as Mock;
6+
7+
/**
8+
* Unit tests for \SV_WC_Payment_Gateway_Apple_Pay_API_Request
9+
*
10+
* @since 4.7.0-dev
11+
*/
12+
class Payment_Gateway_Apple_Pay_API_Request extends Test_Case {
13+
14+
15+
/**
16+
* Tests for \SV_WC_Payment_Gateway_Apple_Pay_API_Request::set_merchant_data()
17+
*
18+
* @since 4.7.0-dev
19+
* @dataProvider provider_test_set_merchant_data
20+
*/
21+
public function test_set_merchant_data( $merchant_id, $domain_name, $display_name, $expected ) {
22+
23+
$gateway = $this->getMock( 'SV_WC_Payment_Gateway' );
24+
25+
$request = new \SV_WC_Payment_Gateway_Apple_Pay_API_Request( $gateway );
26+
27+
$request->set_merchant_data( $merchant_id, $domain_name, $display_name );
28+
29+
$this->assertEquals( $expected, $request->to_string() );
30+
}
31+
32+
33+
/**
34+
* Data provider for test_set_merchant_data()
35+
*
36+
* @since 4.5.0
37+
* @return array
38+
*/
39+
public function provider_test_set_merchant_data() {
40+
41+
return array(
42+
array(
43+
'merchant',
44+
'https://domain.com',
45+
'Domain',
46+
json_encode( array(
47+
'merchantIdentifier' => 'merchant',
48+
'domainName' => 'domain.com',
49+
'displayName' => 'Domain',
50+
) ),
51+
),
52+
array(
53+
'merchant',
54+
'http://domain.com',
55+
'Domain',
56+
json_encode( array(
57+
'merchantIdentifier' => 'merchant',
58+
'domainName' => 'domain.com',
59+
'displayName' => 'Domain',
60+
) ),
61+
),
62+
);
63+
}
64+
65+
66+
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<?php
2+
3+
namespace SkyVerge\WC_Plugin_Framework\Unit_Tests;
4+
5+
use \WP_Mock as Mock;
6+
7+
/**
8+
* Unit tests for \SV_WC_Payment_Gateway_Apple_Pay_API_Response
9+
*
10+
* @since 4.7.0-dev
11+
*/
12+
class Payment_Gateway_Apple_Pay_API_Response extends Test_Case {
13+
14+
15+
/**
16+
* Test for \SV_WC_Payment_Gateway_Apple_Pay_Payment_Response::get_status_code()
17+
*
18+
* @since 4.7.0-dev
19+
*/
20+
public function test_get_status_code() {
21+
22+
$response = new \SV_WC_Payment_Gateway_Apple_Pay_API_Response( $this->get_error_response_data() );
23+
24+
$this->assertEquals( '123', $response->get_status_code() );
25+
}
26+
27+
28+
/**
29+
* Test for blank \SV_WC_Payment_Gateway_Apple_Pay_Payment_Response::get_status_code()
30+
*
31+
* @since 4.7.0-dev
32+
*/
33+
public function test_get_status_code_blank() {
34+
35+
$response = new \SV_WC_Payment_Gateway_Apple_Pay_API_Response( '' );
36+
37+
$this->assertNull( $response->get_status_code() );
38+
}
39+
40+
41+
/**
42+
* Test for \SV_WC_Payment_Gateway_Apple_Pay_Payment_Response::get_status_message()
43+
*
44+
* @since 4.7.0-dev
45+
*/
46+
public function test_get_status_message() {
47+
48+
$response = new \SV_WC_Payment_Gateway_Apple_Pay_API_Response( $this->get_error_response_data() );
49+
50+
$this->assertEquals( 'Error', $response->get_status_message() );
51+
}
52+
53+
54+
/**
55+
* Test for blank \SV_WC_Payment_Gateway_Apple_Pay_Payment_Response::get_status_message()
56+
*
57+
* @since 4.7.0-dev
58+
*/
59+
public function test_get_status_message_blank() {
60+
61+
$response = new \SV_WC_Payment_Gateway_Apple_Pay_API_Response( '' );
62+
63+
$this->assertNull( $response->get_status_message() );
64+
}
65+
66+
67+
/**
68+
* Test for \SV_WC_Payment_Gateway_Apple_Pay_Payment_Response::get_merchant_session()
69+
*
70+
* @since 4.7.0-dev
71+
*/
72+
public function test_get_merchant_session() {
73+
74+
$data = json_encode( array( 'response' ) );
75+
76+
$response = new \SV_WC_Payment_Gateway_Apple_Pay_API_Response( $data );
77+
78+
$this->assertEquals( $data, $response->get_merchant_session() );
79+
}
80+
81+
82+
/**
83+
* Test for blank \SV_WC_Payment_Gateway_Apple_Pay_Payment_Response::get_merchant_session()
84+
*
85+
* @since 4.7.0-dev
86+
*/
87+
public function test_get_merchant_session_blank() {
88+
89+
$response = new \SV_WC_Payment_Gateway_Apple_Pay_API_Response( '' );
90+
91+
$this->assertEquals( '', $response->get_merchant_session() );
92+
}
93+
94+
95+
/**
96+
* Gets an example error response.
97+
*
98+
* @since 4.7.0-dev
99+
* @return string
100+
*/
101+
private function get_error_response_data() {
102+
103+
$data = array(
104+
'statusCode' => '123',
105+
'statusMessage' => 'Error',
106+
);
107+
108+
return json_encode( $data );
109+
}
110+
111+
112+
}

0 commit comments

Comments
 (0)