ApplePayTest.php
2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
namespace Test\Integration;
require_once dirname(__DIR__) . '/Setup.php';
use Test;
use Test\Setup;
use Braintree;
class ApplePayTest extends Setup
{
    private static $gateway;
    public static function setUpBeforeClass()
    {
        self::$gateway = self::_buildMerchantGateway();
    }
    public static function tearDownAfterClass()
    {
        self::$gateway = null;
    }
    private static function _buildMerchantGateway()
    {
        $gateway = new Braintree\Gateway([
            'clientId' => 'client_id$development$integration_client_id',
            'clientSecret' => 'client_secret$development$integration_client_secret',
        ]);
        $result = $gateway->merchant()->create([
            'email' => 'name@email.com',
            'countryCodeAlpha3' => 'USA',
            'paymentMethods' => ['credit_card', 'paypal'],
        ]);
        return new Braintree\Gateway([
            'accessToken' => $result->credentials->accessToken,
        ]);
    }
    public function testRegisterDomainWithExpectedStubbedResult()
    {
        $result = self::$gateway->applePay()->registerDomain('domain');
        $this->assertEquals(true, $result->success);
    }
    public function testValidationErrorWhenRegisteringNoDomain()
    {
        $result = self::$gateway->applePay()->registerDomain('');
        $this->assertEquals(false, $result->success);
        $this->assertEquals(1, preg_match('/Domain name is required\./', $result->message));
    }
    public function testUnregisterDomainWithExpectedStubbedResult()
    {
        $domain = 'example.com';
        $result = self::$gateway->applePay()->unregisterDomain($domain);
        $this->assertEquals(true, $result->success);
    }
    public function testUnregisterDomainWithSpecialCharactersWithExpectedStubbedResult()
    {
        $domain = 'ex&mple.com';
        $result = self::$gateway->applePay()->unregisterDomain($domain);
        $this->assertEquals(true, $result->success);
    }
    public function testUnregisterDomainWithSchemeWithExpectedStubbedResult()
    {
        $domain = 'http://example.com';
        $result = self::$gateway->applePay()->unregisterDomain($domain);
        $this->assertEquals(true, $result->success);
    }
    public function testRegisteredDomainsWithExpectedStubbedResult()
    {
        $result = self::$gateway->applePay()->registeredDomains();
        $this->assertEquals(true, $result->success);
        $registeredDomains = $result->applePayOptions->domains;
        $this->assertEmpty(array_diff(['www.example.com'], $registeredDomains));
    }
}