Passed
Pull Request — staging (#9244)
by Dennis
26:42 queued 13:05
created
Tests/Tracker/Service/ContactTrackingService/ContactTrackingServiceTest.php 1 patch
Switch Indentation   +282 added lines, -282 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php
1
+    <?php
2 2
 
3 3
 /*
4 4
  * @copyright   2017 Mautic Contributors. All rights reserved
@@ -9,316 +9,316 @@  discard block
 block discarded – undo
9 9
  * @license     GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
10 10
  */
11 11
 
12
-namespace Mautic\LeadBundle\Tests\Tracker\Service\ContactTrackingService;
12
+    namespace Mautic\LeadBundle\Tests\Tracker\Service\ContactTrackingService;
13 13
 
14
-use Mautic\CoreBundle\Helper\CookieHelper;
15
-use Mautic\LeadBundle\Entity\Lead;
16
-use Mautic\LeadBundle\Entity\LeadDeviceRepository;
17
-use Mautic\LeadBundle\Entity\LeadRepository;
18
-use Mautic\LeadBundle\Entity\MergeRecordRepository;
19
-use Mautic\LeadBundle\Tracker\Service\ContactTrackingService\ContactTrackingService;
20
-use Symfony\Component\HttpFoundation\Request;
21
-use Symfony\Component\HttpFoundation\RequestStack;
14
+    use Mautic\CoreBundle\Helper\CookieHelper;
15
+    use Mautic\LeadBundle\Entity\Lead;
16
+    use Mautic\LeadBundle\Entity\LeadDeviceRepository;
17
+    use Mautic\LeadBundle\Entity\LeadRepository;
18
+    use Mautic\LeadBundle\Entity\MergeRecordRepository;
19
+    use Mautic\LeadBundle\Tracker\Service\ContactTrackingService\ContactTrackingService;
20
+    use Symfony\Component\HttpFoundation\Request;
21
+    use Symfony\Component\HttpFoundation\RequestStack;
22 22
 
23 23
 /**
24 24
  * Class ContactTrackingServiceTest.
25 25
  */
26
-final class ContactTrackingServiceTest extends \PHPUnit\Framework\TestCase
27
-{
28
-    /**
26
+    final class ContactTrackingServiceTest extends \PHPUnit\Framework\TestCase
27
+    {
28
+        /**
29 29
      * @var \PHPUnit\Framework\MockObject\MockObject
30 30
      */
31
-    private $cookieHelperMock;
31
+        private $cookieHelperMock;
32 32
 
33
-    /**
33
+        /**
34 34
      * @var \PHPUnit\Framework\MockObject\MockObject
35 35
      */
36
-    private $leadDeviceRepositoryMock;
36
+        private $leadDeviceRepositoryMock;
37 37
 
38
-    /**
38
+        /**
39 39
      * @var \PHPUnit\Framework\MockObject\MockObject
40 40
      */
41
-    private $leadRepositoryMock;
41
+        private $leadRepositoryMock;
42 42
 
43
-    /**
43
+        /**
44 44
      * @var \PHPUnit\Framework\MockObject\MockObject
45 45
      */
46
-    private $requestStackMock;
46
+        private $requestStackMock;
47 47
 
48
-    /**
48
+        /**
49 49
      * @var MergeRecordRepository
50 50
      */
51
-    private $mergeRecordRepository;
52
-
53
-    protected function setUp(): void
54
-    {
55
-        $this->cookieHelperMock         = $this->createMock(CookieHelper::class);
56
-        $this->leadDeviceRepositoryMock = $this->createMock(LeadDeviceRepository::class);
57
-        $this->leadRepositoryMock       = $this->createMock(LeadRepository::class);
58
-        $this->requestStackMock         = $this->createMock(RequestStack::class);
59
-        $this->mergeRecordRepository    = $this->createMock(MergeRecordRepository::class);
60
-    }
61
-
62
-    public function testGetTrackedIdentifier()
63
-    {
64
-        // Parameters
65
-        $trackingId = 'randomTrackingId';
66
-
67
-        $this->cookieHelperMock->expects($this->at(0))
68
-            ->method('getCookie')
69
-            ->with('mautic_session_id', null)
70
-            ->willReturn($trackingId);
71
-
72
-        $contactTrackingService = $this->getContactTrackingService();
73
-        $this->assertSame($trackingId, $contactTrackingService->getTrackedIdentifier());
74
-    }
75
-
76
-    public function testGetTrackedLeadNoRequest()
77
-    {
78
-        // __construct
79
-        $this->requestStackMock->expects($this->at(0))
80
-            ->method('getCurrentRequest')
81
-            ->willReturn(null);
82
-
83
-        $contactTrackingService = $this->getContactTrackingService();
84
-        $this->assertNull($contactTrackingService->getTrackedLead());
85
-    }
86
-
87
-    public function testGetTrackedLeadNoTrackedIdentifier()
88
-    {
89
-        // Parameters
90
-        $requestMock = $this->createMock(Request::class);
91
-
92
-        // __construct
93
-        $this->requestStackMock->expects($this->at(0))
94
-            ->method('getCurrentRequest')
95
-            ->willReturn($requestMock);
96
-
97
-        // getTrackedIdentifier()
98
-        $this->cookieHelperMock->expects($this->at(0))
99
-            ->method('getCookie')
100
-            ->with('mautic_session_id', null)
101
-            ->willReturn(null);
102
-
103
-        $contactTrackingService = $this->getContactTrackingService();
104
-        $this->assertNull($contactTrackingService->getTrackedLead());
105
-    }
106
-
107
-    /**
51
+        private $mergeRecordRepository;
52
+
53
+        protected function setUp(): void
54
+        {
55
+            $this->cookieHelperMock         = $this->createMock(CookieHelper::class);
56
+            $this->leadDeviceRepositoryMock = $this->createMock(LeadDeviceRepository::class);
57
+            $this->leadRepositoryMock       = $this->createMock(LeadRepository::class);
58
+            $this->requestStackMock         = $this->createMock(RequestStack::class);
59
+            $this->mergeRecordRepository    = $this->createMock(MergeRecordRepository::class);
60
+        }
61
+
62
+        public function testGetTrackedIdentifier()
63
+        {
64
+            // Parameters
65
+            $trackingId = 'randomTrackingId';
66
+
67
+            $this->cookieHelperMock->expects($this->at(0))
68
+                ->method('getCookie')
69
+                ->with('mautic_session_id', null)
70
+                ->willReturn($trackingId);
71
+
72
+            $contactTrackingService = $this->getContactTrackingService();
73
+            $this->assertSame($trackingId, $contactTrackingService->getTrackedIdentifier());
74
+        }
75
+
76
+        public function testGetTrackedLeadNoRequest()
77
+        {
78
+            // __construct
79
+            $this->requestStackMock->expects($this->at(0))
80
+                ->method('getCurrentRequest')
81
+                ->willReturn(null);
82
+
83
+            $contactTrackingService = $this->getContactTrackingService();
84
+            $this->assertNull($contactTrackingService->getTrackedLead());
85
+        }
86
+
87
+        public function testGetTrackedLeadNoTrackedIdentifier()
88
+        {
89
+            // Parameters
90
+            $requestMock = $this->createMock(Request::class);
91
+
92
+            // __construct
93
+            $this->requestStackMock->expects($this->at(0))
94
+                ->method('getCurrentRequest')
95
+                ->willReturn($requestMock);
96
+
97
+            // getTrackedIdentifier()
98
+            $this->cookieHelperMock->expects($this->at(0))
99
+                ->method('getCookie')
100
+                ->with('mautic_session_id', null)
101
+                ->willReturn(null);
102
+
103
+            $contactTrackingService = $this->getContactTrackingService();
104
+            $this->assertNull($contactTrackingService->getTrackedLead());
105
+        }
106
+
107
+        /**
108 108
      * Test no lead id found.
109 109
      */
110
-    public function testGetTrackedLeadNoLeadId()
111
-    {
112
-        // Parameters
113
-        $requestMock = $this->createMock(Request::class);
114
-        $trackingId  = 'randomTrackingId';
115
-
116
-        // __construct
117
-        $this->requestStackMock->expects($this->at(0))
118
-            ->method('getCurrentRequest')
119
-            ->willReturn($requestMock);
120
-
121
-        // getTrackedIdentifier()
122
-        $this->cookieHelperMock->expects($this->at(0))
123
-            ->method('getCookie')
124
-            ->with('mautic_session_id', null)
125
-            ->willReturn($trackingId);
126
-
127
-        $this->cookieHelperMock->expects($this->at(1))
128
-            ->method('getCookie')
129
-            ->with($trackingId, null)
130
-            ->willReturn(null);
131
-
132
-        $requestMock->expects($this->at(0))
133
-            ->method('get')
134
-            ->with('mtc_id', null)
135
-            ->willReturn(null);
136
-
137
-        $contactTrackingService = $this->getContactTrackingService();
138
-        $this->assertNull($contactTrackingService->getTrackedLead());
139
-    }
140
-
141
-    /**
110
+        public function testGetTrackedLeadNoLeadId()
111
+        {
112
+            // Parameters
113
+            $requestMock = $this->createMock(Request::class);
114
+            $trackingId  = 'randomTrackingId';
115
+
116
+            // __construct
117
+            $this->requestStackMock->expects($this->at(0))
118
+                ->method('getCurrentRequest')
119
+                ->willReturn($requestMock);
120
+
121
+            // getTrackedIdentifier()
122
+            $this->cookieHelperMock->expects($this->at(0))
123
+                ->method('getCookie')
124
+                ->with('mautic_session_id', null)
125
+                ->willReturn($trackingId);
126
+
127
+            $this->cookieHelperMock->expects($this->at(1))
128
+                ->method('getCookie')
129
+                ->with($trackingId, null)
130
+                ->willReturn(null);
131
+
132
+            $requestMock->expects($this->at(0))
133
+                ->method('get')
134
+                ->with('mtc_id', null)
135
+                ->willReturn(null);
136
+
137
+            $contactTrackingService = $this->getContactTrackingService();
138
+            $this->assertNull($contactTrackingService->getTrackedLead());
139
+        }
140
+
141
+        /**
142 142
      * Test lead id found in request but no lead entity found.
143 143
      */
144
-    public function testGetTrackedLeadRequestLeadIdAndNoLeadFound()
145
-    {
146
-        // Parameters
147
-        $requestMock = $this->createMock(Request::class);
148
-        $trackingId  = 'randomTrackingId';
149
-        $leadId      = 1;
150
-
151
-        // __construct
152
-        $this->requestStackMock->expects($this->at(0))
153
-            ->method('getCurrentRequest')
154
-            ->willReturn($requestMock);
155
-
156
-        // getTrackedIdentifier()
157
-        $this->cookieHelperMock->expects($this->at(0))
158
-            ->method('getCookie')
159
-            ->with('mautic_session_id', null)
160
-            ->willReturn($trackingId);
161
-
162
-        $this->cookieHelperMock->expects($this->at(1))
163
-            ->method('getCookie')
164
-            ->with($trackingId, null)
165
-            ->willReturn(null);
166
-
167
-        $requestMock->expects($this->at(0))
168
-            ->method('get')
169
-            ->with('mtc_id', null)
170
-            ->willReturn($leadId);
171
-
172
-        $this->leadRepositoryMock->expects($this->at(0))
173
-            ->method('getEntity')
174
-            ->with($leadId)
175
-            ->willReturn(null);
176
-
177
-        $contactTrackingService = $this->getContactTrackingService();
178
-        $this->assertNull($contactTrackingService->getTrackedLead());
179
-    }
180
-
181
-    /**
144
+        public function testGetTrackedLeadRequestLeadIdAndNoLeadFound()
145
+        {
146
+            // Parameters
147
+            $requestMock = $this->createMock(Request::class);
148
+            $trackingId  = 'randomTrackingId';
149
+            $leadId      = 1;
150
+
151
+            // __construct
152
+            $this->requestStackMock->expects($this->at(0))
153
+                ->method('getCurrentRequest')
154
+                ->willReturn($requestMock);
155
+
156
+            // getTrackedIdentifier()
157
+            $this->cookieHelperMock->expects($this->at(0))
158
+                ->method('getCookie')
159
+                ->with('mautic_session_id', null)
160
+                ->willReturn($trackingId);
161
+
162
+            $this->cookieHelperMock->expects($this->at(1))
163
+                ->method('getCookie')
164
+                ->with($trackingId, null)
165
+                ->willReturn(null);
166
+
167
+            $requestMock->expects($this->at(0))
168
+                ->method('get')
169
+                ->with('mtc_id', null)
170
+                ->willReturn($leadId);
171
+
172
+            $this->leadRepositoryMock->expects($this->at(0))
173
+                ->method('getEntity')
174
+                ->with($leadId)
175
+                ->willReturn(null);
176
+
177
+            $contactTrackingService = $this->getContactTrackingService();
178
+            $this->assertNull($contactTrackingService->getTrackedLead());
179
+        }
180
+
181
+        /**
182 182
      * Test lead id found in request and another device is already tracked and associated with lead.
183 183
      */
184
-    public function testGetTrackedLeadRequestLeadIdAndAnotherDeviceAlreadyTracked()
185
-    {
186
-        // Parameters
187
-        $requestMock = $this->createMock(Request::class);
188
-        $trackingId  = 'randomTrackingId';
189
-        $leadId      = 1;
190
-        $leadMock    = $this->createMock(Lead::class);
191
-
192
-        // __construct
193
-        $this->requestStackMock->expects($this->at(0))
194
-            ->method('getCurrentRequest')
195
-            ->willReturn($requestMock);
196
-
197
-        // getTrackedIdentifier()
198
-        $this->cookieHelperMock->expects($this->at(0))
199
-            ->method('getCookie')
200
-            ->with('mautic_session_id', null)
201
-            ->willReturn($trackingId);
202
-
203
-        $this->cookieHelperMock->expects($this->at(1))
204
-            ->method('getCookie')
205
-            ->with($trackingId, null)
206
-            ->willReturn(null);
207
-
208
-        $requestMock->expects($this->at(0))
209
-            ->method('get')
210
-            ->with('mtc_id', null)
211
-            ->willReturn($leadId);
212
-
213
-        $this->leadRepositoryMock->expects($this->at(0))
214
-            ->method('getEntity')
215
-            ->with($leadId)
216
-            ->willReturn($leadMock);
217
-        $this->leadDeviceRepositoryMock->expects($this->at(0))
218
-            ->method('isAnyLeadDeviceTracked')
219
-            ->with($leadMock)
220
-            ->willReturn(true);
221
-
222
-        $contactTrackingService = $this->getContactTrackingService();
223
-        $this->assertNull($contactTrackingService->getTrackedLead());
224
-    }
225
-
226
-    /**
184
+        public function testGetTrackedLeadRequestLeadIdAndAnotherDeviceAlreadyTracked()
185
+        {
186
+            // Parameters
187
+            $requestMock = $this->createMock(Request::class);
188
+            $trackingId  = 'randomTrackingId';
189
+            $leadId      = 1;
190
+            $leadMock    = $this->createMock(Lead::class);
191
+
192
+            // __construct
193
+            $this->requestStackMock->expects($this->at(0))
194
+                ->method('getCurrentRequest')
195
+                ->willReturn($requestMock);
196
+
197
+            // getTrackedIdentifier()
198
+            $this->cookieHelperMock->expects($this->at(0))
199
+                ->method('getCookie')
200
+                ->with('mautic_session_id', null)
201
+                ->willReturn($trackingId);
202
+
203
+            $this->cookieHelperMock->expects($this->at(1))
204
+                ->method('getCookie')
205
+                ->with($trackingId, null)
206
+                ->willReturn(null);
207
+
208
+            $requestMock->expects($this->at(0))
209
+                ->method('get')
210
+                ->with('mtc_id', null)
211
+                ->willReturn($leadId);
212
+
213
+            $this->leadRepositoryMock->expects($this->at(0))
214
+                ->method('getEntity')
215
+                ->with($leadId)
216
+                ->willReturn($leadMock);
217
+            $this->leadDeviceRepositoryMock->expects($this->at(0))
218
+                ->method('isAnyLeadDeviceTracked')
219
+                ->with($leadMock)
220
+                ->willReturn(true);
221
+
222
+            $contactTrackingService = $this->getContactTrackingService();
223
+            $this->assertNull($contactTrackingService->getTrackedLead());
224
+        }
225
+
226
+        /**
227 227
      * Test lead id found in request and another device is not tracked and associated with lead.
228 228
      */
229
-    public function testGetTrackedLeadRequestLeadIdAndAnotherDeviceNotTracked()
230
-    {
231
-        // Parameters
232
-        $requestMock = $this->createMock(Request::class);
233
-        $trackingId  = 'randomTrackingId';
234
-        $leadId      = 1;
235
-        $leadMock    = $this->createMock(Lead::class);
236
-
237
-        // __construct
238
-        $this->requestStackMock->expects($this->at(0))
239
-            ->method('getCurrentRequest')
240
-            ->willReturn($requestMock);
241
-
242
-        // getTrackedIdentifier()
243
-        $this->cookieHelperMock->expects($this->at(0))
244
-            ->method('getCookie')
245
-            ->with('mautic_session_id', null)
246
-            ->willReturn($trackingId);
247
-
248
-        $this->cookieHelperMock->expects($this->at(1))
249
-            ->method('getCookie')
250
-            ->with($trackingId, null)
251
-            ->willReturn(null);
252
-
253
-        $requestMock->expects($this->at(0))
254
-            ->method('get')
255
-            ->with('mtc_id', null)
256
-            ->willReturn($leadId);
257
-
258
-        $this->leadRepositoryMock->expects($this->at(0))
259
-            ->method('getEntity')
260
-            ->with($leadId)
261
-            ->willReturn($leadMock);
262
-        $this->leadDeviceRepositoryMock->expects($this->at(0))
263
-            ->method('isAnyLeadDeviceTracked')
264
-            ->with($leadMock)
265
-            ->willReturn(false);
266
-
267
-        $contactTrackingService = $this->getContactTrackingService();
268
-        $this->assertSame($leadMock, $contactTrackingService->getTrackedLead());
269
-    }
270
-
271
-    /**
229
+        public function testGetTrackedLeadRequestLeadIdAndAnotherDeviceNotTracked()
230
+        {
231
+            // Parameters
232
+            $requestMock = $this->createMock(Request::class);
233
+            $trackingId  = 'randomTrackingId';
234
+            $leadId      = 1;
235
+            $leadMock    = $this->createMock(Lead::class);
236
+
237
+            // __construct
238
+            $this->requestStackMock->expects($this->at(0))
239
+                ->method('getCurrentRequest')
240
+                ->willReturn($requestMock);
241
+
242
+            // getTrackedIdentifier()
243
+            $this->cookieHelperMock->expects($this->at(0))
244
+                ->method('getCookie')
245
+                ->with('mautic_session_id', null)
246
+                ->willReturn($trackingId);
247
+
248
+            $this->cookieHelperMock->expects($this->at(1))
249
+                ->method('getCookie')
250
+                ->with($trackingId, null)
251
+                ->willReturn(null);
252
+
253
+            $requestMock->expects($this->at(0))
254
+                ->method('get')
255
+                ->with('mtc_id', null)
256
+                ->willReturn($leadId);
257
+
258
+            $this->leadRepositoryMock->expects($this->at(0))
259
+                ->method('getEntity')
260
+                ->with($leadId)
261
+                ->willReturn($leadMock);
262
+            $this->leadDeviceRepositoryMock->expects($this->at(0))
263
+                ->method('isAnyLeadDeviceTracked')
264
+                ->with($leadMock)
265
+                ->willReturn(false);
266
+
267
+            $contactTrackingService = $this->getContactTrackingService();
268
+            $this->assertSame($leadMock, $contactTrackingService->getTrackedLead());
269
+        }
270
+
271
+        /**
272 272
      * Test lead id found in request and another device is not tracked and associated with lead.
273 273
      */
274
-    public function testGetTrackedLeadCookieLeadIdAndAnotherDeviceNotTracked()
275
-    {
276
-        // Parameters
277
-        $requestMock = $this->createMock(Request::class);
278
-        $trackingId  = 'randomTrackingId';
279
-        $leadId      = 1;
280
-        $leadMock    = $this->createMock(Lead::class);
281
-
282
-        // __construct
283
-        $this->requestStackMock->expects($this->at(0))
284
-            ->method('getCurrentRequest')
285
-            ->willReturn($requestMock);
286
-
287
-        // getTrackedIdentifier()
288
-        $this->cookieHelperMock->expects($this->at(0))
289
-            ->method('getCookie')
290
-            ->with('mautic_session_id', null)
291
-            ->willReturn($trackingId);
292
-
293
-        $this->cookieHelperMock->expects($this->at(1))
294
-            ->method('getCookie')
295
-            ->with($trackingId, null)
296
-            ->willReturn($leadId);
297
-
298
-        $this->leadRepositoryMock->expects($this->at(0))
299
-            ->method('getEntity')
300
-            ->with($leadId)
301
-            ->willReturn($leadMock);
302
-        $this->leadDeviceRepositoryMock->expects($this->at(0))
303
-            ->method('isAnyLeadDeviceTracked')
304
-            ->with($leadMock)
305
-            ->willReturn(false);
306
-
307
-        $contactTrackingService = $this->getContactTrackingService();
308
-        $this->assertSame($leadMock, $contactTrackingService->getTrackedLead());
309
-    }
310
-
311
-    /**
274
+        public function testGetTrackedLeadCookieLeadIdAndAnotherDeviceNotTracked()
275
+        {
276
+            // Parameters
277
+            $requestMock = $this->createMock(Request::class);
278
+            $trackingId  = 'randomTrackingId';
279
+            $leadId      = 1;
280
+            $leadMock    = $this->createMock(Lead::class);
281
+
282
+            // __construct
283
+            $this->requestStackMock->expects($this->at(0))
284
+                ->method('getCurrentRequest')
285
+                ->willReturn($requestMock);
286
+
287
+            // getTrackedIdentifier()
288
+            $this->cookieHelperMock->expects($this->at(0))
289
+                ->method('getCookie')
290
+                ->with('mautic_session_id', null)
291
+                ->willReturn($trackingId);
292
+
293
+            $this->cookieHelperMock->expects($this->at(1))
294
+                ->method('getCookie')
295
+                ->with($trackingId, null)
296
+                ->willReturn($leadId);
297
+
298
+            $this->leadRepositoryMock->expects($this->at(0))
299
+                ->method('getEntity')
300
+                ->with($leadId)
301
+                ->willReturn($leadMock);
302
+            $this->leadDeviceRepositoryMock->expects($this->at(0))
303
+                ->method('isAnyLeadDeviceTracked')
304
+                ->with($leadMock)
305
+                ->willReturn(false);
306
+
307
+            $contactTrackingService = $this->getContactTrackingService();
308
+            $this->assertSame($leadMock, $contactTrackingService->getTrackedLead());
309
+        }
310
+
311
+        /**
312 312
      * @return ContactTrackingService
313 313
      */
314
-    private function getContactTrackingService()
315
-    {
316
-        return new ContactTrackingService(
317
-            $this->cookieHelperMock,
318
-            $this->leadDeviceRepositoryMock,
319
-            $this->leadRepositoryMock,
320
-            $this->mergeRecordRepository,
321
-            $this->requestStackMock
322
-        );
323
-    }
314
+        private function getContactTrackingService()
315
+        {
316
+            return new ContactTrackingService(
317
+                $this->cookieHelperMock,
318
+                $this->leadDeviceRepositoryMock,
319
+                $this->leadRepositoryMock,
320
+                $this->mergeRecordRepository,
321
+                $this->requestStackMock
322
+            );
323
+        }
324 324
 }
Please login to merge, or discard this patch.
Tests/Tracker/Service/DeviceTrackingService/DeviceTrackingServiceTest.php 1 patch
Switch Indentation   +391 added lines, -391 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php
1
+    <?php
2 2
 
3 3
 /*
4 4
  * @copyright   2017 Mautic Contributors. All rights reserved
@@ -9,430 +9,430 @@  discard block
 block discarded – undo
9 9
  * @license     GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
10 10
  */
11 11
 
12
-namespace Mautic\LeadBundle\Tests\Tracker\Service\DeviceTrackingService;
12
+    namespace Mautic\LeadBundle\Tests\Tracker\Service\DeviceTrackingService;
13 13
 
14
-use Doctrine\ORM\EntityManagerInterface;
15
-use Mautic\CoreBundle\Helper\CookieHelper;
16
-use Mautic\CoreBundle\Helper\RandomHelper\RandomHelperInterface;
17
-use Mautic\CoreBundle\Security\Permissions\CorePermissions;
18
-use Mautic\LeadBundle\Entity\Lead;
19
-use Mautic\LeadBundle\Entity\LeadDevice;
20
-use Mautic\LeadBundle\Entity\LeadDeviceRepository;
21
-use Mautic\LeadBundle\Tracker\Service\DeviceTrackingService\DeviceTrackingService;
22
-use Symfony\Component\HttpFoundation\Request;
23
-use Symfony\Component\HttpFoundation\RequestStack;
14
+    use Doctrine\ORM\EntityManagerInterface;
15
+    use Mautic\CoreBundle\Helper\CookieHelper;
16
+    use Mautic\CoreBundle\Helper\RandomHelper\RandomHelperInterface;
17
+    use Mautic\CoreBundle\Security\Permissions\CorePermissions;
18
+    use Mautic\LeadBundle\Entity\Lead;
19
+    use Mautic\LeadBundle\Entity\LeadDevice;
20
+    use Mautic\LeadBundle\Entity\LeadDeviceRepository;
21
+    use Mautic\LeadBundle\Tracker\Service\DeviceTrackingService\DeviceTrackingService;
22
+    use Symfony\Component\HttpFoundation\Request;
23
+    use Symfony\Component\HttpFoundation\RequestStack;
24 24
 
25 25
 /**
26 26
  * Class CompanyModelTest.
27 27
  */
28
-final class DeviceTrackingServiceTest extends \PHPUnit\Framework\TestCase
29
-{
30
-    /**
28
+    final class DeviceTrackingServiceTest extends \PHPUnit\Framework\TestCase
29
+    {
30
+        /**
31 31
      * @var \PHPUnit\Framework\MockObject\MockObject
32 32
      */
33
-    private $cookieHelperMock;
33
+        private $cookieHelperMock;
34 34
 
35
-    /**
35
+        /**
36 36
      * @var \PHPUnit\Framework\MockObject\MockObject
37 37
      */
38
-    private $entityManagerMock;
38
+        private $entityManagerMock;
39 39
 
40
-    /**
40
+        /**
41 41
      * @var \PHPUnit\Framework\MockObject\MockObject
42 42
      */
43
-    private $randomHelperMock;
43
+        private $randomHelperMock;
44 44
 
45
-    /**
45
+        /**
46 46
      * @var \PHPUnit\Framework\MockObject\MockObject
47 47
      */
48
-    private $leadDeviceRepositoryMock;
48
+        private $leadDeviceRepositoryMock;
49 49
 
50
-    /**
50
+        /**
51 51
      * @var \PHPUnit\Framework\MockObject\MockObject
52 52
      */
53
-    private $requestStackMock;
53
+        private $requestStackMock;
54 54
 
55
-    /**
55
+        /**
56 56
      * @var \PHPUnit\Framework\MockObject\MockObject
57 57
      */
58
-    private $security;
59
-
60
-    protected function setUp(): void
61
-    {
62
-        $this->cookieHelperMock            = $this->createMock(CookieHelper::class);
63
-        $this->entityManagerMock           = $this->createMock(EntityManagerInterface::class);
64
-        $this->randomHelperMock            = $this->createMock(RandomHelperInterface::class);
65
-        $this->leadDeviceRepositoryMock    = $this->createMock(LeadDeviceRepository::class);
66
-        $this->requestStackMock            = $this->createMock(RequestStack::class);
67
-        $this->security                    = $this->createMock(CorePermissions::class);
68
-    }
69
-
70
-    public function testIsTrackedTrue()
71
-    {
72
-        // Parameters
73
-        $trackingId = 'randomTrackingId';
74
-
75
-        // __construct()
76
-        $requestMock = $this->createMock(Request::class);
77
-        $this->requestStackMock->expects($this->at(0))
78
-            ->method('getCurrentRequest')
79
-            ->willReturn($requestMock);
80
-
81
-        // getTrackedIdentifier()
82
-        $this->cookieHelperMock->expects($this->at(0))
83
-            ->method('getCookie')
84
-            ->with('mautic_device_id', null)
85
-            ->willReturn($trackingId);
86
-        $leadDeviceMock = $this->createMock(LeadDevice::class);
87
-
88
-        $this->security->expects($this->once())
89
-            ->method('isAnonymous')
90
-            ->willReturn(true);
91
-
92
-        $this->leadDeviceRepositoryMock->expects($this->at(0))
93
-            ->method('getByTrackingId')
94
-            ->with($trackingId)
95
-            ->willReturn($leadDeviceMock);
96
-
97
-        $deviceTrackingService = $this->getDeviceTrackingService();
98
-        $this->assertTrue($deviceTrackingService->isTracked());
99
-    }
100
-
101
-    public function testIsTrackedFalse()
102
-    {
103
-        // Parameters
104
-        $trackingId = 'randomTrackingId';
105
-
106
-        // __construct()
107
-        $requestMock = $this->createMock(Request::class);
108
-        $this->requestStackMock->expects($this->at(0))
109
-            ->method('getCurrentRequest')
110
-            ->willReturn($requestMock);
111
-
112
-        // getTrackedIdentifier()
113
-        $this->cookieHelperMock->expects($this->at(0))
114
-            ->method('getCookie')
115
-            ->with('mautic_device_id', null)
116
-            ->willReturn($trackingId);
117
-
118
-        $this->security->expects($this->once())
119
-            ->method('isAnonymous')
120
-            ->willReturn(true);
121
-
122
-        $this->leadDeviceRepositoryMock->expects($this->at(0))
123
-            ->method('getByTrackingId')
124
-            ->with($trackingId)
125
-            ->willReturn(null);
126
-
127
-        $deviceTrackingService = $this->getDeviceTrackingService();
128
-        $this->assertFalse($deviceTrackingService->isTracked());
129
-    }
130
-
131
-    public function testGetTrackedDeviceCookie()
132
-    {
133
-        // Parameters
134
-        $trackingId = 'randomTrackingId';
135
-
136
-        // __construct()
137
-        $requestMock = $this->createMock(Request::class);
138
-        $this->requestStackMock->expects($this->at(0))
139
-            ->method('getCurrentRequest')
140
-            ->willReturn($requestMock);
141
-
142
-        // getTrackedIdentifier()
143
-        $this->cookieHelperMock->expects($this->at(0))
144
-            ->method('getCookie')
145
-            ->with('mautic_device_id', null)
146
-            ->willReturn($trackingId);
147
-
148
-        $this->security->expects($this->once())
149
-            ->method('isAnonymous')
150
-            ->willReturn(true);
151
-
152
-        $leadDeviceMock = $this->createMock(LeadDevice::class);
153
-        $this->leadDeviceRepositoryMock->expects($this->at(0))
154
-            ->method('getByTrackingId')
155
-            ->with($trackingId)
156
-            ->willReturn($leadDeviceMock);
157
-
158
-        $deviceTrackingService = $this->getDeviceTrackingService();
159
-        $this->assertSame($leadDeviceMock, $deviceTrackingService->getTrackedDevice());
160
-    }
161
-
162
-    public function testGetTrackedDeviceGetFromRequest()
163
-    {
164
-        // Parameters
165
-        $trackingId = 'randomTrackingId';
166
-
167
-        // __construct()
168
-        $requestMock = $this->createMock(Request::class);
169
-        $this->requestStackMock->expects($this->at(0))
170
-            ->method('getCurrentRequest')
171
-            ->willReturn($requestMock);
172
-
173
-        // getTrackedIdentifier()
174
-        $this->cookieHelperMock->expects($this->at(0))
175
-            ->method('getCookie')
176
-            ->with('mautic_device_id', null)
177
-            ->willReturn(null);
178
-        $requestMock->expects($this->at(0))
179
-            ->method('get')
180
-            ->with('mautic_device_id', null)
181
-            ->willReturn($trackingId);
182
-
183
-        $this->security->expects($this->once())
184
-            ->method('isAnonymous')
185
-            ->willReturn(true);
186
-
187
-        $leadDeviceMock = $this->createMock(LeadDevice::class);
188
-        $this->leadDeviceRepositoryMock->expects($this->at(0))
189
-            ->method('getByTrackingId')
190
-            ->with($trackingId)
191
-            ->willReturn($leadDeviceMock);
192
-
193
-        $deviceTrackingService = $this->getDeviceTrackingService();
194
-        $this->assertSame($leadDeviceMock, $deviceTrackingService->getTrackedDevice());
195
-    }
196
-
197
-    public function testGetTrackedDeviceNoTrackingId()
198
-    {
199
-        // __construct()
200
-        $requestMock = $this->createMock(Request::class);
201
-        $this->requestStackMock->expects($this->at(0))
202
-            ->method('getCurrentRequest')
203
-            ->willReturn($requestMock);
204
-
205
-        // getTrackedIdentifier()
206
-        $this->cookieHelperMock->expects($this->at(0))
207
-            ->method('getCookie')
208
-            ->with('mautic_device_id', null)
209
-            ->willReturn(null);
210
-        $requestMock->expects($this->at(0))
211
-            ->method('get')
212
-            ->with('mautic_device_id', null)
213
-            ->willReturn(null);
214
-
215
-        $this->security->expects($this->once())
216
-            ->method('isAnonymous')
217
-            ->willReturn(true);
218
-
219
-        $this->leadDeviceRepositoryMock->expects($this->never())
220
-            ->method('getByTrackingId');
221
-
222
-        $deviceTrackingService = $this->getDeviceTrackingService();
223
-        $this->assertNull($deviceTrackingService->getTrackedDevice());
224
-    }
225
-
226
-    public function testGetTrackedDeviceNoRequest()
227
-    {
228
-        // __construct()
229
-        $this->requestStackMock->expects($this->at(0))
230
-            ->method('getCurrentRequest')
231
-            ->willReturn(null);
232
-
233
-        $deviceTrackingService = $this->getDeviceTrackingService();
234
-        $this->assertNull($deviceTrackingService->getTrackedDevice());
235
-    }
236
-
237
-    /**
58
+        private $security;
59
+
60
+        protected function setUp(): void
61
+        {
62
+            $this->cookieHelperMock            = $this->createMock(CookieHelper::class);
63
+            $this->entityManagerMock           = $this->createMock(EntityManagerInterface::class);
64
+            $this->randomHelperMock            = $this->createMock(RandomHelperInterface::class);
65
+            $this->leadDeviceRepositoryMock    = $this->createMock(LeadDeviceRepository::class);
66
+            $this->requestStackMock            = $this->createMock(RequestStack::class);
67
+            $this->security                    = $this->createMock(CorePermissions::class);
68
+        }
69
+
70
+        public function testIsTrackedTrue()
71
+        {
72
+            // Parameters
73
+            $trackingId = 'randomTrackingId';
74
+
75
+            // __construct()
76
+            $requestMock = $this->createMock(Request::class);
77
+            $this->requestStackMock->expects($this->at(0))
78
+                ->method('getCurrentRequest')
79
+                ->willReturn($requestMock);
80
+
81
+            // getTrackedIdentifier()
82
+            $this->cookieHelperMock->expects($this->at(0))
83
+                ->method('getCookie')
84
+                ->with('mautic_device_id', null)
85
+                ->willReturn($trackingId);
86
+            $leadDeviceMock = $this->createMock(LeadDevice::class);
87
+
88
+            $this->security->expects($this->once())
89
+                ->method('isAnonymous')
90
+                ->willReturn(true);
91
+
92
+            $this->leadDeviceRepositoryMock->expects($this->at(0))
93
+                ->method('getByTrackingId')
94
+                ->with($trackingId)
95
+                ->willReturn($leadDeviceMock);
96
+
97
+            $deviceTrackingService = $this->getDeviceTrackingService();
98
+            $this->assertTrue($deviceTrackingService->isTracked());
99
+        }
100
+
101
+        public function testIsTrackedFalse()
102
+        {
103
+            // Parameters
104
+            $trackingId = 'randomTrackingId';
105
+
106
+            // __construct()
107
+            $requestMock = $this->createMock(Request::class);
108
+            $this->requestStackMock->expects($this->at(0))
109
+                ->method('getCurrentRequest')
110
+                ->willReturn($requestMock);
111
+
112
+            // getTrackedIdentifier()
113
+            $this->cookieHelperMock->expects($this->at(0))
114
+                ->method('getCookie')
115
+                ->with('mautic_device_id', null)
116
+                ->willReturn($trackingId);
117
+
118
+            $this->security->expects($this->once())
119
+                ->method('isAnonymous')
120
+                ->willReturn(true);
121
+
122
+            $this->leadDeviceRepositoryMock->expects($this->at(0))
123
+                ->method('getByTrackingId')
124
+                ->with($trackingId)
125
+                ->willReturn(null);
126
+
127
+            $deviceTrackingService = $this->getDeviceTrackingService();
128
+            $this->assertFalse($deviceTrackingService->isTracked());
129
+        }
130
+
131
+        public function testGetTrackedDeviceCookie()
132
+        {
133
+            // Parameters
134
+            $trackingId = 'randomTrackingId';
135
+
136
+            // __construct()
137
+            $requestMock = $this->createMock(Request::class);
138
+            $this->requestStackMock->expects($this->at(0))
139
+                ->method('getCurrentRequest')
140
+                ->willReturn($requestMock);
141
+
142
+            // getTrackedIdentifier()
143
+            $this->cookieHelperMock->expects($this->at(0))
144
+                ->method('getCookie')
145
+                ->with('mautic_device_id', null)
146
+                ->willReturn($trackingId);
147
+
148
+            $this->security->expects($this->once())
149
+                ->method('isAnonymous')
150
+                ->willReturn(true);
151
+
152
+            $leadDeviceMock = $this->createMock(LeadDevice::class);
153
+            $this->leadDeviceRepositoryMock->expects($this->at(0))
154
+                ->method('getByTrackingId')
155
+                ->with($trackingId)
156
+                ->willReturn($leadDeviceMock);
157
+
158
+            $deviceTrackingService = $this->getDeviceTrackingService();
159
+            $this->assertSame($leadDeviceMock, $deviceTrackingService->getTrackedDevice());
160
+        }
161
+
162
+        public function testGetTrackedDeviceGetFromRequest()
163
+        {
164
+            // Parameters
165
+            $trackingId = 'randomTrackingId';
166
+
167
+            // __construct()
168
+            $requestMock = $this->createMock(Request::class);
169
+            $this->requestStackMock->expects($this->at(0))
170
+                ->method('getCurrentRequest')
171
+                ->willReturn($requestMock);
172
+
173
+            // getTrackedIdentifier()
174
+            $this->cookieHelperMock->expects($this->at(0))
175
+                ->method('getCookie')
176
+                ->with('mautic_device_id', null)
177
+                ->willReturn(null);
178
+            $requestMock->expects($this->at(0))
179
+                ->method('get')
180
+                ->with('mautic_device_id', null)
181
+                ->willReturn($trackingId);
182
+
183
+            $this->security->expects($this->once())
184
+                ->method('isAnonymous')
185
+                ->willReturn(true);
186
+
187
+            $leadDeviceMock = $this->createMock(LeadDevice::class);
188
+            $this->leadDeviceRepositoryMock->expects($this->at(0))
189
+                ->method('getByTrackingId')
190
+                ->with($trackingId)
191
+                ->willReturn($leadDeviceMock);
192
+
193
+            $deviceTrackingService = $this->getDeviceTrackingService();
194
+            $this->assertSame($leadDeviceMock, $deviceTrackingService->getTrackedDevice());
195
+        }
196
+
197
+        public function testGetTrackedDeviceNoTrackingId()
198
+        {
199
+            // __construct()
200
+            $requestMock = $this->createMock(Request::class);
201
+            $this->requestStackMock->expects($this->at(0))
202
+                ->method('getCurrentRequest')
203
+                ->willReturn($requestMock);
204
+
205
+            // getTrackedIdentifier()
206
+            $this->cookieHelperMock->expects($this->at(0))
207
+                ->method('getCookie')
208
+                ->with('mautic_device_id', null)
209
+                ->willReturn(null);
210
+            $requestMock->expects($this->at(0))
211
+                ->method('get')
212
+                ->with('mautic_device_id', null)
213
+                ->willReturn(null);
214
+
215
+            $this->security->expects($this->once())
216
+                ->method('isAnonymous')
217
+                ->willReturn(true);
218
+
219
+            $this->leadDeviceRepositoryMock->expects($this->never())
220
+                ->method('getByTrackingId');
221
+
222
+            $deviceTrackingService = $this->getDeviceTrackingService();
223
+            $this->assertNull($deviceTrackingService->getTrackedDevice());
224
+        }
225
+
226
+        public function testGetTrackedDeviceNoRequest()
227
+        {
228
+            // __construct()
229
+            $this->requestStackMock->expects($this->at(0))
230
+                ->method('getCurrentRequest')
231
+                ->willReturn(null);
232
+
233
+            $deviceTrackingService = $this->getDeviceTrackingService();
234
+            $this->assertNull($deviceTrackingService->getTrackedDevice());
235
+        }
236
+
237
+        /**
238 238
      * Test tracking device with already tracked current device.
239 239
      */
240
-    public function testTrackCurrentDeviceAlreadyTracked()
241
-    {
242
-        // Parameters
243
-        $leadDeviceMock        = $this->createMock(LeadDevice::class);
244
-        $trackingId            = 'randomTrackingId';
245
-        $trackedLeadDeviceMock = $this->createMock(LeadDevice::class);
246
-
247
-        // __construct()
248
-        $requestMock = $this->createMock(Request::class);
249
-        $this->requestStackMock->expects($this->at(0))
250
-            ->method('getCurrentRequest')
251
-            ->willReturn($requestMock);
252
-
253
-        // getTrackedDevice()
254
-        // getTrackedIdentifier()
255
-        $this->cookieHelperMock->expects($this->at(0))
256
-            ->method('getCookie')
257
-            ->with('mautic_device_id', null)
258
-            ->willReturn($trackingId);
259
-
260
-        $this->security->expects($this->once())
261
-            ->method('isAnonymous')
262
-            ->willReturn(true);
263
-
264
-        $this->leadDeviceRepositoryMock->expects($this->at(0))
265
-            ->method('getByTrackingId')
266
-            ->with($trackingId)
267
-            ->willReturn($trackedLeadDeviceMock);
268
-
269
-        $deviceTrackingService = $this->getDeviceTrackingService();
270
-        $returnedLeadDevice    = $deviceTrackingService->trackCurrentDevice($leadDeviceMock, false);
271
-        $this->assertInstanceOf(LeadDevice::class, $returnedLeadDevice);
272
-    }
273
-
274
-    /**
240
+        public function testTrackCurrentDeviceAlreadyTracked()
241
+        {
242
+            // Parameters
243
+            $leadDeviceMock        = $this->createMock(LeadDevice::class);
244
+            $trackingId            = 'randomTrackingId';
245
+            $trackedLeadDeviceMock = $this->createMock(LeadDevice::class);
246
+
247
+            // __construct()
248
+            $requestMock = $this->createMock(Request::class);
249
+            $this->requestStackMock->expects($this->at(0))
250
+                ->method('getCurrentRequest')
251
+                ->willReturn($requestMock);
252
+
253
+            // getTrackedDevice()
254
+            // getTrackedIdentifier()
255
+            $this->cookieHelperMock->expects($this->at(0))
256
+                ->method('getCookie')
257
+                ->with('mautic_device_id', null)
258
+                ->willReturn($trackingId);
259
+
260
+            $this->security->expects($this->once())
261
+                ->method('isAnonymous')
262
+                ->willReturn(true);
263
+
264
+            $this->leadDeviceRepositoryMock->expects($this->at(0))
265
+                ->method('getByTrackingId')
266
+                ->with($trackingId)
267
+                ->willReturn($trackedLeadDeviceMock);
268
+
269
+            $deviceTrackingService = $this->getDeviceTrackingService();
270
+            $returnedLeadDevice    = $deviceTrackingService->trackCurrentDevice($leadDeviceMock, false);
271
+            $this->assertInstanceOf(LeadDevice::class, $returnedLeadDevice);
272
+        }
273
+
274
+        /**
275 275
      * Test tracking device with already tracked current device, replace existing tracking.
276 276
      */
277
-    public function testTrackCurrentDeviceAlreadyTrackedReplaceExistingTracking()
278
-    {
279
-        // Parameters
280
-        $leadDeviceMock           = $this->createMock(LeadDevice::class);
281
-        $trackingId               = 'randomTrackingId';
282
-        $trackedLeadDeviceMock    = $this->createMock(LeadDevice::class);
283
-        $uniqueTrackingIdentifier = '1234567890abcdefghij123';
284
-
285
-        // __construct()
286
-        $requestMock = $this->createMock(Request::class);
287
-        $this->requestStackMock->expects($this->at(0))
288
-            ->method('getCurrentRequest')
289
-            ->willReturn($requestMock);
290
-
291
-        // getTrackedDevice()
292
-        // getTrackedIdentifier()
293
-        $this->cookieHelperMock->expects($this->at(0))
294
-            ->method('getCookie')
295
-            ->with('mautic_device_id', null)
296
-            ->willReturn($trackingId);
297
-
298
-        $this->security->expects($this->once())
299
-            ->method('isAnonymous')
300
-            ->willReturn(true);
301
-
302
-        $this->leadDeviceRepositoryMock->expects($this->at(0))
303
-            ->method('getByTrackingId')
304
-            ->with($trackingId)
305
-            ->willReturn($trackedLeadDeviceMock);
306
-
307
-        // getUniqueTrackingIdentifier()
308
-        $this->randomHelperMock->expects($this->at(0))
309
-            ->method('generate')
310
-            ->with(23)
311
-            ->willReturn($uniqueTrackingIdentifier);
312
-
313
-        $this->entityManagerMock->expects($this->at(0))
314
-            ->method('persist')
315
-            ->with($leadDeviceMock);
316
-
317
-        // index 0-3 for leadDeviceRepository::findOneBy
318
-        $leadDeviceMock->expects($this->at(4))
319
-            ->method('getTrackingId')
320
-            ->willReturn(null);
321
-        $leadDeviceMock->expects($this->at(5))
322
-            ->method('setTrackingId')
323
-            ->with($uniqueTrackingIdentifier)
324
-            ->willReturn($leadDeviceMock);
325
-        $leadDeviceMock->expects($this->at(6))
326
-            ->method('getTrackingId')
327
-            ->willReturn($uniqueTrackingIdentifier);
328
-        $leadDeviceMock->expects($this->exactly(2))
329
-            ->method('getLead')
330
-            ->willReturn(new Lead());
331
-        $this->cookieHelperMock->expects($this->at(1))
332
-            ->method('setCookie')
333
-            ->with('mautic_device_id', $uniqueTrackingIdentifier, 31536000);
334
-
335
-        $deviceTrackingService = $this->getDeviceTrackingService();
336
-        $returnedLeadDevice    = $deviceTrackingService->trackCurrentDevice($leadDeviceMock, true);
337
-        $this->assertInstanceOf(LeadDevice::class, $returnedLeadDevice);
338
-    }
339
-
340
-    /**
277
+        public function testTrackCurrentDeviceAlreadyTrackedReplaceExistingTracking()
278
+        {
279
+            // Parameters
280
+            $leadDeviceMock           = $this->createMock(LeadDevice::class);
281
+            $trackingId               = 'randomTrackingId';
282
+            $trackedLeadDeviceMock    = $this->createMock(LeadDevice::class);
283
+            $uniqueTrackingIdentifier = '1234567890abcdefghij123';
284
+
285
+            // __construct()
286
+            $requestMock = $this->createMock(Request::class);
287
+            $this->requestStackMock->expects($this->at(0))
288
+                ->method('getCurrentRequest')
289
+                ->willReturn($requestMock);
290
+
291
+            // getTrackedDevice()
292
+            // getTrackedIdentifier()
293
+            $this->cookieHelperMock->expects($this->at(0))
294
+                ->method('getCookie')
295
+                ->with('mautic_device_id', null)
296
+                ->willReturn($trackingId);
297
+
298
+            $this->security->expects($this->once())
299
+                ->method('isAnonymous')
300
+                ->willReturn(true);
301
+
302
+            $this->leadDeviceRepositoryMock->expects($this->at(0))
303
+                ->method('getByTrackingId')
304
+                ->with($trackingId)
305
+                ->willReturn($trackedLeadDeviceMock);
306
+
307
+            // getUniqueTrackingIdentifier()
308
+            $this->randomHelperMock->expects($this->at(0))
309
+                ->method('generate')
310
+                ->with(23)
311
+                ->willReturn($uniqueTrackingIdentifier);
312
+
313
+            $this->entityManagerMock->expects($this->at(0))
314
+                ->method('persist')
315
+                ->with($leadDeviceMock);
316
+
317
+            // index 0-3 for leadDeviceRepository::findOneBy
318
+            $leadDeviceMock->expects($this->at(4))
319
+                ->method('getTrackingId')
320
+                ->willReturn(null);
321
+            $leadDeviceMock->expects($this->at(5))
322
+                ->method('setTrackingId')
323
+                ->with($uniqueTrackingIdentifier)
324
+                ->willReturn($leadDeviceMock);
325
+            $leadDeviceMock->expects($this->at(6))
326
+                ->method('getTrackingId')
327
+                ->willReturn($uniqueTrackingIdentifier);
328
+            $leadDeviceMock->expects($this->exactly(2))
329
+                ->method('getLead')
330
+                ->willReturn(new Lead());
331
+            $this->cookieHelperMock->expects($this->at(1))
332
+                ->method('setCookie')
333
+                ->with('mautic_device_id', $uniqueTrackingIdentifier, 31536000);
334
+
335
+            $deviceTrackingService = $this->getDeviceTrackingService();
336
+            $returnedLeadDevice    = $deviceTrackingService->trackCurrentDevice($leadDeviceMock, true);
337
+            $this->assertInstanceOf(LeadDevice::class, $returnedLeadDevice);
338
+        }
339
+
340
+        /**
341 341
      * Test tracking device without already tracked current device.
342 342
      */
343
-    public function testTrackCurrentDeviceNotTrackedYet()
344
-    {
345
-        // Parameters
346
-        $leadDeviceMock           = $this->createMock(LeadDevice::class);
347
-        $uniqueTrackingIdentifier = '1234567890abcdefghij123';
348
-
349
-        // __construct()
350
-        $requestMock = $this->createMock(Request::class);
351
-        $this->requestStackMock->expects($this->at(0))
352
-            ->method('getCurrentRequest')
353
-            ->willReturn($requestMock);
354
-
355
-        // getTrackedDevice()
356
-        $this->cookieHelperMock->expects($this->at(0))
357
-            ->method('getCookie')
358
-            ->with('mautic_device_id', null)
359
-            ->willReturn(null);
360
-
361
-        $requestMock->expects($this->at(0))
362
-            ->method('get')
363
-            ->with('mautic_device_id', null)
364
-            ->willReturn(null);
365
-
366
-        $leadDeviceMock->expects($this->at(0))
367
-            ->method('getTrackingId')
368
-            ->willReturn(null);
369
-
370
-        // getUniqueTrackingIdentifier()
371
-        $this->randomHelperMock->expects($this->at(0))
372
-            ->method('generate')
373
-            ->with(23)
374
-            ->willReturn($uniqueTrackingIdentifier);
375
-
376
-        $this->security->expects($this->once())
377
-            ->method('isAnonymous')
378
-            ->willReturn(true);
379
-
380
-        // index 0-3 for leadDeviceRepository::findOneBy
381
-        $leadDeviceMock->expects($this->at(4))
382
-            ->method('getTrackingId')
383
-            ->willReturn(null);
384
-        $leadDeviceMock->expects($this->at(5))
385
-            ->method('setTrackingId')
386
-            ->with($uniqueTrackingIdentifier)
387
-            ->willReturn($leadDeviceMock);
388
-        $leadDeviceMock->expects($this->at(6))
389
-            ->method('getTrackingId')
390
-            ->willReturn($uniqueTrackingIdentifier);
391
-        $leadDeviceMock->expects($this->exactly(2))
392
-            ->method('getLead')
393
-            ->willReturn(new Lead());
394
-
395
-        $this->cookieHelperMock->expects($this->at(1))
396
-            ->method('setCookie')
397
-            ->with('mautic_device_id', $uniqueTrackingIdentifier, 31536000);
398
-
399
-        $deviceTrackingService = $this->getDeviceTrackingService();
400
-        $returnedLeadDevice    = $deviceTrackingService->trackCurrentDevice($leadDeviceMock, false);
401
-        $this->assertInstanceOf(LeadDevice::class, $returnedLeadDevice);
402
-    }
403
-
404
-    /**
343
+        public function testTrackCurrentDeviceNotTrackedYet()
344
+        {
345
+            // Parameters
346
+            $leadDeviceMock           = $this->createMock(LeadDevice::class);
347
+            $uniqueTrackingIdentifier = '1234567890abcdefghij123';
348
+
349
+            // __construct()
350
+            $requestMock = $this->createMock(Request::class);
351
+            $this->requestStackMock->expects($this->at(0))
352
+                ->method('getCurrentRequest')
353
+                ->willReturn($requestMock);
354
+
355
+            // getTrackedDevice()
356
+            $this->cookieHelperMock->expects($this->at(0))
357
+                ->method('getCookie')
358
+                ->with('mautic_device_id', null)
359
+                ->willReturn(null);
360
+
361
+            $requestMock->expects($this->at(0))
362
+                ->method('get')
363
+                ->with('mautic_device_id', null)
364
+                ->willReturn(null);
365
+
366
+            $leadDeviceMock->expects($this->at(0))
367
+                ->method('getTrackingId')
368
+                ->willReturn(null);
369
+
370
+            // getUniqueTrackingIdentifier()
371
+            $this->randomHelperMock->expects($this->at(0))
372
+                ->method('generate')
373
+                ->with(23)
374
+                ->willReturn($uniqueTrackingIdentifier);
375
+
376
+            $this->security->expects($this->once())
377
+                ->method('isAnonymous')
378
+                ->willReturn(true);
379
+
380
+            // index 0-3 for leadDeviceRepository::findOneBy
381
+            $leadDeviceMock->expects($this->at(4))
382
+                ->method('getTrackingId')
383
+                ->willReturn(null);
384
+            $leadDeviceMock->expects($this->at(5))
385
+                ->method('setTrackingId')
386
+                ->with($uniqueTrackingIdentifier)
387
+                ->willReturn($leadDeviceMock);
388
+            $leadDeviceMock->expects($this->at(6))
389
+                ->method('getTrackingId')
390
+                ->willReturn($uniqueTrackingIdentifier);
391
+            $leadDeviceMock->expects($this->exactly(2))
392
+                ->method('getLead')
393
+                ->willReturn(new Lead());
394
+
395
+            $this->cookieHelperMock->expects($this->at(1))
396
+                ->method('setCookie')
397
+                ->with('mautic_device_id', $uniqueTrackingIdentifier, 31536000);
398
+
399
+            $deviceTrackingService = $this->getDeviceTrackingService();
400
+            $returnedLeadDevice    = $deviceTrackingService->trackCurrentDevice($leadDeviceMock, false);
401
+            $this->assertInstanceOf(LeadDevice::class, $returnedLeadDevice);
402
+        }
403
+
404
+        /**
405 405
      * Test that a user is not tracked.
406 406
      */
407
-    public function testUserIsNotTracked()
408
-    {
409
-        $this->leadDeviceRepositoryMock->expects($this->never())
410
-            ->method('getByTrackingId');
407
+        public function testUserIsNotTracked()
408
+        {
409
+            $this->leadDeviceRepositoryMock->expects($this->never())
410
+                ->method('getByTrackingId');
411 411
 
412
-        $requestMock = $this->createMock(Request::class);
413
-        $this->requestStackMock->expects($this->at(0))
414
-            ->method('getCurrentRequest')
415
-            ->willReturn($requestMock);
412
+            $requestMock = $this->createMock(Request::class);
413
+            $this->requestStackMock->expects($this->at(0))
414
+                ->method('getCurrentRequest')
415
+                ->willReturn($requestMock);
416 416
 
417
-        $this->security->expects($this->once())
418
-            ->method('isAnonymous')
419
-            ->willReturn(false);
417
+            $this->security->expects($this->once())
418
+                ->method('isAnonymous')
419
+                ->willReturn(false);
420 420
 
421
-        $this->getDeviceTrackingService()->getTrackedDevice();
422
-    }
421
+            $this->getDeviceTrackingService()->getTrackedDevice();
422
+        }
423 423
 
424
-    /**
424
+        /**
425 425
      * @return DeviceTrackingService
426 426
      */
427
-    private function getDeviceTrackingService()
428
-    {
429
-        return new DeviceTrackingService(
430
-            $this->cookieHelperMock,
431
-            $this->entityManagerMock,
432
-            $this->leadDeviceRepositoryMock,
433
-            $this->randomHelperMock,
434
-            $this->requestStackMock,
435
-            $this->security
436
-        );
437
-    }
427
+        private function getDeviceTrackingService()
428
+        {
429
+            return new DeviceTrackingService(
430
+                $this->cookieHelperMock,
431
+                $this->entityManagerMock,
432
+                $this->leadDeviceRepositoryMock,
433
+                $this->randomHelperMock,
434
+                $this->requestStackMock,
435
+                $this->security
436
+            );
437
+        }
438 438
 }
Please login to merge, or discard this patch.
app/bundles/LeadBundle/Tests/Tracker/DeviceTrackerTest.php 1 patch
Switch Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php
1
+    <?php
2 2
 
3 3
 /*
4 4
  * @copyright   2017 Mautic Contributors. All rights reserved
@@ -9,77 +9,77 @@  discard block
 block discarded – undo
9 9
  * @license     GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
10 10
  */
11 11
 
12
-namespace Mautic\LeadBundle\Tests\Tracker;
12
+    namespace Mautic\LeadBundle\Tests\Tracker;
13 13
 
14
-use Mautic\LeadBundle\Entity\Lead;
15
-use Mautic\LeadBundle\Entity\LeadDevice;
16
-use Mautic\LeadBundle\Tracker\DeviceTracker;
17
-use Mautic\LeadBundle\Tracker\Factory\DeviceDetectorFactory\DeviceDetectorFactory;
18
-use Mautic\LeadBundle\Tracker\Service\DeviceCreatorService\DeviceCreatorService;
19
-use Mautic\LeadBundle\Tracker\Service\DeviceTrackingService\DeviceTrackingServiceInterface;
20
-use Monolog\Logger;
14
+    use Mautic\LeadBundle\Entity\Lead;
15
+    use Mautic\LeadBundle\Entity\LeadDevice;
16
+    use Mautic\LeadBundle\Tracker\DeviceTracker;
17
+    use Mautic\LeadBundle\Tracker\Factory\DeviceDetectorFactory\DeviceDetectorFactory;
18
+    use Mautic\LeadBundle\Tracker\Service\DeviceCreatorService\DeviceCreatorService;
19
+    use Mautic\LeadBundle\Tracker\Service\DeviceTrackingService\DeviceTrackingServiceInterface;
20
+    use Monolog\Logger;
21 21
 
22
-class DeviceTrackerTest extends \PHPUnit\Framework\TestCase
23
-{
24
-    /**
22
+    class DeviceTrackerTest extends \PHPUnit\Framework\TestCase
23
+    {
24
+        /**
25 25
      * @var DeviceCreatorService
26 26
      */
27
-    private $deviceCreatorService;
27
+        private $deviceCreatorService;
28 28
 
29
-    /**
29
+        /**
30 30
      * @var DeviceDetectorFactory
31 31
      */
32
-    private $deviceDetectorFactory;
32
+        private $deviceDetectorFactory;
33 33
 
34
-    /**
34
+        /**
35 35
      * @var DeviceTrackingServiceInterface
36 36
      */
37
-    private $deviceTrackingService;
37
+        private $deviceTrackingService;
38 38
 
39
-    /**
39
+        /**
40 40
      * @var Logger
41 41
      */
42
-    private $logger;
42
+        private $logger;
43 43
 
44
-    /**
44
+        /**
45 45
      * @var string
46 46
      */
47
-    private $userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36';
47
+        private $userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36';
48 48
 
49
-    protected function setUp(): void
50
-    {
51
-        $this->deviceCreatorService = new DeviceCreatorService();
49
+        protected function setUp(): void
50
+        {
51
+            $this->deviceCreatorService = new DeviceCreatorService();
52 52
 
53
-        $this->deviceDetectorFactory = new DeviceDetectorFactory();
53
+            $this->deviceDetectorFactory = new DeviceDetectorFactory();
54 54
 
55
-        $this->deviceTrackingService = $this->getMockBuilder(DeviceTrackingServiceInterface::class)
56
-            ->disableOriginalConstructor()
57
-            ->getMock();
55
+            $this->deviceTrackingService = $this->getMockBuilder(DeviceTrackingServiceInterface::class)
56
+                ->disableOriginalConstructor()
57
+                ->getMock();
58 58
 
59
-        $this->logger = $this->getMockBuilder(Logger::class)
60
-            ->disableOriginalConstructor()
61
-            ->getMock();
62
-    }
59
+            $this->logger = $this->getMockBuilder(Logger::class)
60
+                ->disableOriginalConstructor()
61
+                ->getMock();
62
+        }
63 63
 
64
-    public function testDeviceCreatedByUserAgent()
65
-    {
66
-        $lead    = new Lead();
67
-        $device  = new LeadDevice();
68
-        $device->setDeviceBrand('apple');
64
+        public function testDeviceCreatedByUserAgent()
65
+        {
66
+            $lead    = new Lead();
67
+            $device  = new LeadDevice();
68
+            $device->setDeviceBrand('apple');
69 69
 
70
-        $this->deviceTrackingService->expects($this->once())
71
-            ->method('trackCurrentDevice')
72
-            ->willReturn($device);
70
+            $this->deviceTrackingService->expects($this->once())
71
+                ->method('trackCurrentDevice')
72
+                ->willReturn($device);
73 73
 
74
-        $tracker = new DeviceTracker($this->deviceCreatorService, $this->deviceDetectorFactory, $this->deviceTrackingService, $this->logger);
74
+            $tracker = new DeviceTracker($this->deviceCreatorService, $this->deviceDetectorFactory, $this->deviceTrackingService, $this->logger);
75 75
 
76
-        $device = $tracker->createDeviceFromUserAgent($lead, $this->userAgent);
77
-        $this->assertEquals('3dfc9e6dff07948058df37455718cb98', $device->getSignature());
76
+            $device = $tracker->createDeviceFromUserAgent($lead, $this->userAgent);
77
+            $this->assertEquals('3dfc9e6dff07948058df37455718cb98', $device->getSignature());
78 78
 
79
-        // Subsequent calls should not create a new tracking ID
80
-        $device2 = $tracker->createDeviceFromUserAgent($lead, $this->userAgent);
81
-        $this->assertEquals($device->getTrackingId(), $device2->getTrackingId());
82
-        $this->assertEquals('apple', $device2->getDeviceBrand());
83
-        $this->assertEquals($device->getSignature(), $device2->getSignature());
84
-    }
79
+            // Subsequent calls should not create a new tracking ID
80
+            $device2 = $tracker->createDeviceFromUserAgent($lead, $this->userAgent);
81
+            $this->assertEquals($device->getTrackingId(), $device2->getTrackingId());
82
+            $this->assertEquals('apple', $device2->getDeviceBrand());
83
+            $this->assertEquals($device->getSignature(), $device2->getSignature());
84
+        }
85 85
 }
Please login to merge, or discard this patch.
app/bundles/LeadBundle/Tests/Tracker/ContactTrackerTest.php 1 patch
Switch Indentation   +238 added lines, -238 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php
1
+    <?php
2 2
 
3 3
 /*
4 4
  * @copyright   2017 Mautic Contributors. All rights reserved
@@ -9,309 +9,309 @@  discard block
 block discarded – undo
9 9
  * @license     GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
10 10
  */
11 11
 
12
-namespace Mautic\LeadBundle\Tests\Tracker;
13
-
14
-use Mautic\CoreBundle\Entity\IpAddress;
15
-use Mautic\CoreBundle\Helper\CoreParametersHelper;
16
-use Mautic\CoreBundle\Helper\IpLookupHelper;
17
-use Mautic\CoreBundle\Security\Permissions\CorePermissions;
18
-use Mautic\LeadBundle\Entity\Lead;
19
-use Mautic\LeadBundle\Entity\LeadDevice;
20
-use Mautic\LeadBundle\Entity\LeadRepository;
21
-use Mautic\LeadBundle\LeadEvents;
22
-use Mautic\LeadBundle\Model\FieldModel;
23
-use Mautic\LeadBundle\Tracker\ContactTracker;
24
-use Mautic\LeadBundle\Tracker\DeviceTracker;
25
-use Mautic\LeadBundle\Tracker\Service\ContactTrackingService\ContactTrackingServiceInterface;
26
-use Monolog\Logger;
27
-use Symfony\Component\EventDispatcher\EventDispatcher;
28
-use Symfony\Component\HttpFoundation\Request;
29
-use Symfony\Component\HttpFoundation\RequestStack;
30
-
31
-class ContactTrackerTest extends \PHPUnit\Framework\TestCase
32
-{
33
-    /**
12
+    namespace Mautic\LeadBundle\Tests\Tracker;
13
+
14
+    use Mautic\CoreBundle\Entity\IpAddress;
15
+    use Mautic\CoreBundle\Helper\CoreParametersHelper;
16
+    use Mautic\CoreBundle\Helper\IpLookupHelper;
17
+    use Mautic\CoreBundle\Security\Permissions\CorePermissions;
18
+    use Mautic\LeadBundle\Entity\Lead;
19
+    use Mautic\LeadBundle\Entity\LeadDevice;
20
+    use Mautic\LeadBundle\Entity\LeadRepository;
21
+    use Mautic\LeadBundle\LeadEvents;
22
+    use Mautic\LeadBundle\Model\FieldModel;
23
+    use Mautic\LeadBundle\Tracker\ContactTracker;
24
+    use Mautic\LeadBundle\Tracker\DeviceTracker;
25
+    use Mautic\LeadBundle\Tracker\Service\ContactTrackingService\ContactTrackingServiceInterface;
26
+    use Monolog\Logger;
27
+    use Symfony\Component\EventDispatcher\EventDispatcher;
28
+    use Symfony\Component\HttpFoundation\Request;
29
+    use Symfony\Component\HttpFoundation\RequestStack;
30
+
31
+    class ContactTrackerTest extends \PHPUnit\Framework\TestCase
32
+    {
33
+        /**
34 34
      * @var LeadRepository
35 35
      */
36
-    private $leadRepositoryMock;
36
+        private $leadRepositoryMock;
37 37
 
38
-    /**
38
+        /**
39 39
      * @var ContactTrackingServiceInterface
40 40
      */
41
-    private $contactTrackingServiceMock;
41
+        private $contactTrackingServiceMock;
42 42
 
43
-    /**
43
+        /**
44 44
      * @var DeviceTracker
45 45
      */
46
-    private $deviceTrackerMock;
46
+        private $deviceTrackerMock;
47 47
 
48
-    /**
48
+        /**
49 49
      * @var CorePermissions
50 50
      */
51
-    private $securityMock;
51
+        private $securityMock;
52 52
 
53
-    /**
53
+        /**
54 54
      * @var Logger
55 55
      */
56
-    private $loggerMock;
56
+        private $loggerMock;
57 57
 
58
-    /**
58
+        /**
59 59
      * @var IpLookupHelper
60 60
      */
61
-    private $ipLookupHelperMock;
61
+        private $ipLookupHelperMock;
62 62
 
63
-    /**
63
+        /**
64 64
      * @var RequestStack
65 65
      */
66
-    private $requestStack;
66
+        private $requestStack;
67 67
 
68
-    /**
68
+        /**
69 69
      * @var CoreParametersHelper
70 70
      */
71
-    private $coreParametersHelperMock;
71
+        private $coreParametersHelperMock;
72 72
 
73
-    /**
73
+        /**
74 74
      * @var EventDispatcher
75 75
      */
76
-    private $dispatcherMock;
76
+        private $dispatcherMock;
77 77
 
78
-    /**
78
+        /**
79 79
      * @var FieldModel
80 80
      */
81
-    private $leadFieldModelMock;
81
+        private $leadFieldModelMock;
82
+
83
+        protected function setUp(): void
84
+        {
85
+            $this->leadRepositoryMock = $this->getMockBuilder(LeadRepository::class)
86
+                ->disableOriginalConstructor()
87
+                ->getMock();
88
+
89
+            $this->contactTrackingServiceMock = $this->getMockBuilder(ContactTrackingServiceInterface::class)
90
+                ->disableOriginalConstructor()
91
+                ->getMock();
92
+
93
+            $this->deviceTrackerMock = $this->getMockBuilder(DeviceTracker::class)
94
+                ->disableOriginalConstructor()
95
+                ->getMock();
96
+
97
+            $this->securityMock = $this->getMockBuilder(CorePermissions::class)
98
+                ->disableOriginalConstructor()
99
+                ->getMock();
100
+            $this->securityMock->method('isAnonymous')
101
+                ->willReturn(true);
102
+
103
+            $this->loggerMock = $this->getMockBuilder(Logger::class)
104
+                ->disableOriginalConstructor()
105
+                ->getMock();
106
+
107
+            $this->ipLookupHelperMock = $this->getMockBuilder(IpLookupHelper::class)
108
+                ->disableOriginalConstructor()
109
+                ->getMock();
110
+
111
+            $this->requestStack = new RequestStack();
112
+            $request            = new Request();
113
+            $this->requestStack->push($request);
114
+
115
+            $this->coreParametersHelperMock = $this->getMockBuilder(CoreParametersHelper::class)
116
+                ->disableOriginalConstructor()
117
+                ->getMock();
118
+
119
+            $this->dispatcherMock = $this->getMockBuilder(EventDispatcher::class)
120
+                ->disableOriginalConstructor()
121
+                ->getMock();
122
+
123
+            $this->leadFieldModelMock = $this->createMock(FieldModel::class);
124
+        }
125
+
126
+        public function testSystemContactIsUsedOverTrackedContact()
127
+        {
128
+            $contactTracker = $this->getContactTracker();
129
+
130
+            $this->leadRepositoryMock->expects($this->any())
131
+                ->method('getFieldValues')
132
+                ->willReturn([]);
133
+
134
+            $lead1 = new Lead();
135
+            $lead1->setEmail('[email protected]');
136
+            $contactTracker->setTrackedContact($lead1);
137
+            $this->assertEquals($lead1->getEmail(), $contactTracker->getContact()->getEmail());
138
+
139
+            $lead2 = new Lead();
140
+            $lead1->setEmail('[email protected]');
141
+            $contactTracker->setSystemContact($lead2);
142
+            $this->assertEquals($lead2->getEmail(), $contactTracker->getContact()->getEmail());
143
+        }
144
+
145
+        public function testContactIsTrackedByDevice()
146
+        {
147
+            $contactTracker = $this->getContactTracker();
148
+
149
+            $this->leadRepositoryMock->expects($this->once())
150
+                ->method('getFieldValues')
151
+                ->willReturn(
152
+                    [
153
+                        'core' => [
154
+                            'email' => [
155
+                                'alias' => 'email',
156
+                                'type'  => 'email',
157
+                                'value' => '[email protected]',
158
+                            ],
159
+                        ],
160
+                    ]
161
+                );
82 162
 
83
-    protected function setUp(): void
84
-    {
85
-        $this->leadRepositoryMock = $this->getMockBuilder(LeadRepository::class)
86
-            ->disableOriginalConstructor()
87
-            ->getMock();
163
+            $device = new LeadDevice();
164
+            $lead   = new Lead();
165
+            $device->setLead($lead);
88 166
 
89
-        $this->contactTrackingServiceMock = $this->getMockBuilder(ContactTrackingServiceInterface::class)
90
-            ->disableOriginalConstructor()
91
-            ->getMock();
167
+            $this->deviceTrackerMock->method('getTrackedDevice')
168
+                ->willReturn($device);
92 169
 
93
-        $this->deviceTrackerMock = $this->getMockBuilder(DeviceTracker::class)
94
-            ->disableOriginalConstructor()
95
-            ->getMock();
170
+            $contact = $contactTracker->getContact();
96 171
 
97
-        $this->securityMock = $this->getMockBuilder(CorePermissions::class)
98
-            ->disableOriginalConstructor()
99
-            ->getMock();
100
-        $this->securityMock->method('isAnonymous')
101
-            ->willReturn(true);
172
+            $this->assertEquals('[email protected]', $contact->getFieldValue('email'));
173
+        }
102 174
 
103
-        $this->loggerMock = $this->getMockBuilder(Logger::class)
104
-            ->disableOriginalConstructor()
105
-            ->getMock();
175
+        public function testContactIsTrackedByOldCookie()
176
+        {
177
+            $contactTracker = $this->getContactTracker();
106 178
 
107
-        $this->ipLookupHelperMock = $this->getMockBuilder(IpLookupHelper::class)
108
-            ->disableOriginalConstructor()
109
-            ->getMock();
179
+            $this->leadRepositoryMock->expects($this->never())
180
+                ->method('getFieldValues');
110 181
 
111
-        $this->requestStack = new RequestStack();
112
-        $request            = new Request();
113
-        $this->requestStack->push($request);
182
+            $lead = new Lead();
183
+            $lead->setEmail('[email protected]');
114 184
 
115
-        $this->coreParametersHelperMock = $this->getMockBuilder(CoreParametersHelper::class)
116
-            ->disableOriginalConstructor()
117
-            ->getMock();
185
+            $this->contactTrackingServiceMock->expects($this->once())
186
+                ->method('getTrackedLead')
187
+                ->willReturn($lead);
118 188
 
119
-        $this->dispatcherMock = $this->getMockBuilder(EventDispatcher::class)
120
-            ->disableOriginalConstructor()
121
-            ->getMock();
189
+            $contact = $contactTracker->getContact();
122 190
 
123
-        $this->leadFieldModelMock = $this->createMock(FieldModel::class);
124
-    }
191
+            $this->assertEquals('[email protected]', $contact->getEmail());
192
+        }
125 193
 
126
-    public function testSystemContactIsUsedOverTrackedContact()
127
-    {
128
-        $contactTracker = $this->getContactTracker();
194
+        public function testContactIsTrackedByIp()
195
+        {
196
+            $contactTracker = $this->getContactTracker();
129 197
 
130
-        $this->leadRepositoryMock->expects($this->any())
131
-            ->method('getFieldValues')
132
-            ->willReturn([]);
198
+            $this->ipLookupHelperMock->expects($this->exactly(2))
199
+                ->method('getIpAddress')
200
+                ->willReturn(new IpAddress());
133 201
 
134
-        $lead1 = new Lead();
135
-        $lead1->setEmail('[email protected]');
136
-        $contactTracker->setTrackedContact($lead1);
137
-        $this->assertEquals($lead1->getEmail(), $contactTracker->getContact()->getEmail());
202
+            $this->leadRepositoryMock->expects($this->never())
203
+                ->method('getFieldValues');
138 204
 
139
-        $lead2 = new Lead();
140
-        $lead1->setEmail('[email protected]');
141
-        $contactTracker->setSystemContact($lead2);
142
-        $this->assertEquals($lead2->getEmail(), $contactTracker->getContact()->getEmail());
143
-    }
205
+            $lead = new Lead();
206
+            $lead->setEmail('[email protected]');
144 207
 
145
-    public function testContactIsTrackedByDevice()
146
-    {
147
-        $contactTracker = $this->getContactTracker();
148
-
149
-        $this->leadRepositoryMock->expects($this->once())
150
-            ->method('getFieldValues')
151
-            ->willReturn(
152
-                [
153
-                    'core' => [
154
-                        'email' => [
155
-                            'alias' => 'email',
156
-                            'type'  => 'email',
157
-                            'value' => '[email protected]',
158
-                        ],
159
-                    ],
160
-                ]
161
-            );
208
+            $this->contactTrackingServiceMock->expects($this->once())
209
+                ->method('getTrackedLead')
210
+                ->willReturn(null);
162 211
 
163
-        $device = new LeadDevice();
164
-        $lead   = new Lead();
165
-        $device->setLead($lead);
212
+            $this->coreParametersHelperMock->expects($this->any())
213
+                ->method('get')
214
+                ->willReturn(true);
166 215
 
167
-        $this->deviceTrackerMock->method('getTrackedDevice')
168
-            ->willReturn($device);
216
+            $this->leadRepositoryMock->expects($this->once())
217
+                ->method('getLeadsByIp')
218
+                ->willReturn([$lead]);
169 219
 
170
-        $contact = $contactTracker->getContact();
220
+            $contact = $contactTracker->getContact();
171 221
 
172
-        $this->assertEquals('[email protected]', $contact->getFieldValue('email'));
173
-    }
222
+            $this->assertEquals('[email protected]', $contact->getEmail());
223
+        }
174 224
 
175
-    public function testContactIsTrackedByOldCookie()
176
-    {
177
-        $contactTracker = $this->getContactTracker();
225
+        public function testNewContactIsCreated()
226
+        {
227
+            $contactTracker = $this->getContactTracker();
178 228
 
179
-        $this->leadRepositoryMock->expects($this->never())
180
-            ->method('getFieldValues');
229
+            $this->leadRepositoryMock->expects($this->once())
230
+                ->method('getFieldValues')
231
+                ->willReturn([]);
181 232
 
182
-        $lead = new Lead();
183
-        $lead->setEmail('[email protected]');
233
+            $this->ipLookupHelperMock->expects($this->exactly(2))
234
+                ->method('getIpAddress')
235
+                ->willReturn(new IpAddress());
184 236
 
185
-        $this->contactTrackingServiceMock->expects($this->once())
186
-            ->method('getTrackedLead')
187
-            ->willReturn($lead);
237
+            $this->leadRepositoryMock->expects($this->once())
238
+                ->method('getFieldValues');
188 239
 
189
-        $contact = $contactTracker->getContact();
240
+            $this->contactTrackingServiceMock->expects($this->once())
241
+                ->method('getTrackedLead')
242
+                ->willReturn(null);
190 243
 
191
-        $this->assertEquals('[email protected]', $contact->getEmail());
192
-    }
244
+            $this->coreParametersHelperMock->expects($this->once())
245
+                ->method('get')
246
+                ->willReturn(false);
193 247
 
194
-    public function testContactIsTrackedByIp()
195
-    {
196
-        $contactTracker = $this->getContactTracker();
248
+            $this->leadRepositoryMock->expects($this->never())
249
+                ->method('getLeadsByIp');
250
+            $this->leadFieldModelMock->expects($this->any())->method('getFieldListWithProperties')->willReturn([]);
197 251
 
198
-        $this->ipLookupHelperMock->expects($this->exactly(2))
199
-            ->method('getIpAddress')
200
-            ->willReturn(new IpAddress());
252
+            $contact = $contactTracker->getContact();
253
+            $this->assertEquals(true, $contact->isNewlyCreated());
254
+        }
201 255
 
202
-        $this->leadRepositoryMock->expects($this->never())
203
-            ->method('getFieldValues');
256
+        public function testEventIsDispatchedWithChangeOfContact()
257
+        {
258
+            $contactTracker = $this->getContactTracker();
204 259
 
205
-        $lead = new Lead();
206
-        $lead->setEmail('[email protected]');
260
+            $device = new LeadDevice();
261
+            $device->setTrackingId('abc123');
207 262
 
208
-        $this->contactTrackingServiceMock->expects($this->once())
209
-            ->method('getTrackedLead')
210
-            ->willReturn(null);
263
+            $lead = $this->getMockBuilder(Lead::class)
264
+                ->getMock();
265
+            $lead->method('getId')
266
+                ->willReturn(1);
211 267
 
212
-        $this->coreParametersHelperMock->expects($this->any())
213
-            ->method('get')
214
-            ->willReturn(true);
268
+            $lead2 = $this->getMockBuilder(Lead::class)
269
+                ->getMock();
270
+            $lead2->method('getId')
271
+                ->willReturn(2);
215 272
 
216
-        $this->leadRepositoryMock->expects($this->once())
217
-            ->method('getLeadsByIp')
218
-            ->willReturn([$lead]);
273
+            $this->dispatcherMock->expects($this->once())
274
+                ->method('hasListeners')
275
+                ->withConsecutive([LeadEvents::CURRENT_LEAD_CHANGED])
276
+                ->willReturn(true);
219 277
 
220
-        $contact = $contactTracker->getContact();
278
+            $this->dispatcherMock->expects($this->once())
279
+                ->method('dispatch')
280
+                ->withConsecutive([LeadEvents::CURRENT_LEAD_CHANGED, $this->anything()])
281
+                ->willReturn(true);
221 282
 
222
-        $this->assertEquals('[email protected]', $contact->getEmail());
223
-    }
283
+            $leadDevice1 = new LeadDevice();
284
+            $leadDevice1->setTrackingId('abc123');
285
+            $this->deviceTrackerMock->expects($this->at(0))
286
+                ->method('getTrackedDevice')
287
+                ->willReturn($leadDevice1);
224 288
 
225
-    public function testNewContactIsCreated()
226
-    {
227
-        $contactTracker = $this->getContactTracker();
289
+            $leadDevice2 = new LeadDevice();
290
+            $leadDevice2->setTrackingId('def456');
291
+            $this->deviceTrackerMock->expects($this->at(2))
292
+                ->method('getTrackedDevice')
293
+                ->willReturn($leadDevice2);
228 294
 
229
-        $this->leadRepositoryMock->expects($this->once())
230
-            ->method('getFieldValues')
231
-            ->willReturn([]);
295
+            $contactTracker->setTrackedContact($lead);
296
+            $contactTracker->setTrackedContact($lead2);
297
+        }
232 298
 
233
-        $this->ipLookupHelperMock->expects($this->exactly(2))
234
-            ->method('getIpAddress')
235
-            ->willReturn(new IpAddress());
236
-
237
-        $this->leadRepositoryMock->expects($this->once())
238
-            ->method('getFieldValues');
239
-
240
-        $this->contactTrackingServiceMock->expects($this->once())
241
-            ->method('getTrackedLead')
242
-            ->willReturn(null);
243
-
244
-        $this->coreParametersHelperMock->expects($this->once())
245
-            ->method('get')
246
-            ->willReturn(false);
247
-
248
-        $this->leadRepositoryMock->expects($this->never())
249
-            ->method('getLeadsByIp');
250
-        $this->leadFieldModelMock->expects($this->any())->method('getFieldListWithProperties')->willReturn([]);
251
-
252
-        $contact = $contactTracker->getContact();
253
-        $this->assertEquals(true, $contact->isNewlyCreated());
254
-    }
255
-
256
-    public function testEventIsDispatchedWithChangeOfContact()
257
-    {
258
-        $contactTracker = $this->getContactTracker();
259
-
260
-        $device = new LeadDevice();
261
-        $device->setTrackingId('abc123');
262
-
263
-        $lead = $this->getMockBuilder(Lead::class)
264
-            ->getMock();
265
-        $lead->method('getId')
266
-            ->willReturn(1);
267
-
268
-        $lead2 = $this->getMockBuilder(Lead::class)
269
-            ->getMock();
270
-        $lead2->method('getId')
271
-            ->willReturn(2);
272
-
273
-        $this->dispatcherMock->expects($this->once())
274
-            ->method('hasListeners')
275
-            ->withConsecutive([LeadEvents::CURRENT_LEAD_CHANGED])
276
-            ->willReturn(true);
277
-
278
-        $this->dispatcherMock->expects($this->once())
279
-            ->method('dispatch')
280
-            ->withConsecutive([LeadEvents::CURRENT_LEAD_CHANGED, $this->anything()])
281
-            ->willReturn(true);
282
-
283
-        $leadDevice1 = new LeadDevice();
284
-        $leadDevice1->setTrackingId('abc123');
285
-        $this->deviceTrackerMock->expects($this->at(0))
286
-            ->method('getTrackedDevice')
287
-            ->willReturn($leadDevice1);
288
-
289
-        $leadDevice2 = new LeadDevice();
290
-        $leadDevice2->setTrackingId('def456');
291
-        $this->deviceTrackerMock->expects($this->at(2))
292
-            ->method('getTrackedDevice')
293
-            ->willReturn($leadDevice2);
294
-
295
-        $contactTracker->setTrackedContact($lead);
296
-        $contactTracker->setTrackedContact($lead2);
297
-    }
298
-
299
-    /**
299
+        /**
300 300
      * @return ContactTracker
301 301
      */
302
-    private function getContactTracker()
303
-    {
304
-        return new ContactTracker(
305
-            $this->leadRepositoryMock,
306
-            $this->contactTrackingServiceMock,
307
-            $this->deviceTrackerMock,
308
-            $this->securityMock,
309
-            $this->loggerMock,
310
-            $this->ipLookupHelperMock,
311
-            $this->requestStack,
312
-            $this->coreParametersHelperMock,
313
-            $this->dispatcherMock,
314
-            $this->leadFieldModelMock
315
-        );
316
-    }
302
+        private function getContactTracker()
303
+        {
304
+            return new ContactTracker(
305
+                $this->leadRepositoryMock,
306
+                $this->contactTrackingServiceMock,
307
+                $this->deviceTrackerMock,
308
+                $this->securityMock,
309
+                $this->loggerMock,
310
+                $this->ipLookupHelperMock,
311
+                $this->requestStack,
312
+                $this->coreParametersHelperMock,
313
+                $this->dispatcherMock,
314
+                $this->leadFieldModelMock
315
+            );
316
+        }
317 317
 }
Please login to merge, or discard this patch.
Tests/Form/Validator/Constraints/FieldAliasKeywordValidatorTest.php 1 patch
Switch Indentation   +121 added lines, -121 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php
1
+    <?php
2 2
 
3 3
 /*
4 4
  * @copyright   2018 Mautic Contributors. All rights reserved
@@ -9,152 +9,152 @@  discard block
 block discarded – undo
9 9
  * @license     GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
10 10
  */
11 11
 
12
-namespace Mautic\LeadBundle\Tests\Form\Validator\Constraints;
13
-
14
-use Doctrine\ORM\EntityManager;
15
-use Doctrine\ORM\UnitOfWork;
16
-use Mautic\LeadBundle\Entity\LeadField;
17
-use Mautic\LeadBundle\Form\Validator\Constraints\FieldAliasKeyword;
18
-use Mautic\LeadBundle\Form\Validator\Constraints\FieldAliasKeywordValidator;
19
-use Mautic\LeadBundle\Helper\FieldAliasHelper;
20
-use Mautic\LeadBundle\Model\ListModel;
21
-use Symfony\Component\Validator\Context\ExecutionContextInterface;
22
-
23
-class FieldAliasKeywordValidatorTest extends \PHPUnit\Framework\TestCase
24
-{
25
-    private $listModelMock;
26
-    private $fieldAliasHelperlMock;
27
-    private $executionContextMock;
28
-    private $entityManagerMock;
29
-    private $unitOfWorkMock;
30
-    private $validator;
31
-
32
-    protected function setUp(): void
12
+    namespace Mautic\LeadBundle\Tests\Form\Validator\Constraints;
13
+
14
+    use Doctrine\ORM\EntityManager;
15
+    use Doctrine\ORM\UnitOfWork;
16
+    use Mautic\LeadBundle\Entity\LeadField;
17
+    use Mautic\LeadBundle\Form\Validator\Constraints\FieldAliasKeyword;
18
+    use Mautic\LeadBundle\Form\Validator\Constraints\FieldAliasKeywordValidator;
19
+    use Mautic\LeadBundle\Helper\FieldAliasHelper;
20
+    use Mautic\LeadBundle\Model\ListModel;
21
+    use Symfony\Component\Validator\Context\ExecutionContextInterface;
22
+
23
+    class FieldAliasKeywordValidatorTest extends \PHPUnit\Framework\TestCase
33 24
     {
34
-        parent::setUp();
35
-
36
-        $this->fieldAliasHelperlMock = $this->createMock(FieldAliasHelper::class);
37
-        $this->listModelMock         = $this->createMock(ListModel::class);
38
-        $this->executionContextMock  = $this->createMock(ExecutionContextInterface::class);
39
-        $this->entityManagerMock     = $this->createMock(EntityManager::class);
40
-        $this->unitOfWorkMock        = $this->createMock(UnitOfWork::class);
41
-
42
-        $this->entityManagerMock
43
-            ->method('getUnitOfWork')
44
-            ->willReturn($this->unitOfWorkMock);
45
-
46
-        $this->listModelMock->method('getChoiceFields')
47
-            ->willReturn(
48
-                [
49
-                    'lead' => [
50
-                        'date_added' => [
51
-                            'label'      => 'mautic.core.date.added',
52
-                            'properties' => ['type' => 'date'],
53
-                            'operators'  => 'default',
54
-                            'object'     => 'lead',
25
+        private $listModelMock;
26
+        private $fieldAliasHelperlMock;
27
+        private $executionContextMock;
28
+        private $entityManagerMock;
29
+        private $unitOfWorkMock;
30
+        private $validator;
31
+
32
+        protected function setUp(): void
33
+        {
34
+            parent::setUp();
35
+
36
+            $this->fieldAliasHelperlMock = $this->createMock(FieldAliasHelper::class);
37
+            $this->listModelMock         = $this->createMock(ListModel::class);
38
+            $this->executionContextMock  = $this->createMock(ExecutionContextInterface::class);
39
+            $this->entityManagerMock     = $this->createMock(EntityManager::class);
40
+            $this->unitOfWorkMock        = $this->createMock(UnitOfWork::class);
41
+
42
+            $this->entityManagerMock
43
+                ->method('getUnitOfWork')
44
+                ->willReturn($this->unitOfWorkMock);
45
+
46
+            $this->listModelMock->method('getChoiceFields')
47
+                ->willReturn(
48
+                    [
49
+                        'lead' => [
50
+                            'date_added' => [
51
+                                'label'      => 'mautic.core.date.added',
52
+                                'properties' => ['type' => 'date'],
53
+                                'operators'  => 'default',
54
+                                'object'     => 'lead',
55
+                            ],
56
+                            'date_identified' => [
57
+                                'label'      => 'mautic.lead.list.filter.date_identified',
58
+                                'properties' => ['type' => 'date'],
59
+                                'operators'  => 'default',
60
+                                'object'     => 'lead',
61
+                            ],
55 62
                         ],
56
-                        'date_identified' => [
57
-                            'label'      => 'mautic.lead.list.filter.date_identified',
58
-                            'properties' => ['type' => 'date'],
59
-                            'operators'  => 'default',
60
-                            'object'     => 'lead',
61
-                        ],
62
-                    ],
63
-                ]
64
-            );
63
+                    ]
64
+                );
65 65
 
66
-        $this->validator = new FieldAliasKeywordValidator($this->listModelMock, $this->fieldAliasHelperlMock, $this->entityManagerMock);
67
-        $this->validator->initialize($this->executionContextMock);
68
-    }
66
+            $this->validator = new FieldAliasKeywordValidator($this->listModelMock, $this->fieldAliasHelperlMock, $this->entityManagerMock);
67
+            $this->validator->initialize($this->executionContextMock);
68
+        }
69 69
 
70
-    public function testAddValidationFailure()
71
-    {
72
-        $originalField = [];
70
+        public function testAddValidationFailure()
71
+        {
72
+            $originalField = [];
73 73
 
74
-        $this->unitOfWorkMock
75
-            ->method('getOriginalEntityData')
76
-            ->willReturn($originalField);
74
+            $this->unitOfWorkMock
75
+                ->method('getOriginalEntityData')
76
+                ->willReturn($originalField);
77 77
 
78
-        $field = new LeadField();
79
-        $field->setObject('lead');
80
-        $field->setAlias('date_added');
78
+            $field = new LeadField();
79
+            $field->setObject('lead');
80
+            $field->setAlias('date_added');
81 81
 
82
-        $this->executionContextMock->expects($this->once())->method('addViolation')->with('mautic.lead.field.keyword.invalid');
82
+            $this->executionContextMock->expects($this->once())->method('addViolation')->with('mautic.lead.field.keyword.invalid');
83 83
 
84
-        $this->validator->validate($field, new FieldAliasKeyword());
85
-    }
84
+            $this->validator->validate($field, new FieldAliasKeyword());
85
+        }
86 86
 
87
-    public function testAddValidationSuccess()
88
-    {
89
-        $originalField = [];
87
+        public function testAddValidationSuccess()
88
+        {
89
+            $originalField = [];
90 90
 
91
-        $this->unitOfWorkMock
92
-            ->method('getOriginalEntityData')
93
-            ->willReturn($originalField);
91
+            $this->unitOfWorkMock
92
+                ->method('getOriginalEntityData')
93
+                ->willReturn($originalField);
94 94
 
95
-        $field = new LeadField();
96
-        $field->setObject('lead');
97
-        $field->setAlias('not_keyword');
95
+            $field = new LeadField();
96
+            $field->setObject('lead');
97
+            $field->setAlias('not_keyword');
98 98
 
99
-        $this->executionContextMock->expects($this->never())->method('addViolation');
99
+            $this->executionContextMock->expects($this->never())->method('addViolation');
100 100
 
101
-        $this->validator->validate($field, new FieldAliasKeyword());
102
-    }
101
+            $this->validator->validate($field, new FieldAliasKeyword());
102
+        }
103 103
 
104
-    public function testEditValidationFailure()
105
-    {
106
-        $originalField = [
107
-            'alias' => 'old_alias',
108
-        ];
104
+        public function testEditValidationFailure()
105
+        {
106
+            $originalField = [
107
+                'alias' => 'old_alias',
108
+            ];
109 109
 
110
-        $this->unitOfWorkMock
111
-            ->method('getOriginalEntityData')
112
-            ->willReturn($originalField);
110
+            $this->unitOfWorkMock
111
+                ->method('getOriginalEntityData')
112
+                ->willReturn($originalField);
113 113
 
114
-        $field = new LeadField();
115
-        $field->setObject('lead');
116
-        $field->setAlias('date_added');
114
+            $field = new LeadField();
115
+            $field->setObject('lead');
116
+            $field->setAlias('date_added');
117 117
 
118
-        $this->executionContextMock->expects($this->once())->method('addViolation')->with('mautic.lead.field.keyword.invalid');
118
+            $this->executionContextMock->expects($this->once())->method('addViolation')->with('mautic.lead.field.keyword.invalid');
119 119
 
120
-        $this->validator->validate($field, new FieldAliasKeyword());
121
-    }
120
+            $this->validator->validate($field, new FieldAliasKeyword());
121
+        }
122 122
 
123
-    public function testEditValidationSuccess()
124
-    {
125
-        $originalField = [
126
-            'alias' => 'old_alias',
127
-        ];
123
+        public function testEditValidationSuccess()
124
+        {
125
+            $originalField = [
126
+                'alias' => 'old_alias',
127
+            ];
128 128
 
129
-        $this->unitOfWorkMock
130
-            ->method('getOriginalEntityData')
131
-            ->willReturn($originalField);
129
+            $this->unitOfWorkMock
130
+                ->method('getOriginalEntityData')
131
+                ->willReturn($originalField);
132 132
 
133
-        $field = new LeadField();
134
-        $field->setObject('lead');
135
-        $field->setAlias('not_keyword');
133
+            $field = new LeadField();
134
+            $field->setObject('lead');
135
+            $field->setAlias('not_keyword');
136 136
 
137
-        $this->executionContextMock->expects($this->never())->method('addViolation');
137
+            $this->executionContextMock->expects($this->never())->method('addViolation');
138 138
 
139
-        $this->validator->validate($field, new FieldAliasKeyword());
140
-    }
139
+            $this->validator->validate($field, new FieldAliasKeyword());
140
+        }
141 141
 
142
-    public function testEditWithoutChangesValidationSuccess()
143
-    {
144
-        $originalField = [
145
-            'alias' => 'date_added',
146
-        ];
142
+        public function testEditWithoutChangesValidationSuccess()
143
+        {
144
+            $originalField = [
145
+                'alias' => 'date_added',
146
+            ];
147 147
 
148
-        $this->unitOfWorkMock
149
-            ->method('getOriginalEntityData')
150
-            ->willReturn($originalField);
148
+            $this->unitOfWorkMock
149
+                ->method('getOriginalEntityData')
150
+                ->willReturn($originalField);
151 151
 
152
-        $field = new LeadField();
153
-        $field->setObject('lead');
154
-        $field->setAlias('date_added');
152
+            $field = new LeadField();
153
+            $field->setObject('lead');
154
+            $field->setAlias('date_added');
155 155
 
156
-        $this->executionContextMock->expects($this->never())->method('addViolation');
156
+            $this->executionContextMock->expects($this->never())->method('addViolation');
157 157
 
158
-        $this->validator->validate($field, new FieldAliasKeyword());
159
-    }
158
+            $this->validator->validate($field, new FieldAliasKeyword());
159
+        }
160 160
 }
Please login to merge, or discard this patch.
app/bundles/LeadBundle/Tests/StandardImportTestHelper.php 1 patch
Switch Indentation   +154 added lines, -154 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php
1
+    <?php
2 2
 
3 3
 /*
4 4
  * @copyright   2016 Mautic Contributors. All rights reserved
@@ -9,178 +9,178 @@  discard block
 block discarded – undo
9 9
  * @license     GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
10 10
  */
11 11
 
12
-namespace Mautic\LeadBundle\Tests;
13
-
14
-use Mautic\CoreBundle\Helper\UserHelper;
15
-use Mautic\CoreBundle\Model\NotificationModel;
16
-use Mautic\CoreBundle\Tests\CommonMocks;
17
-use Mautic\LeadBundle\Entity\Import;
18
-use Mautic\LeadBundle\Entity\ImportRepository;
19
-use Mautic\LeadBundle\Entity\LeadEventLogRepository;
20
-use Mautic\LeadBundle\Model\CompanyModel;
21
-use Mautic\LeadBundle\Model\ImportModel;
22
-use Mautic\LeadBundle\Model\LeadModel;
23
-use Symfony\Component\EventDispatcher\EventDispatcher;
24
-
25
-abstract class StandardImportTestHelper extends CommonMocks
26
-{
27
-    protected $eventEntities = [];
28
-    protected static $csvPath;
29
-    protected static $largeCsvPath;
30
-
31
-    protected static $initialList = [
32
-        ['email', 'firstname', 'lastname'],
33
-        ['[email protected]', 'John', 'Doe'],
34
-        ['[email protected]', 'Bad', 'Doe'],
35
-        ['[email protected]', 'Don', 'Doe'],
36
-        [''],
37
-        ['[email protected]', 'Ella', 'Doe'],
38
-    ];
39
-
40
-    public static function setUpBeforeClass(): void
41
-    {
42
-        parent::setUpBeforeClass();
12
+    namespace Mautic\LeadBundle\Tests;
43 13
 
44
-        static::generateSmallCSV();
45
-        static::generateLargeCSV();
46
-    }
14
+    use Mautic\CoreBundle\Helper\UserHelper;
15
+    use Mautic\CoreBundle\Model\NotificationModel;
16
+    use Mautic\CoreBundle\Tests\CommonMocks;
17
+    use Mautic\LeadBundle\Entity\Import;
18
+    use Mautic\LeadBundle\Entity\ImportRepository;
19
+    use Mautic\LeadBundle\Entity\LeadEventLogRepository;
20
+    use Mautic\LeadBundle\Model\CompanyModel;
21
+    use Mautic\LeadBundle\Model\ImportModel;
22
+    use Mautic\LeadBundle\Model\LeadModel;
23
+    use Symfony\Component\EventDispatcher\EventDispatcher;
47 24
 
48
-    public static function tearDownAfterClass(): void
25
+    abstract class StandardImportTestHelper extends CommonMocks
49 26
     {
50
-        if (file_exists(self::$csvPath)) {
51
-            unlink(self::$csvPath);
27
+        protected $eventEntities = [];
28
+        protected static $csvPath;
29
+        protected static $largeCsvPath;
30
+
31
+        protected static $initialList = [
32
+            ['email', 'firstname', 'lastname'],
33
+            ['[email protected]', 'John', 'Doe'],
34
+            ['[email protected]', 'Bad', 'Doe'],
35
+            ['[email protected]', 'Don', 'Doe'],
36
+            [''],
37
+            ['[email protected]', 'Ella', 'Doe'],
38
+        ];
39
+
40
+        public static function setUpBeforeClass(): void
41
+        {
42
+            parent::setUpBeforeClass();
43
+
44
+            static::generateSmallCSV();
45
+            static::generateLargeCSV();
52 46
         }
53 47
 
54
-        if (file_exists(self::$largeCsvPath)) {
55
-            unlink(self::$largeCsvPath);
48
+        public static function tearDownAfterClass(): void
49
+        {
50
+            if (file_exists(self::$csvPath)) {
51
+                unlink(self::$csvPath);
52
+            }
53
+
54
+            if (file_exists(self::$largeCsvPath)) {
55
+                unlink(self::$largeCsvPath);
56
+            }
57
+
58
+            parent::tearDownAfterClass();
56 59
         }
57 60
 
58
-        parent::tearDownAfterClass();
59
-    }
61
+        public static function generateSmallCSV()
62
+        {
63
+            $tmpFile = tempnam(sys_get_temp_dir(), 'mautic_import_test_');
64
+            $file    = fopen($tmpFile, 'w');
60 65
 
61
-    public static function generateSmallCSV()
62
-    {
63
-        $tmpFile = tempnam(sys_get_temp_dir(), 'mautic_import_test_');
64
-        $file    = fopen($tmpFile, 'w');
66
+            foreach (self::$initialList as $line) {
67
+                fputcsv($file, $line);
68
+            }
65 69
 
66
-        foreach (self::$initialList as $line) {
67
-            fputcsv($file, $line);
70
+            fclose($file);
71
+            self::$csvPath = $tmpFile;
68 72
         }
69 73
 
70
-        fclose($file);
71
-        self::$csvPath = $tmpFile;
72
-    }
74
+        public static function generateLargeCSV()
75
+        {
76
+            $tmpFile = tempnam(sys_get_temp_dir(), 'mautic_import_large_test_');
77
+            $file    = fopen($tmpFile, 'w');
78
+            fputcsv($file, ['email', 'firstname', 'lastname']);
79
+            $counter = 510;
80
+            while ($counter) {
81
+                fputcsv($file, [uniqid().'@gmail.com', uniqid(), uniqid()]);
73 82
 
74
-    public static function generateLargeCSV()
75
-    {
76
-        $tmpFile = tempnam(sys_get_temp_dir(), 'mautic_import_large_test_');
77
-        $file    = fopen($tmpFile, 'w');
78
-        fputcsv($file, ['email', 'firstname', 'lastname']);
79
-        $counter = 510;
80
-        while ($counter) {
81
-            fputcsv($file, [uniqid().'@gmail.com', uniqid(), uniqid()]);
82
-
83
-            --$counter;
83
+                --$counter;
84
+            }
85
+
86
+            fclose($file);
87
+            self::$largeCsvPath = $tmpFile;
84 88
         }
85 89
 
86
-        fclose($file);
87
-        self::$largeCsvPath = $tmpFile;
88
-    }
90
+        public function setUp(): void
91
+        {
92
+            defined('MAUTIC_ENV') or define('MAUTIC_ENV', 'test');
89 93
 
90
-    public function setUp(): void
91
-    {
92
-        defined('MAUTIC_ENV') or define('MAUTIC_ENV', 'test');
94
+            $this->eventEntities = [];
95
+        }
93 96
 
94
-        $this->eventEntities = [];
95
-    }
97
+        protected function initImportEntity(array $methods = null)
98
+        {
99
+            $entity = $this->getMockBuilder(Import::class)
100
+                ->setMethods($methods)
101
+                ->getMock();
96 102
 
97
-    protected function initImportEntity(array $methods = null)
98
-    {
99
-        $entity = $this->getMockBuilder(Import::class)
100
-            ->setMethods($methods)
101
-            ->getMock();
102
-
103
-        $entity->setFilePath(self::$csvPath)
104
-            ->setLineCount(count(self::$initialList))
105
-            ->setHeaders(self::$initialList[0])
106
-            ->setParserConfig(
107
-                [
108
-                    'batchlimit' => 10,
109
-                    'delimiter'  => ',',
110
-                    'enclosure'  => '"',
111
-                    'escape'     => '/',
112
-                ]
113
-            );
114
-
115
-        return $entity;
116
-    }
117
-
118
-    /**
119
-     * Initialize the ImportModel object.
120
-     *
121
-     * @return ImportModel
122
-     */
123
-    protected function initImportModel()
124
-    {
125
-        $translator           = $this->getTranslatorMock();
126
-        $pathsHelper          = $this->getPathsHelperMock();
127
-        $entityManager        = $this->getEntityManagerMock();
128
-        $coreParametersHelper = $this->getCoreParametersHelperMock();
129
-
130
-        $logRepository = $this->getMockBuilder(LeadEventLogRepository::class)
131
-            ->disableOriginalConstructor()
132
-            ->getMock();
133
-
134
-        $importRepository = $this->getMockBuilder(ImportRepository::class)
135
-            ->disableOriginalConstructor()
136
-            ->getMock();
137
-        $importRepository->method('getValue')
138
-            ->willReturn(true);
139
-
140
-        $entityManager->expects($this->any())
141
-            ->method('getRepository')
142
-            ->will(
143
-                $this->returnValueMap(
103
+            $entity->setFilePath(self::$csvPath)
104
+                ->setLineCount(count(self::$initialList))
105
+                ->setHeaders(self::$initialList[0])
106
+                ->setParserConfig(
144 107
                     [
145
-                        ['MauticLeadBundle:LeadEventLog', $logRepository],
146
-                        ['MauticLeadBundle:Import', $importRepository],
108
+                        'batchlimit' => 10,
109
+                        'delimiter'  => ',',
110
+                        'enclosure'  => '"',
111
+                        'escape'     => '/',
147 112
                     ]
148
-                )
149
-            );
150
-
151
-        $leadModel = $this->getMockBuilder(LeadModel::class)
152
-            ->disableOriginalConstructor()
153
-            ->getMock();
113
+                );
154 114
 
155
-        $leadModel->setEntityManager($entityManager);
156
-
157
-        $leadModel->expects($this->any())
158
-            ->method('getEventLogRepository')
159
-            ->will($this->returnValue($logRepository));
160
-
161
-        $companyModel = $this->getMockBuilder(CompanyModel::class)
162
-            ->disableOriginalConstructor()
163
-            ->getMock();
164
-
165
-        $companyModel->setEntityManager($entityManager);
166
-
167
-        $notificationModel = $this->getMockBuilder(NotificationModel::class)
168
-            ->disableOriginalConstructor()
169
-            ->getMock();
170
-
171
-        $notificationModel->setEntityManager($entityManager);
172
-
173
-        $importModel = new ImportModel($pathsHelper, $leadModel, $notificationModel, $coreParametersHelper, $companyModel);
174
-        $importModel->setEntityManager($entityManager);
175
-        $importModel->setTranslator($translator);
176
-
177
-        $userHelper = $this->getMockBuilder(UserHelper::class)
178
-            ->disableOriginalConstructor()
179
-            ->getMock();
180
-        $importModel->setUserHelper($userHelper);
181
-
182
-        $importModel->setDispatcher(new EventDispatcher());
115
+            return $entity;
116
+        }
183 117
 
184
-        return $importModel;
185
-    }
118
+        /**
119
+     * Initialize the ImportModel object.
120
+     *
121
+     * @return ImportModel
122
+     */
123
+        protected function initImportModel()
124
+        {
125
+            $translator           = $this->getTranslatorMock();
126
+            $pathsHelper          = $this->getPathsHelperMock();
127
+            $entityManager        = $this->getEntityManagerMock();
128
+            $coreParametersHelper = $this->getCoreParametersHelperMock();
129
+
130
+            $logRepository = $this->getMockBuilder(LeadEventLogRepository::class)
131
+                ->disableOriginalConstructor()
132
+                ->getMock();
133
+
134
+            $importRepository = $this->getMockBuilder(ImportRepository::class)
135
+                ->disableOriginalConstructor()
136
+                ->getMock();
137
+            $importRepository->method('getValue')
138
+                ->willReturn(true);
139
+
140
+            $entityManager->expects($this->any())
141
+                ->method('getRepository')
142
+                ->will(
143
+                    $this->returnValueMap(
144
+                        [
145
+                            ['MauticLeadBundle:LeadEventLog', $logRepository],
146
+                            ['MauticLeadBundle:Import', $importRepository],
147
+                        ]
148
+                    )
149
+                );
150
+
151
+            $leadModel = $this->getMockBuilder(LeadModel::class)
152
+                ->disableOriginalConstructor()
153
+                ->getMock();
154
+
155
+            $leadModel->setEntityManager($entityManager);
156
+
157
+            $leadModel->expects($this->any())
158
+                ->method('getEventLogRepository')
159
+                ->will($this->returnValue($logRepository));
160
+
161
+            $companyModel = $this->getMockBuilder(CompanyModel::class)
162
+                ->disableOriginalConstructor()
163
+                ->getMock();
164
+
165
+            $companyModel->setEntityManager($entityManager);
166
+
167
+            $notificationModel = $this->getMockBuilder(NotificationModel::class)
168
+                ->disableOriginalConstructor()
169
+                ->getMock();
170
+
171
+            $notificationModel->setEntityManager($entityManager);
172
+
173
+            $importModel = new ImportModel($pathsHelper, $leadModel, $notificationModel, $coreParametersHelper, $companyModel);
174
+            $importModel->setEntityManager($entityManager);
175
+            $importModel->setTranslator($translator);
176
+
177
+            $userHelper = $this->getMockBuilder(UserHelper::class)
178
+                ->disableOriginalConstructor()
179
+                ->getMock();
180
+            $importModel->setUserHelper($userHelper);
181
+
182
+            $importModel->setDispatcher(new EventDispatcher());
183
+
184
+            return $importModel;
185
+        }
186 186
 }
Please login to merge, or discard this patch.
app/bundles/LeadBundle/Tests/Deduplicate/ContactDeduperTest.php 1 patch
Switch Indentation   +138 added lines, -138 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php
1
+    <?php
2 2
 
3 3
 /*
4 4
  * @copyright   2018 Mautic Contributors. All rights reserved
@@ -9,158 +9,158 @@  discard block
 block discarded – undo
9 9
  * @license     GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
10 10
  */
11 11
 
12
-namespace Mautic\LeadBundle\Tests\Deduplicate;
12
+    namespace Mautic\LeadBundle\Tests\Deduplicate;
13 13
 
14
-use Mautic\LeadBundle\Deduplicate\ContactDeduper;
15
-use Mautic\LeadBundle\Deduplicate\ContactMerger;
16
-use Mautic\LeadBundle\Entity\Lead;
17
-use Mautic\LeadBundle\Entity\LeadRepository;
18
-use Mautic\LeadBundle\Model\FieldModel;
14
+    use Mautic\LeadBundle\Deduplicate\ContactDeduper;
15
+    use Mautic\LeadBundle\Deduplicate\ContactMerger;
16
+    use Mautic\LeadBundle\Entity\Lead;
17
+    use Mautic\LeadBundle\Entity\LeadRepository;
18
+    use Mautic\LeadBundle\Model\FieldModel;
19 19
 
20
-class ContactDeduperTest extends \PHPUnit\Framework\TestCase
21
-{
22
-    /**
20
+    class ContactDeduperTest extends \PHPUnit\Framework\TestCase
21
+    {
22
+        /**
23 23
      * @var \PHPUnit\Framework\MockObject\MockObject|FieldModel
24 24
      */
25
-    private $fieldModel;
25
+        private $fieldModel;
26 26
 
27
-    /**
27
+        /**
28 28
      * @var \PHPUnit\Framework\MockObject\MockObject|ContactMerger
29 29
      */
30
-    private $contactMerger;
30
+        private $contactMerger;
31 31
 
32
-    /**
32
+        /**
33 33
      * @var \PHPUnit\Framework\MockObject\MockObject|LeadRepository
34 34
      */
35
-    private $leadRepository;
36
-
37
-    protected function setUp(): void
38
-    {
39
-        $this->fieldModel = $this->getMockBuilder(FieldModel::class)
40
-            ->disableOriginalConstructor()
41
-            ->getMock();
42
-
43
-        $this->contactMerger = $this->getMockBuilder(ContactMerger::class)
44
-            ->disableOriginalConstructor()
45
-            ->getMock();
46
-
47
-        $this->leadRepository = $this->getMockBuilder(LeadRepository::class)
48
-            ->disableOriginalConstructor()
49
-            ->getMock();
50
-    }
51
-
52
-    public function testDuplicatesAreMergedWithMergeOlderIntoNewer()
53
-    {
54
-        $this->leadRepository->expects($this->once())
55
-            ->method('getIdentifiedContactCount')
56
-            ->willReturn(4);
57
-
58
-        $lead1 = $this->getLead(1, '[email protected]');
59
-        $lead2 = $this->getLead(2, '[email protected]');
60
-        $lead3 = $this->getLead(3, '[email protected]');
61
-        // Duplicate
62
-        $lead4 = $this->getLead(4, '[email protected]');
63
-
64
-        $this->leadRepository->expects($this->exactly(4))
65
-            ->method('getNextIdentifiedContact')
66
-            ->withConsecutive([0], [1], [2], [3])
67
-            ->willReturnOnConsecutiveCalls($lead1, $lead2, $lead3, null);
68
-
69
-        $this->fieldModel->expects($this->exactly(3))
70
-            ->method('getUniqueIdentifierFields')
71
-            ->willReturn(['email' => 'email']);
72
-        $this->fieldModel->expects($this->once())
73
-            ->method('getFieldList')
74
-            ->willReturn(['email' => 'email']);
75
-
76
-        $this->leadRepository->expects($this->exactly(3))
77
-            ->method('getLeadsByUniqueFields')
78
-            // $lead4 has a older dateAdded
79
-            ->willReturnOnConsecutiveCalls([$lead4, $lead1], [], []);
80
-
81
-        // $lead4 is winner as the older contact
82
-        $this->contactMerger->expects($this->once())
83
-            ->method('merge')
84
-            ->with($lead4, $lead1);
85
-
86
-        $this->getDeduper()->deduplicate();
87
-    }
88
-
89
-    public function testDuplicatesAreMergedWithMergeNewerIntoOlder()
90
-    {
91
-        $this->leadRepository->expects($this->once())
92
-            ->method('getIdentifiedContactCount')
93
-            ->willReturn(4);
94
-
95
-        $lead1 = $this->getLead(1, '[email protected]');
96
-        $lead2 = $this->getLead(2, '[email protected]');
97
-        $lead3 = $this->getLead(3, '[email protected]');
98
-        // Duplicate
99
-        $lead4 = $this->getLead(4, '[email protected]');
100
-
101
-        $this->leadRepository->expects($this->exactly(4))
102
-            ->method('getNextIdentifiedContact')
103
-            ->withConsecutive([0], [1], [2], [3])
104
-            ->willReturnOnConsecutiveCalls($lead1, $lead2, $lead3, null);
105
-
106
-        $this->fieldModel->expects($this->exactly(3))
107
-            ->method('getUniqueIdentifierFields')
108
-            ->willReturn(['email' => 'email']);
109
-        $this->fieldModel->expects($this->once())
110
-            ->method('getFieldList')
111
-            ->willReturn(['email' => 'email']);
112
-
113
-        $this->leadRepository->expects($this->exactly(3))
114
-            ->method('getLeadsByUniqueFields')
115
-            // $lead1 has a older dateAdded
116
-            ->willReturnOnConsecutiveCalls([$lead1, $lead4], [], []);
117
-
118
-        // $lead1 is the winner as the newer contact
119
-        $this->contactMerger->expects($this->once())
120
-            ->method('merge')
121
-            ->with($lead1, $lead4);
122
-
123
-        $this->getDeduper()->deduplicate();
124
-    }
125
-
126
-    /**
35
+        private $leadRepository;
36
+
37
+        protected function setUp(): void
38
+        {
39
+            $this->fieldModel = $this->getMockBuilder(FieldModel::class)
40
+                ->disableOriginalConstructor()
41
+                ->getMock();
42
+
43
+            $this->contactMerger = $this->getMockBuilder(ContactMerger::class)
44
+                ->disableOriginalConstructor()
45
+                ->getMock();
46
+
47
+            $this->leadRepository = $this->getMockBuilder(LeadRepository::class)
48
+                ->disableOriginalConstructor()
49
+                ->getMock();
50
+        }
51
+
52
+        public function testDuplicatesAreMergedWithMergeOlderIntoNewer()
53
+        {
54
+            $this->leadRepository->expects($this->once())
55
+                ->method('getIdentifiedContactCount')
56
+                ->willReturn(4);
57
+
58
+            $lead1 = $this->getLead(1, '[email protected]');
59
+            $lead2 = $this->getLead(2, '[email protected]');
60
+            $lead3 = $this->getLead(3, '[email protected]');
61
+            // Duplicate
62
+            $lead4 = $this->getLead(4, '[email protected]');
63
+
64
+            $this->leadRepository->expects($this->exactly(4))
65
+                ->method('getNextIdentifiedContact')
66
+                ->withConsecutive([0], [1], [2], [3])
67
+                ->willReturnOnConsecutiveCalls($lead1, $lead2, $lead3, null);
68
+
69
+            $this->fieldModel->expects($this->exactly(3))
70
+                ->method('getUniqueIdentifierFields')
71
+                ->willReturn(['email' => 'email']);
72
+            $this->fieldModel->expects($this->once())
73
+                ->method('getFieldList')
74
+                ->willReturn(['email' => 'email']);
75
+
76
+            $this->leadRepository->expects($this->exactly(3))
77
+                ->method('getLeadsByUniqueFields')
78
+                // $lead4 has a older dateAdded
79
+                ->willReturnOnConsecutiveCalls([$lead4, $lead1], [], []);
80
+
81
+            // $lead4 is winner as the older contact
82
+            $this->contactMerger->expects($this->once())
83
+                ->method('merge')
84
+                ->with($lead4, $lead1);
85
+
86
+            $this->getDeduper()->deduplicate();
87
+        }
88
+
89
+        public function testDuplicatesAreMergedWithMergeNewerIntoOlder()
90
+        {
91
+            $this->leadRepository->expects($this->once())
92
+                ->method('getIdentifiedContactCount')
93
+                ->willReturn(4);
94
+
95
+            $lead1 = $this->getLead(1, '[email protected]');
96
+            $lead2 = $this->getLead(2, '[email protected]');
97
+            $lead3 = $this->getLead(3, '[email protected]');
98
+            // Duplicate
99
+            $lead4 = $this->getLead(4, '[email protected]');
100
+
101
+            $this->leadRepository->expects($this->exactly(4))
102
+                ->method('getNextIdentifiedContact')
103
+                ->withConsecutive([0], [1], [2], [3])
104
+                ->willReturnOnConsecutiveCalls($lead1, $lead2, $lead3, null);
105
+
106
+            $this->fieldModel->expects($this->exactly(3))
107
+                ->method('getUniqueIdentifierFields')
108
+                ->willReturn(['email' => 'email']);
109
+            $this->fieldModel->expects($this->once())
110
+                ->method('getFieldList')
111
+                ->willReturn(['email' => 'email']);
112
+
113
+            $this->leadRepository->expects($this->exactly(3))
114
+                ->method('getLeadsByUniqueFields')
115
+                // $lead1 has a older dateAdded
116
+                ->willReturnOnConsecutiveCalls([$lead1, $lead4], [], []);
117
+
118
+            // $lead1 is the winner as the newer contact
119
+            $this->contactMerger->expects($this->once())
120
+                ->method('merge')
121
+                ->with($lead1, $lead4);
122
+
123
+            $this->getDeduper()->deduplicate();
124
+        }
125
+
126
+        /**
127 127
      * @param $id
128 128
      * @param $email
129 129
      *
130 130
      * @return Lead|\PHPUnit\Framework\MockObject\MockObject
131 131
      */
132
-    private function getLead($id, $email)
133
-    {
134
-        $lead = $this->getMockBuilder(Lead::class)
135
-            ->getMock();
136
-        $lead->expects($this->any())
137
-            ->method('getId')
138
-            ->willReturn($id);
139
-        $lead->expects($this->any())
140
-            ->method('getProfileFields')
141
-            ->willReturn(
142
-                [
143
-                    'id'     => $id,
144
-                    'points' => 10,
145
-                    'email'  => $email,
146
-                ]
147
-            );
148
-        $lead->expects($this->any())
149
-            ->method('getDateModified')
150
-            ->willReturn(new \DateTime());
151
-
152
-        return $lead;
153
-    }
154
-
155
-    /**
132
+        private function getLead($id, $email)
133
+        {
134
+            $lead = $this->getMockBuilder(Lead::class)
135
+                ->getMock();
136
+            $lead->expects($this->any())
137
+                ->method('getId')
138
+                ->willReturn($id);
139
+            $lead->expects($this->any())
140
+                ->method('getProfileFields')
141
+                ->willReturn(
142
+                    [
143
+                        'id'     => $id,
144
+                        'points' => 10,
145
+                        'email'  => $email,
146
+                    ]
147
+                );
148
+            $lead->expects($this->any())
149
+                ->method('getDateModified')
150
+                ->willReturn(new \DateTime());
151
+
152
+            return $lead;
153
+        }
154
+
155
+        /**
156 156
      * @return ContactDeduper
157 157
      */
158
-    private function getDeduper()
159
-    {
160
-        return new ContactDeduper(
161
-            $this->fieldModel,
162
-            $this->contactMerger,
163
-            $this->leadRepository
164
-        );
165
-    }
158
+        private function getDeduper()
159
+        {
160
+            return new ContactDeduper(
161
+                $this->fieldModel,
162
+                $this->contactMerger,
163
+                $this->leadRepository
164
+            );
165
+        }
166 166
 }
Please login to merge, or discard this patch.
app/bundles/LeadBundle/Tests/Deduplicate/ContactMergerTest.php 1 patch
Switch Indentation   +653 added lines, -653 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php
1
+    <?php
2 2
 
3 3
 /*
4 4
  * @copyright   2018 Mautic Contributors. All rights reserved
@@ -9,730 +9,730 @@  discard block
 block discarded – undo
9 9
  * @license     GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
10 10
  */
11 11
 
12
-namespace Mautic\LeadBundle\Tests\Deduplicate;
13
-
14
-use Doctrine\Common\Collections\ArrayCollection;
15
-use Mautic\CoreBundle\Entity\IpAddress;
16
-use Mautic\LeadBundle\Deduplicate\ContactMerger;
17
-use Mautic\LeadBundle\Deduplicate\Exception\SameContactException;
18
-use Mautic\LeadBundle\Entity\Lead;
19
-use Mautic\LeadBundle\Entity\LeadRepository;
20
-use Mautic\LeadBundle\Entity\MergeRecordRepository;
21
-use Mautic\LeadBundle\Entity\Tag;
22
-use Mautic\LeadBundle\Model\LeadModel;
23
-use Mautic\UserBundle\Entity\User;
24
-use Monolog\Logger;
25
-use Symfony\Component\EventDispatcher\EventDispatcher;
26
-
27
-class ContactMergerTest extends \PHPUnit\Framework\TestCase
28
-{
29
-    /**
12
+    namespace Mautic\LeadBundle\Tests\Deduplicate;
13
+
14
+    use Doctrine\Common\Collections\ArrayCollection;
15
+    use Mautic\CoreBundle\Entity\IpAddress;
16
+    use Mautic\LeadBundle\Deduplicate\ContactMerger;
17
+    use Mautic\LeadBundle\Deduplicate\Exception\SameContactException;
18
+    use Mautic\LeadBundle\Entity\Lead;
19
+    use Mautic\LeadBundle\Entity\LeadRepository;
20
+    use Mautic\LeadBundle\Entity\MergeRecordRepository;
21
+    use Mautic\LeadBundle\Entity\Tag;
22
+    use Mautic\LeadBundle\Model\LeadModel;
23
+    use Mautic\UserBundle\Entity\User;
24
+    use Monolog\Logger;
25
+    use Symfony\Component\EventDispatcher\EventDispatcher;
26
+
27
+    class ContactMergerTest extends \PHPUnit\Framework\TestCase
28
+    {
29
+        /**
30 30
      * @var \PHPUnit\Framework\MockObject\MockObject|LeadModel
31 31
      */
32
-    private $leadModel;
32
+        private $leadModel;
33 33
 
34
-    /**
34
+        /**
35 35
      * @var \PHPUnit\Framework\MockObject\MockObject|MergeRecordRepository
36 36
      */
37
-    private $leadRepo;
37
+        private $leadRepo;
38 38
 
39
-    /**
39
+        /**
40 40
      * @var \PHPUnit\Framework\MockObject\MockObject|MergeRecordRepository
41 41
      */
42
-    private $mergeRecordRepo;
42
+        private $mergeRecordRepo;
43 43
 
44
-    /**
44
+        /**
45 45
      * @var \PHPUnit\Framework\MockObject\MockObject|EventDispatcher
46 46
      */
47
-    private $dispatcher;
47
+        private $dispatcher;
48 48
 
49
-    /**
49
+        /**
50 50
      * @var \PHPUnit\Framework\MockObject\MockObject|Logger
51 51
      */
52
-    private $logger;
52
+        private $logger;
53 53
 
54
-    protected function setUp(): void
55
-    {
56
-        $this->leadModel       = $this->createMock(LeadModel::class);
57
-        $this->leadRepo        = $this->createMock(LeadRepository::class);
58
-        $this->mergeRecordRepo = $this->createMock(MergeRecordRepository::class);
59
-        $this->dispatcher      = $this->createMock(EventDispatcher::class);
60
-        $this->logger          = $this->createMock(Logger::class);
54
+        protected function setUp(): void
55
+        {
56
+            $this->leadModel       = $this->createMock(LeadModel::class);
57
+            $this->leadRepo        = $this->createMock(LeadRepository::class);
58
+            $this->mergeRecordRepo = $this->createMock(MergeRecordRepository::class);
59
+            $this->dispatcher      = $this->createMock(EventDispatcher::class);
60
+            $this->logger          = $this->createMock(Logger::class);
61 61
 
62
-        $this->leadModel->method('getRepository')->willReturn($this->leadRepo);
63
-    }
62
+            $this->leadModel->method('getRepository')->willReturn($this->leadRepo);
63
+        }
64 64
 
65
-    public function testMergeTimestamps()
66
-    {
67
-        $oldestDateTime = new \DateTime('-60 minutes');
68
-        $latestDateTime = new \DateTime('-30 minutes');
65
+        public function testMergeTimestamps()
66
+        {
67
+            $oldestDateTime = new \DateTime('-60 minutes');
68
+            $latestDateTime = new \DateTime('-30 minutes');
69 69
 
70
-        $winner = new Lead();
71
-        $winner->setLastActive($oldestDateTime);
72
-        $winner->setDateIdentified($latestDateTime);
70
+            $winner = new Lead();
71
+            $winner->setLastActive($oldestDateTime);
72
+            $winner->setDateIdentified($latestDateTime);
73 73
 
74
-        $loser  = new Lead();
75
-        $loser->setLastActive($latestDateTime);
76
-        $loser->setDateIdentified($oldestDateTime);
74
+            $loser  = new Lead();
75
+            $loser->setLastActive($latestDateTime);
76
+            $loser->setDateIdentified($oldestDateTime);
77 77
 
78
-        $this->getMerger()->mergeTimestamps($winner, $loser);
78
+            $this->getMerger()->mergeTimestamps($winner, $loser);
79 79
 
80
-        $this->assertEquals($latestDateTime, $winner->getLastActive());
81
-        $this->assertEquals($oldestDateTime, $winner->getDateIdentified());
80
+            $this->assertEquals($latestDateTime, $winner->getLastActive());
81
+            $this->assertEquals($oldestDateTime, $winner->getDateIdentified());
82 82
 
83
-        // Test with null date identified loser
84
-        $winner->setDateIdentified($latestDateTime);
85
-        $loser->setDateIdentified(null);
83
+            // Test with null date identified loser
84
+            $winner->setDateIdentified($latestDateTime);
85
+            $loser->setDateIdentified(null);
86 86
 
87
-        $this->getMerger()->mergeTimestamps($winner, $loser);
87
+            $this->getMerger()->mergeTimestamps($winner, $loser);
88 88
 
89
-        $this->assertEquals($latestDateTime, $winner->getDateIdentified());
89
+            $this->assertEquals($latestDateTime, $winner->getDateIdentified());
90 90
 
91
-        // Test with null date identified winner
92
-        $winner->setDateIdentified(null);
93
-        $loser->setDateIdentified($latestDateTime);
91
+            // Test with null date identified winner
92
+            $winner->setDateIdentified(null);
93
+            $loser->setDateIdentified($latestDateTime);
94 94
 
95
-        $this->getMerger()->mergeTimestamps($winner, $loser);
95
+            $this->getMerger()->mergeTimestamps($winner, $loser);
96 96
 
97
-        $this->assertEquals($latestDateTime, $winner->getDateIdentified());
98
-    }
97
+            $this->assertEquals($latestDateTime, $winner->getDateIdentified());
98
+        }
99 99
 
100
-    public function testMergeIpAddresses()
101
-    {
102
-        $winner = new Lead();
103
-        $winner->addIpAddress((new IpAddress('1.2.3.4'))->setIpDetails('from winner'));
104
-        $winner->addIpAddress((new IpAddress('4.3.2.1'))->setIpDetails('from winner'));
105
-        $winner->addIpAddress((new IpAddress('5.6.7.8'))->setIpDetails('from winner'));
100
+        public function testMergeIpAddresses()
101
+        {
102
+            $winner = new Lead();
103
+            $winner->addIpAddress((new IpAddress('1.2.3.4'))->setIpDetails('from winner'));
104
+            $winner->addIpAddress((new IpAddress('4.3.2.1'))->setIpDetails('from winner'));
105
+            $winner->addIpAddress((new IpAddress('5.6.7.8'))->setIpDetails('from winner'));
106 106
 
107
-        $loser = new Lead();
108
-        $loser->addIpAddress((new IpAddress('5.6.7.8'))->setIpDetails('from loser'));
109
-        $loser->addIpAddress((new IpAddress('8.7.6.5'))->setIpDetails('from loser'));
107
+            $loser = new Lead();
108
+            $loser->addIpAddress((new IpAddress('5.6.7.8'))->setIpDetails('from loser'));
109
+            $loser->addIpAddress((new IpAddress('8.7.6.5'))->setIpDetails('from loser'));
110 110
 
111
-        $this->getMerger()->mergeIpAddressHistory($winner, $loser);
111
+            $this->getMerger()->mergeIpAddressHistory($winner, $loser);
112 112
 
113
-        $ipAddresses = $winner->getIpAddresses();
114
-        $this->assertCount(4, $ipAddresses);
113
+            $ipAddresses = $winner->getIpAddresses();
114
+            $this->assertCount(4, $ipAddresses);
115 115
 
116
-        $ipAddressArray = $ipAddresses->toArray();
116
+            $ipAddressArray = $ipAddresses->toArray();
117 117
 
118
-        $expectedIpAddressArray = [
119
-            '1.2.3.4' => 'from winner',
120
-            '4.3.2.1' => 'from winner',
121
-            '5.6.7.8' => 'from winner',
122
-            '8.7.6.5' => 'from loser',
123
-        ];
118
+            $expectedIpAddressArray = [
119
+                '1.2.3.4' => 'from winner',
120
+                '4.3.2.1' => 'from winner',
121
+                '5.6.7.8' => 'from winner',
122
+                '8.7.6.5' => 'from loser',
123
+            ];
124 124
 
125
-        foreach ($expectedIpAddressArray as $ipAddress => $ipId) {
126
-            $this->assertSame($ipAddress, $ipAddressArray[$ipAddress]->getIpAddress());
127
-            $this->assertSame($ipId, $ipAddressArray[$ipAddress]->getIpDetails());
125
+            foreach ($expectedIpAddressArray as $ipAddress => $ipId) {
126
+                $this->assertSame($ipAddress, $ipAddressArray[$ipAddress]->getIpAddress());
127
+                $this->assertSame($ipId, $ipAddressArray[$ipAddress]->getIpDetails());
128
+            }
128 129
         }
129
-    }
130
-
131
-    public function testMergeFieldDataWithLoserAsNewlyUpdated()
132
-    {
133
-        $winner = $this->getMockBuilder(Lead::class)
134
-            ->getMock();
135
-        $winner->expects($this->once())
136
-            ->method('getProfileFields')
137
-            ->willReturn(
138
-                [
139
-                    'id'     => 1,
140
-                    'points' => 10,
141
-                    'email'  => '[email protected]',
142
-                ]
143
-            );
144
-
145
-        $loser = $this->getMockBuilder(Lead::class)
146
-            ->getMock();
147
-        $loser->expects($this->once())
148
-            ->method('getProfileFields')
149
-            ->willReturn(
150
-                [
151
-                    'id'     => 2,
152
-                    'points' => 20,
153
-                    'email'  => '[email protected]',
154
-                ]
155
-            );
156
-
157
-        $merger = $this->getMerger();
158
-
159
-        $winnerDateModified = new \DateTime('-30 minutes');
160
-        $loserDateModified  = new \DateTime();
161
-        $winner->expects($this->exactly(2))
162
-            ->method('getDateModified')
163
-            ->willReturn($winnerDateModified);
164
-        $loser->expects($this->exactly(2))
165
-            ->method('getDateModified')
166
-            ->willReturn($loserDateModified);
167
-        $winner->expects($this->once())
168
-            ->method('getFieldValue')
169
-            ->with('email')
170
-            ->willReturn('[email protected]');
171
-
172
-        $winner->expects($this->once())
173
-            ->method('getField')
174
-            ->with('email')
175
-            ->willReturn([
176
-                'value'         => '[email protected]',
177
-                'id'            => 22,
178
-                'label'         => 'Email',
179
-                'alias'         => 'email',
180
-                'type'          => 'email',
181
-                'group'         => 'core',
182
-                'object'        => 'lead',
183
-                'is_fixed'      => true,
184
-                'default_value' => null,
185
-            ]);
186
-
187
-        $winner->expects($this->exactly(3))
188
-            ->method('getId')
189
-            ->willReturn(1);
190
-
191
-        $loser->expects($this->exactly(2))
192
-            ->method('getId')
193
-            ->willReturn(2);
194
-
195
-        // Loser values are newest so should be kept
196
-        // id and points should not be set addUpdatedField should only be called once for email
197
-        $winner->expects($this->once())
198
-            ->method('addUpdatedField')
199
-            ->with('email', '[email protected]');
200
-
201
-        $merger->mergeFieldData($winner, $loser);
202
-    }
203
-
204
-    public function testMergeFieldDataWithWinnerAsNewlyUpdated()
205
-    {
206
-        $winner = $this->getMockBuilder(Lead::class)
207
-            ->getMock();
208
-        $winner->expects($this->once())
209
-            ->method('getProfileFields')
210
-            ->willReturn(
211
-                [
212
-                    'id'     => 1,
213
-                    'points' => 10,
214
-                    'email'  => '[email protected]',
215
-                ]
216
-            );
217 130
 
218
-        $loser = $this->getMockBuilder(Lead::class)
219
-            ->getMock();
220
-        $loser->expects($this->once())
221
-            ->method('getProfileFields')
222
-            ->willReturn(
223
-                [
224
-                    'id'     => 2,
225
-                    'points' => 20,
226
-                    'email'  => '[email protected]',
227
-                ]
228
-            );
229
-
230
-        $merger = $this->getMerger();
231
-
232
-        $winnerDateModified = new \DateTime();
233
-        $loserDateModified  = new \DateTime('-30 minutes');
234
-        $winner->expects($this->exactly(2))
235
-            ->method('getDateModified')
236
-            ->willReturn($winnerDateModified);
237
-
238
-        $winner->expects($this->once())
239
-            ->method('getField')
240
-            ->with('email')
241
-            ->willReturn([
242
-                'value'         => '[email protected]',
243
-                'id'            => 22,
244
-                'label'         => 'Email',
245
-                'alias'         => 'email',
246
-                'type'          => 'email',
247
-                'group'         => 'core',
248
-                'object'        => 'lead',
249
-                'is_fixed'      => true,
250
-                'default_value' => null,
251
-            ]);
252
-
253
-        $winner->expects($this->once())
254
-            ->method('getFieldValue')
255
-            ->with('email')
256
-            ->willReturn('[email protected]');
257
-
258
-        $loser->expects($this->exactly(2))
259
-            ->method('getDateModified')
260
-            ->willReturn($loserDateModified);
261
-
262
-        $winner->expects($this->exactly(4))
263
-            ->method('getId')
264
-            ->willReturn(1);
265
-
266
-        $loser->expects($this->once())
267
-            ->method('getId');
268
-
269
-        // Winner values are newest so should be kept
270
-        // addUpdatedField should never be called as they aren't different values
271
-        $winner->expects($this->never())
272
-            ->method('addUpdatedField');
273
-
274
-        $merger->mergeFieldData($winner, $loser);
275
-    }
276
-
277
-    public function testMergeFieldDataWithLoserAsNewlyCreated()
278
-    {
279
-        $winner = $this->getMockBuilder(Lead::class)
280
-            ->getMock();
281
-        $winner->expects($this->once())
282
-            ->method('getProfileFields')
283
-            ->willReturn(
284
-                [
285
-                    'id'     => 1,
286
-                    'points' => 10,
287
-                    'email'  => '[email protected]',
288
-                ]
289
-            );
131
+        public function testMergeFieldDataWithLoserAsNewlyUpdated()
132
+        {
133
+            $winner = $this->getMockBuilder(Lead::class)
134
+                ->getMock();
135
+            $winner->expects($this->once())
136
+                ->method('getProfileFields')
137
+                ->willReturn(
138
+                    [
139
+                        'id'     => 1,
140
+                        'points' => 10,
141
+                        'email'  => '[email protected]',
142
+                    ]
143
+                );
144
+
145
+            $loser = $this->getMockBuilder(Lead::class)
146
+                ->getMock();
147
+            $loser->expects($this->once())
148
+                ->method('getProfileFields')
149
+                ->willReturn(
150
+                    [
151
+                        'id'     => 2,
152
+                        'points' => 20,
153
+                        'email'  => '[email protected]',
154
+                    ]
155
+                );
156
+
157
+            $merger = $this->getMerger();
158
+
159
+            $winnerDateModified = new \DateTime('-30 minutes');
160
+            $loserDateModified  = new \DateTime();
161
+            $winner->expects($this->exactly(2))
162
+                ->method('getDateModified')
163
+                ->willReturn($winnerDateModified);
164
+            $loser->expects($this->exactly(2))
165
+                ->method('getDateModified')
166
+                ->willReturn($loserDateModified);
167
+            $winner->expects($this->once())
168
+                ->method('getFieldValue')
169
+                ->with('email')
170
+                ->willReturn('[email protected]');
171
+
172
+            $winner->expects($this->once())
173
+                ->method('getField')
174
+                ->with('email')
175
+                ->willReturn([
176
+                    'value'         => '[email protected]',
177
+                    'id'            => 22,
178
+                    'label'         => 'Email',
179
+                    'alias'         => 'email',
180
+                    'type'          => 'email',
181
+                    'group'         => 'core',
182
+                    'object'        => 'lead',
183
+                    'is_fixed'      => true,
184
+                    'default_value' => null,
185
+                ]);
186
+
187
+            $winner->expects($this->exactly(3))
188
+                ->method('getId')
189
+                ->willReturn(1);
190
+
191
+            $loser->expects($this->exactly(2))
192
+                ->method('getId')
193
+                ->willReturn(2);
194
+
195
+            // Loser values are newest so should be kept
196
+            // id and points should not be set addUpdatedField should only be called once for email
197
+            $winner->expects($this->once())
198
+                ->method('addUpdatedField')
199
+                ->with('email', '[email protected]');
200
+
201
+            $merger->mergeFieldData($winner, $loser);
202
+        }
290 203
 
291
-        $loser = $this->getMockBuilder(Lead::class)
292
-            ->getMock();
293
-        $loser->expects($this->once())
294
-            ->method('getProfileFields')
295
-            ->willReturn(
296
-                [
297
-                    'id'     => 2,
298
-                    'points' => 20,
299
-                    'email'  => '[email protected]',
300
-                ]
301
-            );
204
+        public function testMergeFieldDataWithWinnerAsNewlyUpdated()
205
+        {
206
+            $winner = $this->getMockBuilder(Lead::class)
207
+                ->getMock();
208
+            $winner->expects($this->once())
209
+                ->method('getProfileFields')
210
+                ->willReturn(
211
+                    [
212
+                        'id'     => 1,
213
+                        'points' => 10,
214
+                        'email'  => '[email protected]',
215
+                    ]
216
+                );
217
+
218
+            $loser = $this->getMockBuilder(Lead::class)
219
+                ->getMock();
220
+            $loser->expects($this->once())
221
+                ->method('getProfileFields')
222
+                ->willReturn(
223
+                    [
224
+                        'id'     => 2,
225
+                        'points' => 20,
226
+                        'email'  => '[email protected]',
227
+                    ]
228
+                );
229
+
230
+            $merger = $this->getMerger();
231
+
232
+            $winnerDateModified = new \DateTime();
233
+            $loserDateModified  = new \DateTime('-30 minutes');
234
+            $winner->expects($this->exactly(2))
235
+                ->method('getDateModified')
236
+                ->willReturn($winnerDateModified);
237
+
238
+            $winner->expects($this->once())
239
+                ->method('getField')
240
+                ->with('email')
241
+                ->willReturn([
242
+                    'value'         => '[email protected]',
243
+                    'id'            => 22,
244
+                    'label'         => 'Email',
245
+                    'alias'         => 'email',
246
+                    'type'          => 'email',
247
+                    'group'         => 'core',
248
+                    'object'        => 'lead',
249
+                    'is_fixed'      => true,
250
+                    'default_value' => null,
251
+                ]);
252
+
253
+            $winner->expects($this->once())
254
+                ->method('getFieldValue')
255
+                ->with('email')
256
+                ->willReturn('[email protected]');
257
+
258
+            $loser->expects($this->exactly(2))
259
+                ->method('getDateModified')
260
+                ->willReturn($loserDateModified);
261
+
262
+            $winner->expects($this->exactly(4))
263
+                ->method('getId')
264
+                ->willReturn(1);
265
+
266
+            $loser->expects($this->once())
267
+                ->method('getId');
268
+
269
+            // Winner values are newest so should be kept
270
+            // addUpdatedField should never be called as they aren't different values
271
+            $winner->expects($this->never())
272
+                ->method('addUpdatedField');
273
+
274
+            $merger->mergeFieldData($winner, $loser);
275
+        }
302 276
 
303
-        $merger = $this->getMerger();
304
-
305
-        $winnerDateModified = new \DateTime('-30 minutes');
306
-        $loserDateModified  = new \DateTime();
307
-        $winner->expects($this->exactly(2))
308
-            ->method('getDateModified')
309
-            ->willReturn($winnerDateModified);
310
-
311
-        $winner->expects($this->once())
312
-            ->method('getField')
313
-            ->with('email')
314
-            ->willReturn([
315
-                'value'         => '[email protected]',
316
-                'id'            => 22,
317
-                'label'         => 'Email',
318
-                'alias'         => 'email',
319
-                'type'          => 'email',
320
-                'group'         => 'core',
321
-                'object'        => 'lead',
322
-                'is_fixed'      => true,
323
-                'default_value' => null,
324
-            ]);
325
-
326
-        $winner->expects($this->once())
327
-            ->method('getFieldValue')
328
-            ->with('email')
329
-            ->willReturn('[email protected]');
330
-
331
-        $loser->expects($this->exactly(1))
332
-            ->method('getDateModified')
333
-            ->willReturn(null);
334
-        $loser->expects($this->once())
335
-            ->method('getDateAdded')
336
-            ->willReturn($loserDateModified);
337
-
338
-        $winner->expects($this->exactly(3))
339
-            ->method('getId')
340
-            ->willReturn(1);
341
-
342
-        $loser->expects($this->exactly(2))
343
-            ->method('getId')
344
-            ->willReturn(2);
345
-
346
-        // Loser values are newest so should be kept
347
-        // id and points should not be set addUpdatedField should only be called once for email
348
-        $winner->expects($this->once())
349
-            ->method('addUpdatedField')
350
-            ->with('email', '[email protected]');
351
-
352
-        $merger->mergeFieldData($winner, $loser);
353
-    }
354
-
355
-    public function testMergeFieldDataWithWinnerAsNewlyCreated()
356
-    {
357
-        $winner = $this->getMockBuilder(Lead::class)
358
-            ->getMock();
359
-        $winner->expects($this->once())
360
-            ->method('getProfileFields')
361
-            ->willReturn(
362
-                [
363
-                    'id'     => 1,
364
-                    'points' => 10,
365
-                    'email'  => '[email protected]',
366
-                ]
367
-            );
277
+        public function testMergeFieldDataWithLoserAsNewlyCreated()
278
+        {
279
+            $winner = $this->getMockBuilder(Lead::class)
280
+                ->getMock();
281
+            $winner->expects($this->once())
282
+                ->method('getProfileFields')
283
+                ->willReturn(
284
+                    [
285
+                        'id'     => 1,
286
+                        'points' => 10,
287
+                        'email'  => '[email protected]',
288
+                    ]
289
+                );
290
+
291
+            $loser = $this->getMockBuilder(Lead::class)
292
+                ->getMock();
293
+            $loser->expects($this->once())
294
+                ->method('getProfileFields')
295
+                ->willReturn(
296
+                    [
297
+                        'id'     => 2,
298
+                        'points' => 20,
299
+                        'email'  => '[email protected]',
300
+                    ]
301
+                );
302
+
303
+            $merger = $this->getMerger();
304
+
305
+            $winnerDateModified = new \DateTime('-30 minutes');
306
+            $loserDateModified  = new \DateTime();
307
+            $winner->expects($this->exactly(2))
308
+                ->method('getDateModified')
309
+                ->willReturn($winnerDateModified);
310
+
311
+            $winner->expects($this->once())
312
+                ->method('getField')
313
+                ->with('email')
314
+                ->willReturn([
315
+                    'value'         => '[email protected]',
316
+                    'id'            => 22,
317
+                    'label'         => 'Email',
318
+                    'alias'         => 'email',
319
+                    'type'          => 'email',
320
+                    'group'         => 'core',
321
+                    'object'        => 'lead',
322
+                    'is_fixed'      => true,
323
+                    'default_value' => null,
324
+                ]);
325
+
326
+            $winner->expects($this->once())
327
+                ->method('getFieldValue')
328
+                ->with('email')
329
+                ->willReturn('[email protected]');
330
+
331
+            $loser->expects($this->exactly(1))
332
+                ->method('getDateModified')
333
+                ->willReturn(null);
334
+            $loser->expects($this->once())
335
+                ->method('getDateAdded')
336
+                ->willReturn($loserDateModified);
337
+
338
+            $winner->expects($this->exactly(3))
339
+                ->method('getId')
340
+                ->willReturn(1);
341
+
342
+            $loser->expects($this->exactly(2))
343
+                ->method('getId')
344
+                ->willReturn(2);
345
+
346
+            // Loser values are newest so should be kept
347
+            // id and points should not be set addUpdatedField should only be called once for email
348
+            $winner->expects($this->once())
349
+                ->method('addUpdatedField')
350
+                ->with('email', '[email protected]');
351
+
352
+            $merger->mergeFieldData($winner, $loser);
353
+        }
368 354
 
369
-        $loser = $this->getMockBuilder(Lead::class)
370
-            ->getMock();
371
-        $loser->expects($this->once())
372
-            ->method('getProfileFields')
373
-            ->willReturn(
374
-                [
375
-                    'id'     => 2,
376
-                    'points' => 20,
377
-                    'email'  => '[email protected]',
378
-                ]
379
-            );
355
+        public function testMergeFieldDataWithWinnerAsNewlyCreated()
356
+        {
357
+            $winner = $this->getMockBuilder(Lead::class)
358
+                ->getMock();
359
+            $winner->expects($this->once())
360
+                ->method('getProfileFields')
361
+                ->willReturn(
362
+                    [
363
+                        'id'     => 1,
364
+                        'points' => 10,
365
+                        'email'  => '[email protected]',
366
+                    ]
367
+                );
368
+
369
+            $loser = $this->getMockBuilder(Lead::class)
370
+                ->getMock();
371
+            $loser->expects($this->once())
372
+                ->method('getProfileFields')
373
+                ->willReturn(
374
+                    [
375
+                        'id'     => 2,
376
+                        'points' => 20,
377
+                        'email'  => '[email protected]',
378
+                    ]
379
+                );
380
+
381
+            $merger = $this->getMerger();
382
+
383
+            $winnerDateModified = new \DateTime();
384
+            $loserDateModified  = new \DateTime('-30 minutes');
385
+            $winner->expects($this->once())
386
+                ->method('getDateModified')
387
+                ->willReturn(null);
388
+            $winner->expects($this->once())
389
+                ->method('getDateAdded')
390
+                ->willReturn($winnerDateModified);
391
+
392
+            $winner->expects($this->once())
393
+                ->method('getField')
394
+                ->with('email')
395
+                ->willReturn([
396
+                    'value'         => '[email protected]',
397
+                    'id'            => 22,
398
+                    'label'         => 'Email',
399
+                    'alias'         => 'email',
400
+                    'type'          => 'email',
401
+                    'group'         => 'core',
402
+                    'object'        => 'lead',
403
+                    'is_fixed'      => true,
404
+                    'default_value' => null,
405
+                ]);
406
+
407
+            $winner->expects($this->once())
408
+                ->method('getFieldValue')
409
+                ->with('email')
410
+                ->willReturn('[email protected]');
411
+
412
+            $loser->expects($this->exactly(2))
413
+                ->method('getDateModified')
414
+                ->willReturn($loserDateModified);
415
+
416
+            $winner->expects($this->exactly(4))
417
+                ->method('getId')
418
+                ->willReturn(1);
419
+
420
+            $loser->expects($this->once())
421
+                ->method('getId');
422
+
423
+            // Winner values are newest so should be kept
424
+            // addUpdatedField should never be called as they aren't different values
425
+            $winner->expects($this->never())
426
+                ->method('addUpdatedField');
427
+
428
+            $merger->mergeFieldData($winner, $loser);
429
+        }
380 430
 
381
-        $merger = $this->getMerger();
382
-
383
-        $winnerDateModified = new \DateTime();
384
-        $loserDateModified  = new \DateTime('-30 minutes');
385
-        $winner->expects($this->once())
386
-            ->method('getDateModified')
387
-            ->willReturn(null);
388
-        $winner->expects($this->once())
389
-            ->method('getDateAdded')
390
-            ->willReturn($winnerDateModified);
391
-
392
-        $winner->expects($this->once())
393
-            ->method('getField')
394
-            ->with('email')
395
-            ->willReturn([
396
-                'value'         => '[email protected]',
397
-                'id'            => 22,
398
-                'label'         => 'Email',
399
-                'alias'         => 'email',
400
-                'type'          => 'email',
401
-                'group'         => 'core',
402
-                'object'        => 'lead',
403
-                'is_fixed'      => true,
404
-                'default_value' => null,
405
-            ]);
406
-
407
-        $winner->expects($this->once())
408
-            ->method('getFieldValue')
409
-            ->with('email')
410
-            ->willReturn('[email protected]');
411
-
412
-        $loser->expects($this->exactly(2))
413
-            ->method('getDateModified')
414
-            ->willReturn($loserDateModified);
415
-
416
-        $winner->expects($this->exactly(4))
417
-            ->method('getId')
418
-            ->willReturn(1);
419
-
420
-        $loser->expects($this->once())
421
-            ->method('getId');
422
-
423
-        // Winner values are newest so should be kept
424
-        // addUpdatedField should never be called as they aren't different values
425
-        $winner->expects($this->never())
426
-            ->method('addUpdatedField');
427
-
428
-        $merger->mergeFieldData($winner, $loser);
429
-    }
430
-
431
-    /**
431
+        /**
432 432
      * Scenario: A contact clicks on a tracked email link that goes to a tracked page.
433 433
      * The browser must contain no Mautic cookies. A new contact is created with only default values.
434 434
      * If default values from the new contact overwrite the values of the original contact then data are lost.
435 435
      */
436
-    public function testMergeFieldDataWithDefaultValues()
437
-    {
438
-        $winner = $this->createMock(Lead::class);
439
-        $loser  = $this->createMock(Lead::class);
440
-        $merger = $this->getMerger();
441
-
442
-        $winnerDateModified = new \DateTime('-30 minutes');
443
-        $loserDateModified  = new \DateTime();
444
-
445
-        $winner->expects($this->once())
446
-            ->method('getProfileFields')
447
-            ->willReturn([
448
-                'id'      => 1,
449
-                'email'   => '[email protected]',
450
-                'consent' => 'Yes',
451
-                'boolean' => 1,
452
-            ]);
453
-
454
-        $loser->expects($this->once())
455
-            ->method('getProfileFields')
456
-            ->willReturn([
457
-                'id'      => 2,
458
-                'email'   => null,
459
-                'consent' => 'No',
460
-                'boolean' => 0,
461
-            ]);
462
-
463
-        $winner->method('getDateModified')->willReturn($winnerDateModified);
464
-        $winner->method('getId')->willReturn(1);
465
-        $loser->method('getDateModified')->willReturn($loserDateModified);
466
-        $loser->method('getId')->willReturn(2);
467
-        $loser->method('isAnonymous')->willReturn(true);
468
-
469
-        $winner->expects($this->exactly(3))
470
-            ->method('getFieldValue')
471
-            ->withConsecutive(['email'], ['consent'], ['boolean'])
472
-            ->will($this->onConsecutiveCalls('[email protected]', 'Yes', 1));
473
-
474
-        $winner->expects($this->exactly(3))
475
-            ->method('getField')
476
-            ->withConsecutive(['email'], ['consent'], ['boolean'])
477
-            ->will($this->onConsecutiveCalls([
478
-                'id'            => 22,
479
-                'label'         => 'Email',
480
-                'alias'         => 'email',
481
-                'type'          => 'email',
482
-                'group'         => 'core',
483
-                'object'        => 'lead',
484
-                'is_fixed'      => true,
485
-                'default_value' => null,
486
-            ], [
487
-                'id'            => 44,
488
-                'label'         => 'Email Consent',
489
-                'alias'         => 'consent',
490
-                'type'          => 'select',
491
-                'group'         => 'core',
492
-                'object'        => 'lead',
493
-                'is_fixed'      => true,
494
-                'default_value' => 'No',
495
-            ], [
496
-                'id'            => 45,
497
-                'label'         => 'Boolean Field',
498
-                'alias'         => 'boolean',
499
-                'type'          => 'boolean',
500
-                'group'         => 'core',
501
-                'object'        => 'lead',
502
-                'is_fixed'      => true,
503
-                'default_value' => 0,
504
-            ]));
505
-
506
-        $winner->expects($this->exactly(3))
507
-            ->method('addUpdatedField')
508
-            ->withConsecutive(
509
-                ['email', '[email protected]'],
510
-                ['consent', 'Yes'],
511
-                ['boolean', 1]
512
-            );
436
+        public function testMergeFieldDataWithDefaultValues()
437
+        {
438
+            $winner = $this->createMock(Lead::class);
439
+            $loser  = $this->createMock(Lead::class);
440
+            $merger = $this->getMerger();
441
+
442
+            $winnerDateModified = new \DateTime('-30 minutes');
443
+            $loserDateModified  = new \DateTime();
444
+
445
+            $winner->expects($this->once())
446
+                ->method('getProfileFields')
447
+                ->willReturn([
448
+                    'id'      => 1,
449
+                    'email'   => '[email protected]',
450
+                    'consent' => 'Yes',
451
+                    'boolean' => 1,
452
+                ]);
453
+
454
+            $loser->expects($this->once())
455
+                ->method('getProfileFields')
456
+                ->willReturn([
457
+                    'id'      => 2,
458
+                    'email'   => null,
459
+                    'consent' => 'No',
460
+                    'boolean' => 0,
461
+                ]);
462
+
463
+            $winner->method('getDateModified')->willReturn($winnerDateModified);
464
+            $winner->method('getId')->willReturn(1);
465
+            $loser->method('getDateModified')->willReturn($loserDateModified);
466
+            $loser->method('getId')->willReturn(2);
467
+            $loser->method('isAnonymous')->willReturn(true);
468
+
469
+            $winner->expects($this->exactly(3))
470
+                ->method('getFieldValue')
471
+                ->withConsecutive(['email'], ['consent'], ['boolean'])
472
+                ->will($this->onConsecutiveCalls('[email protected]', 'Yes', 1));
473
+
474
+            $winner->expects($this->exactly(3))
475
+                ->method('getField')
476
+                ->withConsecutive(['email'], ['consent'], ['boolean'])
477
+                ->will($this->onConsecutiveCalls([
478
+                    'id'            => 22,
479
+                    'label'         => 'Email',
480
+                    'alias'         => 'email',
481
+                    'type'          => 'email',
482
+                    'group'         => 'core',
483
+                    'object'        => 'lead',
484
+                    'is_fixed'      => true,
485
+                    'default_value' => null,
486
+                ], [
487
+                    'id'            => 44,
488
+                    'label'         => 'Email Consent',
489
+                    'alias'         => 'consent',
490
+                    'type'          => 'select',
491
+                    'group'         => 'core',
492
+                    'object'        => 'lead',
493
+                    'is_fixed'      => true,
494
+                    'default_value' => 'No',
495
+                ], [
496
+                    'id'            => 45,
497
+                    'label'         => 'Boolean Field',
498
+                    'alias'         => 'boolean',
499
+                    'type'          => 'boolean',
500
+                    'group'         => 'core',
501
+                    'object'        => 'lead',
502
+                    'is_fixed'      => true,
503
+                    'default_value' => 0,
504
+                ]));
505
+
506
+            $winner->expects($this->exactly(3))
507
+                ->method('addUpdatedField')
508
+                ->withConsecutive(
509
+                    ['email', '[email protected]'],
510
+                    ['consent', 'Yes'],
511
+                    ['boolean', 1]
512
+                );
513
+
514
+            $merger->mergeFieldData($winner, $loser);
515
+        }
513 516
 
514
-        $merger->mergeFieldData($winner, $loser);
515
-    }
517
+        public function testMergeOwners()
518
+        {
519
+            $winner = new Lead();
520
+            $loser  = new Lead();
516 521
 
517
-    public function testMergeOwners()
518
-    {
519
-        $winner = new Lead();
520
-        $loser  = new Lead();
522
+            $winnerOwner = new User();
523
+            $winnerOwner->setUsername('bob');
524
+            $winner->setOwner($winnerOwner);
521 525
 
522
-        $winnerOwner = new User();
523
-        $winnerOwner->setUsername('bob');
524
-        $winner->setOwner($winnerOwner);
526
+            $loserOwner = new User();
527
+            $loserOwner->setUsername('susan');
528
+            $loser->setOwner($loserOwner);
525 529
 
526
-        $loserOwner = new User();
527
-        $loserOwner->setUsername('susan');
528
-        $loser->setOwner($loserOwner);
530
+            // Should not have been merged due to winner already having one
531
+            $this->getMerger()->mergeOwners($winner, $loser);
532
+            $this->assertEquals($winnerOwner->getUsername(), $winner->getOwner()->getUsername());
529 533
 
530
-        // Should not have been merged due to winner already having one
531
-        $this->getMerger()->mergeOwners($winner, $loser);
532
-        $this->assertEquals($winnerOwner->getUsername(), $winner->getOwner()->getUsername());
534
+            $winner->setOwner(null);
535
+            $this->getMerger()->mergeOwners($winner, $loser);
533 536
 
534
-        $winner->setOwner(null);
535
-        $this->getMerger()->mergeOwners($winner, $loser);
537
+            // Should be set to loser owner since winner owner was null
538
+            $this->assertEquals($loserOwner->getUsername(), $winner->getOwner()->getUsername());
539
+        }
536 540
 
537
-        // Should be set to loser owner since winner owner was null
538
-        $this->assertEquals($loserOwner->getUsername(), $winner->getOwner()->getUsername());
539
-    }
541
+        public function testMergePoints()
542
+        {
543
+            $winner = new Lead();
544
+            $loser  = new Lead();
540 545
 
541
-    public function testMergePoints()
542
-    {
543
-        $winner = new Lead();
544
-        $loser  = new Lead();
546
+            $winner->setPoints(100);
547
+            $loser->setPoints(50);
545 548
 
546
-        $winner->setPoints(100);
547
-        $loser->setPoints(50);
549
+            $this->getMerger()->mergePoints($winner, $loser);
548 550
 
549
-        $this->getMerger()->mergePoints($winner, $loser);
551
+            $this->assertEquals(150, $winner->getPoints());
552
+        }
550 553
 
551
-        $this->assertEquals(150, $winner->getPoints());
552
-    }
554
+        public function testMergeTags()
555
+        {
556
+            $winner = new Lead();
557
+            $loser  = new Lead();
558
+            $loser->addTag(new Tag('loser'));
559
+            $loser->addTag(new Tag('loser2'));
553 560
 
554
-    public function testMergeTags()
555
-    {
556
-        $winner = new Lead();
557
-        $loser  = new Lead();
558
-        $loser->addTag(new Tag('loser'));
559
-        $loser->addTag(new Tag('loser2'));
561
+            $this->leadModel->expects($this->once())
562
+                ->method('modifyTags')
563
+                ->with($winner, ['loser', 'loser2'], null, false);
560 564
 
561
-        $this->leadModel->expects($this->once())
562
-            ->method('modifyTags')
563
-            ->with($winner, ['loser', 'loser2'], null, false);
565
+            $this->getMerger()->mergeTags($winner, $loser);
566
+        }
564 567
 
565
-        $this->getMerger()->mergeTags($winner, $loser);
566
-    }
568
+        public function testFullMergeThrowsSameContactException()
569
+        {
570
+            $winner = $this->getMockBuilder(Lead::class)
571
+                ->getMock();
572
+            $winner->expects($this->once())
573
+                ->method('getId')
574
+                ->willReturn(1);
567 575
 
568
-    public function testFullMergeThrowsSameContactException()
569
-    {
570
-        $winner = $this->getMockBuilder(Lead::class)
571
-            ->getMock();
572
-        $winner->expects($this->once())
573
-            ->method('getId')
574
-            ->willReturn(1);
576
+            $loser = $this->getMockBuilder(Lead::class)
577
+                ->getMock();
578
+            $loser->expects($this->once())
579
+                ->method('getId')
580
+                ->willReturn(1);
575 581
 
576
-        $loser = $this->getMockBuilder(Lead::class)
577
-            ->getMock();
578
-        $loser->expects($this->once())
579
-            ->method('getId')
580
-            ->willReturn(1);
582
+            $this->expectException(SameContactException::class);
581 583
 
582
-        $this->expectException(SameContactException::class);
584
+            $this->getMerger()->merge($winner, $loser);
585
+        }
583 586
 
584
-        $this->getMerger()->merge($winner, $loser);
585
-    }
587
+        public function testFullMerge()
588
+        {
589
+            $winner = $this->getMockBuilder(Lead::class)
590
+                ->getMock();
591
+            $winner->expects($this->any())
592
+                ->method('getId')
593
+                ->willReturn(1);
594
+            $winner->expects($this->once())
595
+                ->method('getProfileFields')
596
+                ->willReturn(
597
+                    [
598
+                        'id'     => 1,
599
+                        'points' => 10,
600
+                        'email'  => '[email protected]',
601
+                    ]
602
+                );
603
+            $winner->expects($this->exactly(2))
604
+                ->method('getDateModified')
605
+                ->willReturn(new \DateTime('-30 minutes'));
606
+
607
+            $loser = $this->getMockBuilder(Lead::class)
608
+                ->getMock();
609
+            $loser->expects($this->any())
610
+                ->method('getId')
611
+                ->willReturn(2);
612
+            $loser->expects($this->once())
613
+                ->method('getProfileFields')
614
+                ->willReturn(
615
+                    [
616
+                        'id'     => 2,
617
+                        'points' => 20,
618
+                        'email'  => '[email protected]',
619
+                    ]
620
+                );
621
+            $loser->expects($this->exactly(2))
622
+                ->method('getDateModified')
623
+                ->willReturn(new \DateTime());
624
+
625
+            // updateMergeRecords
626
+            $this->mergeRecordRepo->expects($this->once())
627
+                ->method('moveMergeRecord')
628
+                ->with(2, 1);
629
+
630
+            // mergeIpAddresses
631
+            $ip = new IpAddress('1.2.3..4');
632
+            $loser->expects($this->once())
633
+                ->method('getIpAddresses')
634
+                ->willReturn(new ArrayCollection([$ip]));
635
+            $winner->expects($this->once())
636
+                ->method('addIpAddress')
637
+                ->with($ip);
638
+
639
+            // mergeFieldData
640
+            $winner->expects($this->once())
641
+                ->method('getFieldValue')
642
+                ->with('email')
643
+                ->willReturn('[email protected]');
644
+
645
+            $winner->expects($this->once())
646
+                ->method('getField')
647
+                ->with('email')
648
+                ->willReturn([
649
+                    'value'         => '[email protected]',
650
+                    'id'            => 22,
651
+                    'label'         => 'Email',
652
+                    'alias'         => 'email',
653
+                    'type'          => 'email',
654
+                    'group'         => 'core',
655
+                    'object'        => 'lead',
656
+                    'is_fixed'      => true,
657
+                    'default_value' => null,
658
+                ]);
659
+
660
+            $winner->expects($this->once())
661
+                ->method('addUpdatedField')
662
+                ->with('email', '[email protected]');
663
+
664
+            // mergeOwners
665
+            $winner->expects($this->never())
666
+                ->method('setOwner');
667
+
668
+            // mergePoints
669
+            $loser->expects($this->once())
670
+                ->method('getPoints')
671
+                ->willReturn(100);
672
+            $winner->expects($this->once())
673
+                ->method('adjustPoints')
674
+                ->with(100);
675
+
676
+            // mergeTags
677
+            $loser->expects($this->once())
678
+                ->method('getTags')
679
+                ->willReturn(new ArrayCollection());
680
+            $this->leadModel->expects($this->once())
681
+                ->method('modifyTags')
682
+                ->with($winner, [], null, false);
683
+
684
+            $this->getMerger()->merge($winner, $loser);
685
+        }
586 686
 
587
-    public function testFullMerge()
588
-    {
589
-        $winner = $this->getMockBuilder(Lead::class)
590
-            ->getMock();
591
-        $winner->expects($this->any())
592
-            ->method('getId')
593
-            ->willReturn(1);
594
-        $winner->expects($this->once())
595
-            ->method('getProfileFields')
596
-            ->willReturn(
597
-                [
598
-                    'id'     => 1,
599
-                    'points' => 10,
600
-                    'email'  => '[email protected]',
601
-                ]
602
-            );
603
-        $winner->expects($this->exactly(2))
604
-            ->method('getDateModified')
605
-            ->willReturn(new \DateTime('-30 minutes'));
606
-
607
-        $loser = $this->getMockBuilder(Lead::class)
608
-            ->getMock();
609
-        $loser->expects($this->any())
610
-            ->method('getId')
611
-            ->willReturn(2);
612
-        $loser->expects($this->once())
613
-            ->method('getProfileFields')
614
-            ->willReturn(
615
-                [
616
-                    'id'     => 2,
617
-                    'points' => 20,
618
-                    'email'  => '[email protected]',
619
-                ]
620
-            );
621
-        $loser->expects($this->exactly(2))
622
-            ->method('getDateModified')
623
-            ->willReturn(new \DateTime());
624
-
625
-        // updateMergeRecords
626
-        $this->mergeRecordRepo->expects($this->once())
627
-            ->method('moveMergeRecord')
628
-            ->with(2, 1);
629
-
630
-        // mergeIpAddresses
631
-        $ip = new IpAddress('1.2.3..4');
632
-        $loser->expects($this->once())
633
-            ->method('getIpAddresses')
634
-            ->willReturn(new ArrayCollection([$ip]));
635
-        $winner->expects($this->once())
636
-            ->method('addIpAddress')
637
-            ->with($ip);
638
-
639
-        // mergeFieldData
640
-        $winner->expects($this->once())
641
-            ->method('getFieldValue')
642
-            ->with('email')
643
-            ->willReturn('[email protected]');
644
-
645
-        $winner->expects($this->once())
646
-            ->method('getField')
647
-            ->with('email')
648
-            ->willReturn([
649
-                'value'         => '[email protected]',
650
-                'id'            => 22,
651
-                'label'         => 'Email',
652
-                'alias'         => 'email',
653
-                'type'          => 'email',
654
-                'group'         => 'core',
655
-                'object'        => 'lead',
656
-                'is_fixed'      => true,
657
-                'default_value' => null,
658
-            ]);
659
-
660
-        $winner->expects($this->once())
661
-            ->method('addUpdatedField')
662
-            ->with('email', '[email protected]');
663
-
664
-        // mergeOwners
665
-        $winner->expects($this->never())
666
-            ->method('setOwner');
667
-
668
-        // mergePoints
669
-        $loser->expects($this->once())
670
-            ->method('getPoints')
671
-            ->willReturn(100);
672
-        $winner->expects($this->once())
673
-            ->method('adjustPoints')
674
-            ->with(100);
675
-
676
-        // mergeTags
677
-        $loser->expects($this->once())
678
-            ->method('getTags')
679
-            ->willReturn(new ArrayCollection());
680
-        $this->leadModel->expects($this->once())
681
-            ->method('modifyTags')
682
-            ->with($winner, [], null, false);
683
-
684
-        $this->getMerger()->merge($winner, $loser);
685
-    }
686
-
687
-    public function testMergeFieldWithEmptyFieldData()
688
-    {
689
-        $loser  = $this->createMock(Lead::class);
690
-        $winner = $this->createMock(Lead::class);
687
+        public function testMergeFieldWithEmptyFieldData()
688
+        {
689
+            $loser  = $this->createMock(Lead::class);
690
+            $winner = $this->createMock(Lead::class);
691 691
 
692
-        $loser->expects($this->exactly(2))
693
-            ->method('getDateModified')
694
-            ->willReturn(new \DateTime('-10 minutes'));
692
+            $loser->expects($this->exactly(2))
693
+                ->method('getDateModified')
694
+                ->willReturn(new \DateTime('-10 minutes'));
695 695
 
696
-        $winner->expects($this->exactly(2))
697
-            ->method('getDateModified')
698
-            ->willReturn(new \DateTime());
696
+            $winner->expects($this->exactly(2))
697
+                ->method('getDateModified')
698
+                ->willReturn(new \DateTime());
699 699
 
700
-        $winner->expects($this->exactly(4))
701
-            ->method('getId')
702
-            ->willReturn(1);
700
+            $winner->expects($this->exactly(4))
701
+                ->method('getId')
702
+                ->willReturn(1);
703 703
 
704
-        $loser->expects($this->once())
705
-            ->method('getId')
706
-            ->willReturn(2);
704
+            $loser->expects($this->once())
705
+                ->method('getId')
706
+                ->willReturn(2);
707 707
 
708
-        $winner->expects($this->once())
709
-            ->method('getProfileFields')
710
-            ->willReturn([
711
-                'email'  => '[email protected]',
712
-            ]);
708
+            $winner->expects($this->once())
709
+                ->method('getProfileFields')
710
+                ->willReturn([
711
+                    'email'  => '[email protected]',
712
+                ]);
713 713
 
714
-        $winner->expects($this->once())
715
-            ->method('getField')
716
-            ->with('email')
717
-            ->willReturn(false);
714
+            $winner->expects($this->once())
715
+                ->method('getField')
716
+                ->with('email')
717
+                ->willReturn(false);
718 718
 
719
-        $this->logger->expects($this->once())
720
-            ->method('info')
721
-            ->with('CONTACT: email is not mergeable for 1 - ');
719
+            $this->logger->expects($this->once())
720
+                ->method('info')
721
+                ->with('CONTACT: email is not mergeable for 1 - ');
722 722
 
723
-        $this->getMerger()->mergeFieldData($winner, $loser);
724
-    }
723
+            $this->getMerger()->mergeFieldData($winner, $loser);
724
+        }
725 725
 
726
-    /**
726
+        /**
727 727
      * @return ContactMerger
728 728
      */
729
-    private function getMerger()
730
-    {
731
-        return new ContactMerger(
732
-            $this->leadModel,
733
-            $this->mergeRecordRepo,
734
-            $this->dispatcher,
735
-            $this->logger
736
-        );
737
-    }
729
+        private function getMerger()
730
+        {
731
+            return new ContactMerger(
732
+                $this->leadModel,
733
+                $this->mergeRecordRepo,
734
+                $this->dispatcher,
735
+                $this->logger
736
+            );
737
+        }
738 738
 }
Please login to merge, or discard this patch.
app/bundles/LeadBundle/Tests/Controller/LeadControllerTest.php 1 patch
Switch Indentation   +200 added lines, -200 removed lines patch added patch discarded remove patch
@@ -1,229 +1,229 @@
 block discarded – undo
1
-<?php
2
-
3
-namespace Mautic\LeadBundle\Tests\Controller;
4
-
5
-use Mautic\CampaignBundle\DataFixtures\ORM\CampaignData;
6
-use Mautic\CoreBundle\Entity\AuditLog;
7
-use Mautic\CoreBundle\Entity\AuditLogRepository;
8
-use Mautic\CoreBundle\Test\MauticMysqlTestCase;
9
-use Mautic\LeadBundle\DataFixtures\ORM\LoadLeadData;
10
-use Mautic\LeadBundle\Entity\Company;
11
-use Mautic\LeadBundle\Entity\Lead;
12
-use Mautic\LeadBundle\Entity\LeadRepository;
13
-use PHPUnit\Framework\Assert;
14
-use Symfony\Component\HttpFoundation\Request;
15
-use Symfony\Component\HttpFoundation\Response;
16
-
17
-class LeadControllerTest extends MauticMysqlTestCase
18
-{
19
-    protected function setUp(): void
1
+    <?php
2
+
3
+    namespace Mautic\LeadBundle\Tests\Controller;
4
+
5
+    use Mautic\CampaignBundle\DataFixtures\ORM\CampaignData;
6
+    use Mautic\CoreBundle\Entity\AuditLog;
7
+    use Mautic\CoreBundle\Entity\AuditLogRepository;
8
+    use Mautic\CoreBundle\Test\MauticMysqlTestCase;
9
+    use Mautic\LeadBundle\DataFixtures\ORM\LoadLeadData;
10
+    use Mautic\LeadBundle\Entity\Company;
11
+    use Mautic\LeadBundle\Entity\Lead;
12
+    use Mautic\LeadBundle\Entity\LeadRepository;
13
+    use PHPUnit\Framework\Assert;
14
+    use Symfony\Component\HttpFoundation\Request;
15
+    use Symfony\Component\HttpFoundation\Response;
16
+
17
+    class LeadControllerTest extends MauticMysqlTestCase
20 18
     {
21
-        parent::setUp();
19
+        protected function setUp(): void
20
+        {
21
+            parent::setUp();
22
+
23
+            defined('MAUTIC_TABLE_PREFIX') or define('MAUTIC_TABLE_PREFIX', '');
24
+        }
25
+
26
+        protected function beforeBeginTransaction(): void
27
+        {
28
+            $this->resetAutoincrement([
29
+                'leads',
30
+                'companies',
31
+                'campaigns',
32
+            ]);
33
+        }
34
+
35
+        public function testContactsAreAddedToThenRemovedFromCampaignsInBatch()
36
+        {
37
+            $this->loadFixtures([CampaignData::class, LoadLeadData::class]);
38
+
39
+            $payload = [
40
+                'lead_batch' => [
41
+                    'add' => [1],
42
+                    'ids' => json_encode([1, 2, 3]),
43
+                ],
44
+            ];
22 45
 
23
-        defined('MAUTIC_TABLE_PREFIX') or define('MAUTIC_TABLE_PREFIX', '');
24
-    }
46
+            $this->client->request(Request::METHOD_POST, '/s/contacts/batchCampaigns', $payload);
25 47
 
26
-    protected function beforeBeginTransaction(): void
27
-    {
28
-        $this->resetAutoincrement([
29
-            'leads',
30
-            'companies',
31
-            'campaigns',
32
-        ]);
33
-    }
34
-
35
-    public function testContactsAreAddedToThenRemovedFromCampaignsInBatch()
36
-    {
37
-        $this->loadFixtures([CampaignData::class, LoadLeadData::class]);
48
+            $clientResponse = $this->client->getResponse();
49
+            $this->assertEquals(Response::HTTP_OK, $clientResponse->getStatusCode());
38 50
 
39
-        $payload = [
40
-            'lead_batch' => [
41
-                'add' => [1],
42
-                'ids' => json_encode([1, 2, 3]),
43
-            ],
44
-        ];
51
+            $this->assertSame(
52
+                [
53
+                    [
54
+                        'lead_id'          => '1',
55
+                        'manually_added'   => '1',
56
+                        'manually_removed' => '0',
57
+                        'date_last_exited' => null,
58
+                    ],
59
+                    [
60
+                        'lead_id'          => '2',
61
+                        'manually_added'   => '1',
62
+                        'manually_removed' => '0',
63
+                        'date_last_exited' => null,
64
+                    ],
65
+                    [
66
+                        'lead_id'          => '3',
67
+                        'manually_added'   => '1',
68
+                        'manually_removed' => '0',
69
+                        'date_last_exited' => null,
70
+                    ],
71
+                ],
72
+                $this->getMembersForCampaign(1)
73
+            );
74
+
75
+            $response = json_decode($clientResponse->getContent(), true);
76
+            $this->assertTrue(isset($response['closeModal']), 'The response does not contain the `closeModal` param.');
77
+            $this->assertTrue($response['closeModal']);
78
+            $this->assertStringContainsString('3 contacts affected', $response['flashes']);
79
+
80
+            $payload = [
81
+                'lead_batch' => [
82
+                    'remove' => [1],
83
+                    'ids'    => json_encode([1, 2, 3]),
84
+                ],
85
+            ];
45 86
 
46
-        $this->client->request(Request::METHOD_POST, '/s/contacts/batchCampaigns', $payload);
87
+            $this->client->request(Request::METHOD_POST, '/s/contacts/batchCampaigns', $payload);
47 88
 
48
-        $clientResponse = $this->client->getResponse();
49
-        $this->assertEquals(Response::HTTP_OK, $clientResponse->getStatusCode());
89
+            $clientResponse = $this->client->getResponse();
90
+            $this->assertEquals(Response::HTTP_OK, $clientResponse->getStatusCode());
50 91
 
51
-        $this->assertSame(
52
-            [
53
-                [
54
-                    'lead_id'          => '1',
55
-                    'manually_added'   => '1',
56
-                    'manually_removed' => '0',
57
-                    'date_last_exited' => null,
58
-                ],
92
+            $this->assertSame(
59 93
                 [
60
-                    'lead_id'          => '2',
61
-                    'manually_added'   => '1',
62
-                    'manually_removed' => '0',
63
-                    'date_last_exited' => null,
94
+                    [
95
+                        'lead_id'          => '1',
96
+                        'manually_added'   => '0',
97
+                        'manually_removed' => '1',
98
+                        'date_last_exited' => null,
99
+                    ],
100
+                    [
101
+                        'lead_id'          => '2',
102
+                        'manually_added'   => '0',
103
+                        'manually_removed' => '1',
104
+                        'date_last_exited' => null,
105
+                    ],
106
+                    [
107
+                        'lead_id'          => '3',
108
+                        'manually_added'   => '0',
109
+                        'manually_removed' => '1',
110
+                        'date_last_exited' => null,
111
+                    ],
64 112
                 ],
113
+                $this->getMembersForCampaign(1)
114
+            );
115
+
116
+            $response = json_decode($clientResponse->getContent(), true);
117
+            $this->assertTrue(isset($response['closeModal']), 'The response does not contain the `closeModal` param.');
118
+            $this->assertTrue($response['closeModal']);
119
+            $this->assertStringContainsString('3 contacts affected', $response['flashes']);
120
+        }
121
+
122
+        public function testCompanyChangesAreTrackedWhenContactAddedViaUI(): void
123
+        {
124
+            $company = new Company();
125
+            $company->setName('Doe Corp');
126
+
127
+            $this->em->persist($company);
128
+            $this->em->flush();
129
+
130
+            $crawler = $this->client->request('GET', 's/contacts/new/');
131
+            $form    = $crawler->filterXPath('//form[@name="lead"]')->form();
132
+            $form->setValues(
65 133
                 [
66
-                    'lead_id'          => '3',
67
-                    'manually_added'   => '1',
68
-                    'manually_removed' => '0',
69
-                    'date_last_exited' => null,
70
-                ],
71
-            ],
72
-            $this->getMembersForCampaign(1)
73
-        );
134
+                    'lead[firstname]' => 'John',
135
+                    'lead[lastname]'  => 'Doe',
136
+                    'lead[email]'     => '[email protected]',
137
+                    'lead[companies]' => [$company->getId()],
138
+                    'lead[points]'    => 20,
139
+                ]
140
+            );
74 141
 
75
-        $response = json_decode($clientResponse->getContent(), true);
76
-        $this->assertTrue(isset($response['closeModal']), 'The response does not contain the `closeModal` param.');
77
-        $this->assertTrue($response['closeModal']);
78
-        $this->assertStringContainsString('3 contacts affected', $response['flashes']);
142
+            $this->client->submit($form);
79 143
 
80
-        $payload = [
81
-            'lead_batch' => [
82
-                'remove' => [1],
83
-                'ids'    => json_encode([1, 2, 3]),
84
-            ],
85
-        ];
144
+            /** @var AuditLogRepository $auditLogRepository */
145
+            $auditLogRepository = $this->em->getRepository(AuditLog::class);
86 146
 
87
-        $this->client->request(Request::METHOD_POST, '/s/contacts/batchCampaigns', $payload);
147
+            /** @var LeadRepository $contactRepository */
148
+            $contactRepository = $this->em->getRepository(Lead::class);
88 149
 
89
-        $clientResponse = $this->client->getResponse();
90
-        $this->assertEquals(Response::HTTP_OK, $clientResponse->getStatusCode());
150
+            /** @var AuditLog[] $auditLogs */
151
+            $auditLogs = $auditLogRepository->getAuditLogs($contactRepository->findOneBy(['email' => '[email protected]']));
91 152
 
92
-        $this->assertSame(
93
-            [
94
-                [
95
-                    'lead_id'          => '1',
96
-                    'manually_added'   => '0',
97
-                    'manually_removed' => '1',
98
-                    'date_last_exited' => null,
99
-                ],
153
+            Assert::assertSame(
100 154
                 [
101
-                    'lead_id'          => '2',
102
-                    'manually_added'   => '0',
103
-                    'manually_removed' => '1',
104
-                    'date_last_exited' => null,
105
-                ],
106
-                [
107
-                    'lead_id'          => '3',
108
-                    'manually_added'   => '0',
109
-                    'manually_removed' => '1',
110
-                    'date_last_exited' => null,
111
-                ],
112
-            ],
113
-            $this->getMembersForCampaign(1)
114
-        );
115
-
116
-        $response = json_decode($clientResponse->getContent(), true);
117
-        $this->assertTrue(isset($response['closeModal']), 'The response does not contain the `closeModal` param.');
118
-        $this->assertTrue($response['closeModal']);
119
-        $this->assertStringContainsString('3 contacts affected', $response['flashes']);
120
-    }
121
-
122
-    public function testCompanyChangesAreTrackedWhenContactAddedViaUI(): void
123
-    {
124
-        $company = new Company();
125
-        $company->setName('Doe Corp');
126
-
127
-        $this->em->persist($company);
128
-        $this->em->flush();
129
-
130
-        $crawler = $this->client->request('GET', 's/contacts/new/');
131
-        $form    = $crawler->filterXPath('//form[@name="lead"]')->form();
132
-        $form->setValues(
133
-            [
134
-                'lead[firstname]' => 'John',
135
-                'lead[lastname]'  => 'Doe',
136
-                'lead[email]'     => '[email protected]',
137
-                'lead[companies]' => [$company->getId()],
138
-                'lead[points]'    => 20,
139
-            ]
140
-        );
141
-
142
-        $this->client->submit($form);
143
-
144
-        /** @var AuditLogRepository $auditLogRepository */
145
-        $auditLogRepository = $this->em->getRepository(AuditLog::class);
146
-
147
-        /** @var LeadRepository $contactRepository */
148
-        $contactRepository = $this->em->getRepository(Lead::class);
149
-
150
-        /** @var AuditLog[] $auditLogs */
151
-        $auditLogs = $auditLogRepository->getAuditLogs($contactRepository->findOneBy(['email' => '[email protected]']));
152
-
153
-        Assert::assertSame(
154
-            [
155
-                'firstname' => [
156
-                    0 => null,
157
-                    1 => 'John',
158
-                ],
159
-                'lastname' => [
160
-                    0 => null,
161
-                    1 => 'Doe',
162
-                ],
163
-                'email' => [
164
-                    0 => null,
165
-                    1 => '[email protected]',
166
-                ],
167
-                'points' => [
168
-                    0 => 0,
169
-                    1 => 20.0,
170
-                ],
171
-                'company' => [
172
-                    0 => '',
173
-                    1 => 'Doe Corp',
155
+                    'firstname' => [
156
+                        0 => null,
157
+                        1 => 'John',
158
+                    ],
159
+                    'lastname' => [
160
+                        0 => null,
161
+                        1 => 'Doe',
162
+                    ],
163
+                    'email' => [
164
+                        0 => null,
165
+                        1 => '[email protected]',
166
+                    ],
167
+                    'points' => [
168
+                        0 => 0,
169
+                        1 => 20.0,
170
+                    ],
171
+                    'company' => [
172
+                        0 => '',
173
+                        1 => 'Doe Corp',
174
+                    ],
174 175
                 ],
175
-            ],
176
-            $auditLogs[0]['details']['fields']
177
-        );
178
-    }
176
+                $auditLogs[0]['details']['fields']
177
+            );
178
+        }
179 179
 
180
-    /**
180
+        /**
181 181
      * Only tests if an actual CSV file is returned and if the content size isn't suspiciously small.
182 182
      * We do more in-depth tests in \Mautic\CoreBundle\Tests\Unit\Helper\ExportHelperTest.
183 183
      */
184
-    public function testCsvIsExportedCorrectly()
185
-    {
186
-        $this->loadFixtures([LoadLeadData::class]);
184
+        public function testCsvIsExportedCorrectly()
185
+        {
186
+            $this->loadFixtures([LoadLeadData::class]);
187 187
 
188
-        ob_start();
189
-        $this->client->request(Request::METHOD_GET, '/s/contacts/batchExport?filetype=csv');
190
-        $content = ob_get_contents();
191
-        ob_end_clean();
188
+            ob_start();
189
+            $this->client->request(Request::METHOD_GET, '/s/contacts/batchExport?filetype=csv');
190
+            $content = ob_get_contents();
191
+            ob_end_clean();
192 192
 
193
-        $clientResponse = $this->client->getResponse();
193
+            $clientResponse = $this->client->getResponse();
194 194
 
195
-        $this->assertEquals(Response::HTTP_OK, $clientResponse->getStatusCode());
196
-        $this->assertEquals($this->client->getInternalResponse()->getHeader('content-type'), 'text/csv; charset=UTF-8');
197
-        $this->assertEquals(true, (strlen($content) > 5000));
198
-    }
195
+            $this->assertEquals(Response::HTTP_OK, $clientResponse->getStatusCode());
196
+            $this->assertEquals($this->client->getInternalResponse()->getHeader('content-type'), 'text/csv; charset=UTF-8');
197
+            $this->assertEquals(true, (strlen($content) > 5000));
198
+        }
199 199
 
200
-    /**
200
+        /**
201 201
      * Only tests if an actual Excel file is returned and if the content size isn't suspiciously small.
202 202
      * We do more in-depth tests in \Mautic\CoreBundle\Tests\Unit\Helper\ExportHelperTest.
203 203
      */
204
-    public function testExcelIsExportedCorrectly()
205
-    {
206
-        $this->loadFixtures([LoadLeadData::class]);
207
-
208
-        ob_start();
209
-        $this->client->request(Request::METHOD_GET, '/s/contacts/batchExport?filetype=xlsx');
210
-        $content = ob_get_contents();
211
-        ob_end_clean();
212
-
213
-        $clientResponse = $this->client->getResponse();
214
-
215
-        $this->assertEquals(Response::HTTP_OK, $clientResponse->getStatusCode());
216
-        $this->assertEquals($this->client->getInternalResponse()->getHeader('content-type'), 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
217
-        $this->assertEquals(true, (strlen($content) > 10000));
218
-    }
219
-
220
-    private function getMembersForCampaign(int $campaignId): array
221
-    {
222
-        return $this->connection->createQueryBuilder()
223
-            ->select('cl.lead_id, cl.manually_added, cl.manually_removed, cl.date_last_exited')
224
-            ->from(MAUTIC_TABLE_PREFIX.'campaign_leads', 'cl')
225
-            ->where("cl.campaign_id = {$campaignId}")
226
-            ->execute()
227
-            ->fetchAll();
228
-    }
204
+        public function testExcelIsExportedCorrectly()
205
+        {
206
+            $this->loadFixtures([LoadLeadData::class]);
207
+
208
+            ob_start();
209
+            $this->client->request(Request::METHOD_GET, '/s/contacts/batchExport?filetype=xlsx');
210
+            $content = ob_get_contents();
211
+            ob_end_clean();
212
+
213
+            $clientResponse = $this->client->getResponse();
214
+
215
+            $this->assertEquals(Response::HTTP_OK, $clientResponse->getStatusCode());
216
+            $this->assertEquals($this->client->getInternalResponse()->getHeader('content-type'), 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
217
+            $this->assertEquals(true, (strlen($content) > 10000));
218
+        }
219
+
220
+        private function getMembersForCampaign(int $campaignId): array
221
+        {
222
+            return $this->connection->createQueryBuilder()
223
+                ->select('cl.lead_id, cl.manually_added, cl.manually_removed, cl.date_last_exited')
224
+                ->from(MAUTIC_TABLE_PREFIX.'campaign_leads', 'cl')
225
+                ->where("cl.campaign_id = {$campaignId}")
226
+                ->execute()
227
+                ->fetchAll();
228
+        }
229 229
 }
Please login to merge, or discard this patch.