1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
/** |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace CommerceLeague\ActiveCampaign\Test\Unit\Gateway\Request; |
7
|
|
|
|
8
|
|
|
use CommerceLeague\ActiveCampaign\Gateway\Request\ContactBuilder; |
9
|
|
|
use CommerceLeague\ActiveCampaign\Helper\Contants; |
10
|
|
|
use Magento\Framework\Api\ExtensionAttributesInterface; |
11
|
|
|
use Magento\Newsletter\Model\Subscriber; |
12
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
13
|
|
|
use PHPUnit\Framework\TestCase; |
14
|
|
|
use Magento\Customer\Api\Data\CustomerInterface as MagentoCustomerInterface; |
15
|
|
|
|
16
|
|
|
class ContactBuilderTest extends TestCase |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var MockObject|MagentoCustomerInterface |
20
|
|
|
*/ |
21
|
|
|
protected $magentoCustomer; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var MockObject|Subscriber |
25
|
|
|
*/ |
26
|
|
|
protected $subscriber; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var MockObject|ExtensionAttributesInterface |
30
|
|
|
*/ |
31
|
|
|
protected $extensionAttributes; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var ContactBuilder |
35
|
|
|
*/ |
36
|
|
|
protected $contactBuilder; |
37
|
|
|
|
38
|
|
|
protected function setUp() |
39
|
|
|
{ |
40
|
|
|
$this->magentoCustomer = $this->createMock(MagentoCustomerInterface::class); |
41
|
|
|
$this->subscriber = $this->createMock(Subscriber::class); |
42
|
|
|
$this->extensionAttributes = $this->getMockBuilder(ExtensionAttributesInterface::class) |
43
|
|
|
->setMethods(['getIsSubscribed']) |
44
|
|
|
->getMockForAbstractClass(); |
45
|
|
|
|
46
|
|
|
$this->contactBuilder = new ContactBuilder(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testBuildWithMagentoCustomerNotSubscribed() |
50
|
|
|
{ |
51
|
|
|
$email = '[email protected]'; |
52
|
|
|
$firstName = 'firstName'; |
53
|
|
|
$lastName = 'lastName'; |
54
|
|
|
|
55
|
|
|
$this->magentoCustomer->expects($this->once()) |
|
|
|
|
56
|
|
|
->method('getExtensionAttributes') |
57
|
|
|
->willReturn($this->extensionAttributes); |
58
|
|
|
|
59
|
|
|
$this->extensionAttributes->expects($this->once()) |
|
|
|
|
60
|
|
|
->method('getIsSubscribed') |
61
|
|
|
->willReturn(false); |
62
|
|
|
|
63
|
|
|
$this->magentoCustomer->expects($this->once()) |
64
|
|
|
->method('getEmail') |
65
|
|
|
->willReturn($email); |
66
|
|
|
|
67
|
|
|
$this->magentoCustomer->expects($this->once()) |
68
|
|
|
->method('getFirstname') |
69
|
|
|
->willReturn($firstName); |
70
|
|
|
|
71
|
|
|
$this->magentoCustomer->expects($this->once()) |
72
|
|
|
->method('getLastname') |
73
|
|
|
->willReturn($lastName); |
74
|
|
|
|
75
|
|
|
$expected = [ |
76
|
|
|
'status' => Contants::CONTACT_STATUS_UNSUBSCRIBED, |
77
|
|
|
'email' => $email, |
78
|
|
|
'firstName' => $firstName, |
79
|
|
|
'lastName' => $lastName |
80
|
|
|
]; |
81
|
|
|
|
82
|
|
|
$this->assertEquals( |
83
|
|
|
$expected, |
84
|
|
|
$this->contactBuilder->buildWithMagentoCustomer($this->magentoCustomer) |
85
|
|
|
); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
|
89
|
|
|
public function testBuildWithMagentoCustomerSubscribed() |
90
|
|
|
{ |
91
|
|
|
$email = '[email protected]'; |
92
|
|
|
$firstName = 'firstName'; |
93
|
|
|
$lastName = 'lastName'; |
94
|
|
|
|
95
|
|
|
$this->magentoCustomer->expects($this->once()) |
96
|
|
|
->method('getExtensionAttributes') |
97
|
|
|
->willReturn($this->extensionAttributes); |
98
|
|
|
|
99
|
|
|
$this->extensionAttributes->expects($this->once()) |
100
|
|
|
->method('getIsSubscribed') |
101
|
|
|
->willReturn(true); |
102
|
|
|
|
103
|
|
|
$this->magentoCustomer->expects($this->once()) |
104
|
|
|
->method('getEmail') |
105
|
|
|
->willReturn($email); |
106
|
|
|
|
107
|
|
|
$this->magentoCustomer->expects($this->once()) |
108
|
|
|
->method('getFirstname') |
109
|
|
|
->willReturn($firstName); |
110
|
|
|
|
111
|
|
|
$this->magentoCustomer->expects($this->once()) |
112
|
|
|
->method('getLastname') |
113
|
|
|
->willReturn($lastName); |
114
|
|
|
|
115
|
|
|
$expected = [ |
116
|
|
|
'status' => Contants::CONTACT_STATUS_ACTIVE, |
117
|
|
|
'email' => $email, |
118
|
|
|
'firstName' => $firstName, |
119
|
|
|
'lastName' => $lastName |
120
|
|
|
]; |
121
|
|
|
|
122
|
|
|
$this->assertEquals( |
123
|
|
|
$expected, |
124
|
|
|
$this->contactBuilder->buildWithMagentoCustomer($this->magentoCustomer) |
125
|
|
|
); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
public function testBuildWithSubscriberNotSubscribed() |
129
|
|
|
{ |
130
|
|
|
$email = '[email protected]'; |
131
|
|
|
|
132
|
|
|
$this->subscriber->expects($this->once()) |
133
|
|
|
->method('isSubscribed') |
|
|
|
|
134
|
|
|
->willReturn(false); |
|
|
|
|
135
|
|
|
|
136
|
|
|
$this->subscriber->expects($this->once()) |
137
|
|
|
->method('getEmail') |
138
|
|
|
->willReturn($email); |
139
|
|
|
|
140
|
|
|
$expected = [ |
141
|
|
|
'status' => Contants::CONTACT_STATUS_UNSUBSCRIBED, |
142
|
|
|
'email' => $email |
143
|
|
|
]; |
144
|
|
|
|
145
|
|
|
$this->assertEquals( |
146
|
|
|
$expected, |
147
|
|
|
$this->contactBuilder->buildWithSubscriber($this->subscriber) |
148
|
|
|
); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
public function testBuildWithSubscriberSubscribed() |
152
|
|
|
{ |
153
|
|
|
$email = '[email protected]'; |
154
|
|
|
|
155
|
|
|
$this->subscriber->expects($this->once()) |
156
|
|
|
->method('isSubscribed') |
157
|
|
|
->willReturn(true); |
158
|
|
|
|
159
|
|
|
$this->subscriber->expects($this->once()) |
160
|
|
|
->method('getEmail') |
161
|
|
|
->willReturn($email); |
162
|
|
|
|
163
|
|
|
$expected = [ |
164
|
|
|
'status' => Contants::CONTACT_STATUS_ACTIVE, |
165
|
|
|
'email' => $email |
166
|
|
|
]; |
167
|
|
|
|
168
|
|
|
$this->assertEquals( |
169
|
|
|
$expected, |
170
|
|
|
$this->contactBuilder->buildWithSubscriber($this->subscriber) |
171
|
|
|
); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
} |
175
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.