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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Paypal\Test\Unit\CustomerData;
use Magento\Customer\Helper\Session\CurrentCustomer;
use Magento\Paypal\CustomerData\BillingAgreement;
use Magento\Paypal\Helper\Data;
use Magento\Paypal\Model\Config;
use Magento\Paypal\Model\ConfigFactory;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Framework\Escaper;
class BillingAgreementTest extends \PHPUnit\Framework\TestCase
{
/**
* @var CurrentCustomer | \PHPUnit_Framework_MockObject_MockObject
*/
private $currentCustomer;
/**
* @var Data | \PHPUnit_Framework_MockObject_MockObject
*/
private $paypalData;
/**
* @var Config|\PHPUnit_Framework_MockObject_MockObject
*/
private $paypalConfig;
/**
* @var BillingAgreement
*/
private $billingAgreement;
/**
* @var Escaper
*/
private $escaperMock;
protected function setUp()
{
$helper = new ObjectManager($this);
$this->paypalConfig = $this->createMock(Config::class);
$this->escaperMock = $helper->getObject(Escaper::class);
$this->paypalConfig
->expects($this->once())
->method('setMethod')
->will($this->returnSelf());
$this->paypalConfig->expects($this->once())
->method('setMethod')
->with(Config::METHOD_EXPRESS);
$paypalConfigFactory = $this->createPartialMock(ConfigFactory::class, ['create']);
$paypalConfigFactory->expects($this->once())
->method('create')
->will($this->returnValue($this->paypalConfig));
$customerId = 20;
$this->currentCustomer = $this->createMock(CurrentCustomer::class);
$this->currentCustomer->expects($this->any())
->method('getCustomerId')
->willReturn($customerId);
$this->paypalData = $this->createMock(Data::class);
$this->billingAgreement = $helper->getObject(
BillingAgreement::class,
[
'paypalConfigFactory' => $paypalConfigFactory,
'paypalData' => $this->paypalData,
'currentCustomer' => $this->currentCustomer,
'escaper' => $this->escaperMock
]
);
}
public function testGetSectionData()
{
$this->paypalData->expects($this->once())
->method('shouldAskToCreateBillingAgreement')
->with($this->paypalConfig, $this->currentCustomer->getCustomerId())
->willReturn(true);
$result = $this->billingAgreement->getSectionData();
$this->assertArrayHasKey('askToCreate', $result);
$this->assertArrayHasKey('confirmUrl', $result);
$this->assertArrayHasKey('confirmMessage', $result);
$this->assertEquals(
'Would you like to sign a billing agreement to streamline further purchases with PayPal?',
$result['confirmMessage']
);
$this->assertTrue($result['askToCreate']);
}
public function testGetSectionDataNotNeedToCreateBillingAgreement()
{
$this->paypalData->expects($this->once())
->method('shouldAskToCreateBillingAgreement')
->with($this->paypalConfig, $this->currentCustomer->getCustomerId())
->willReturn(false);
$result = $this->billingAgreement->getSectionData();
$this->assertEmpty($result);
}
}