Completed
Push — master ( 0b658a...cae295 )
by
unknown
54:13
created

UpdateActivityContactFieldsTest   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 445
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
lcom 1
cbo 5
dl 0
loc 445
rs 10
c 1
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 18 1
B testProcessForNotCompletedConfig() 0 35 1
B testProcessForNotConfigurableEntity() 0 39 1
B testProcessForNotExtendableEntity() 0 44 1
A testProcessForEntityWithoutActivities() 0 53 1
A testProcessForEntityWithoutSupportedActivities() 0 55 1
A testProcessForEntityWithSupportedActivities() 0 55 1
B testProcessForUpdateAction() 0 77 1
A testProcessForEntityWithSupportedActivitiesAndHasConflicts() 0 49 1
1
<?php
2
3
namespace OroCRM\Bundle\ActivityContactBundle\Bundle\Tests\Unit\Api\Processor\Config;
4
5
use Oro\Bundle\ApiBundle\Tests\Unit\Processor\Config\ConfigProcessorTestCase;
6
use Oro\Bundle\EntityConfigBundle\Config\Config;
7
use Oro\Bundle\EntityConfigBundle\Config\Id\EntityConfigId;
8
use OroCRM\Bundle\ActivityContactBundle\Api\Processor\Config\UpdateActivityContactFields;
9
use OroCRM\Bundle\ActivityContactBundle\EntityConfig\ActivityScope;
10
11
class UpdateActivityContactFieldsTest extends ConfigProcessorTestCase
12
{
13
    /** @var \PHPUnit_Framework_MockObject_MockObject */
14
    protected $configManager;
15
16
    /** @var \PHPUnit_Framework_MockObject_MockObject */
17
    protected $activityContactProvider;
18
19
    /** @var UpdateActivityContactFields */
20
    protected $processor;
21
22
    protected function setUp()
23
    {
24
        parent::setUp();
25
26
        $this->configManager = $this->getMockBuilder('Oro\Bundle\EntityConfigBundle\Config\ConfigManager')
27
            ->disableOriginalConstructor()
28
            ->getMock();
29
        $this->activityContactProvider = $this
30
            ->getMockBuilder('OroCRM\Bundle\ActivityContactBundle\Provider\ActivityContactProvider')
31
            ->disableOriginalConstructor()
32
            ->getMock();
33
34
        $this->processor = new UpdateActivityContactFields(
35
            $this->configManager,
36
            $this->activityContactProvider,
37
            ['create', 'update']
0 ignored issues
show
Documentation introduced by
array('create', 'update') is of type array<integer,string,{"0":"string","1":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
38
        );
39
    }
40
41
    public function testProcessForNotCompletedConfig()
42
    {
43
        $config = [
44
            'exclusion_policy' => 'none',
45
            'fields'           => [
46
                ActivityScope::LAST_CONTACT_DATE     => null,
47
                ActivityScope::LAST_CONTACT_DATE_IN  => null,
48
                ActivityScope::LAST_CONTACT_DATE_OUT => null,
49
                ActivityScope::CONTACT_COUNT         => null,
50
                ActivityScope::CONTACT_COUNT_IN      => null,
51
                ActivityScope::CONTACT_COUNT_OUT     => null,
52
            ]
53
        ];
54
55
        $this->configManager->expects($this->never())
56
            ->method('hasConfig');
57
58
        $configObject = $this->createConfigObject($config);
59
        $this->context->setResult($configObject);
60
        $this->processor->process($this->context);
61
62
        $this->assertConfig(
63
            [
64
                'fields' => [
65
                    ActivityScope::LAST_CONTACT_DATE     => null,
66
                    ActivityScope::LAST_CONTACT_DATE_IN  => null,
67
                    ActivityScope::LAST_CONTACT_DATE_OUT => null,
68
                    ActivityScope::CONTACT_COUNT         => null,
69
                    ActivityScope::CONTACT_COUNT_IN      => null,
70
                    ActivityScope::CONTACT_COUNT_OUT     => null,
71
                ]
72
            ],
73
            $configObject
74
        );
75
    }
76
77
    public function testProcessForNotConfigurableEntity()
78
    {
79
        $config = [
80
            'exclusion_policy' => 'all',
81
            'fields'           => [
82
                ActivityScope::LAST_CONTACT_DATE     => null,
83
                ActivityScope::LAST_CONTACT_DATE_IN  => null,
84
                ActivityScope::LAST_CONTACT_DATE_OUT => null,
85
                ActivityScope::CONTACT_COUNT         => null,
86
                ActivityScope::CONTACT_COUNT_IN      => null,
87
                ActivityScope::CONTACT_COUNT_OUT     => null,
88
            ]
89
        ];
90
91
        $this->configManager->expects($this->once())
92
            ->method('hasConfig')
93
            ->with(self::TEST_CLASS_NAME);
94
        $this->configManager->expects($this->never())
95
            ->method('getEntityConfig');
96
97
        $configObject = $this->createConfigObject($config);
98
        $this->context->setResult($configObject);
99
        $this->processor->process($this->context);
100
101
        $this->assertConfig(
102
            [
103
                'exclusion_policy' => 'all',
104
                'fields'           => [
105
                    ActivityScope::LAST_CONTACT_DATE     => null,
106
                    ActivityScope::LAST_CONTACT_DATE_IN  => null,
107
                    ActivityScope::LAST_CONTACT_DATE_OUT => null,
108
                    ActivityScope::CONTACT_COUNT         => null,
109
                    ActivityScope::CONTACT_COUNT_IN      => null,
110
                    ActivityScope::CONTACT_COUNT_OUT     => null,
111
                ]
112
            ],
113
            $configObject
114
        );
115
    }
116
117
    public function testProcessForNotExtendableEntity()
118
    {
119
        $config = [
120
            'exclusion_policy' => 'all',
121
            'fields'           => [
122
                ActivityScope::LAST_CONTACT_DATE     => null,
123
                ActivityScope::LAST_CONTACT_DATE_IN  => null,
124
                ActivityScope::LAST_CONTACT_DATE_OUT => null,
125
                ActivityScope::CONTACT_COUNT         => null,
126
                ActivityScope::CONTACT_COUNT_IN      => null,
127
                ActivityScope::CONTACT_COUNT_OUT     => null,
128
            ]
129
        ];
130
131
        $expendConfig = new Config(new EntityConfigId('extend', self::TEST_CLASS_NAME));
132
133
        $this->configManager->expects($this->once())
134
            ->method('hasConfig')
135
            ->with(self::TEST_CLASS_NAME)
136
            ->willReturn(true);
137
        $this->configManager->expects($this->once())
138
            ->method('getEntityConfig')
139
            ->with('extend', self::TEST_CLASS_NAME)
140
            ->willReturn($expendConfig);
141
142
        $configObject = $this->createConfigObject($config);
143
        $this->context->setResult($configObject);
144
        $this->processor->process($this->context);
145
146
        $this->assertConfig(
147
            [
148
                'exclusion_policy' => 'all',
149
                'fields'           => [
150
                    ActivityScope::LAST_CONTACT_DATE     => null,
151
                    ActivityScope::LAST_CONTACT_DATE_IN  => null,
152
                    ActivityScope::LAST_CONTACT_DATE_OUT => null,
153
                    ActivityScope::CONTACT_COUNT         => null,
154
                    ActivityScope::CONTACT_COUNT_IN      => null,
155
                    ActivityScope::CONTACT_COUNT_OUT     => null,
156
                ]
157
            ],
158
            $configObject
159
        );
160
    }
161
162
    public function testProcessForEntityWithoutActivities()
163
    {
164
        $config = [
165
            'exclusion_policy' => 'all',
166
            'fields'           => [
167
                ActivityScope::LAST_CONTACT_DATE     => null,
168
                ActivityScope::LAST_CONTACT_DATE_IN  => null,
169
                ActivityScope::LAST_CONTACT_DATE_OUT => null,
170
                ActivityScope::CONTACT_COUNT         => null,
171
                ActivityScope::CONTACT_COUNT_IN      => null,
172
                ActivityScope::CONTACT_COUNT_OUT     => null,
173
            ]
174
        ];
175
176
        $expendConfig = new Config(new EntityConfigId('extend', self::TEST_CLASS_NAME));
177
        $expendConfig->set('is_extend', true);
178
        $activityConfig = new Config(new EntityConfigId('activity', self::TEST_CLASS_NAME));
179
180
        $this->configManager->expects($this->once())
181
            ->method('hasConfig')
182
            ->with(self::TEST_CLASS_NAME)
183
            ->willReturn(true);
184
        $this->configManager->expects($this->exactly(2))
185
            ->method('getEntityConfig')
186
            ->willReturnMap(
187
                [
188
                    ['extend', self::TEST_CLASS_NAME, $expendConfig],
189
                    ['activity', self::TEST_CLASS_NAME, $activityConfig],
190
                ]
191
            );
192
193
        $this->activityContactProvider->expects($this->never())
194
            ->method('getSupportedActivityClasses');
195
196
        $configObject = $this->createConfigObject($config);
197
        $this->context->setResult($configObject);
198
        $this->processor->process($this->context);
199
200
        $this->assertConfig(
201
            [
202
                'exclusion_policy' => 'all',
203
                'fields'           => [
204
                    ActivityScope::LAST_CONTACT_DATE     => null,
205
                    ActivityScope::LAST_CONTACT_DATE_IN  => null,
206
                    ActivityScope::LAST_CONTACT_DATE_OUT => null,
207
                    ActivityScope::CONTACT_COUNT         => null,
208
                    ActivityScope::CONTACT_COUNT_IN      => null,
209
                    ActivityScope::CONTACT_COUNT_OUT     => null,
210
                ]
211
            ],
212
            $configObject
213
        );
214
    }
215
216
    public function testProcessForEntityWithoutSupportedActivities()
217
    {
218
        $config = [
219
            'exclusion_policy' => 'all',
220
            'fields'           => [
221
                ActivityScope::LAST_CONTACT_DATE     => null,
222
                ActivityScope::LAST_CONTACT_DATE_IN  => null,
223
                ActivityScope::LAST_CONTACT_DATE_OUT => null,
224
                ActivityScope::CONTACT_COUNT         => null,
225
                ActivityScope::CONTACT_COUNT_IN      => null,
226
                ActivityScope::CONTACT_COUNT_OUT     => null,
227
            ]
228
        ];
229
230
        $expendConfig = new Config(new EntityConfigId('extend', self::TEST_CLASS_NAME));
231
        $expendConfig->set('is_extend', true);
232
        $activityConfig = new Config(new EntityConfigId('activity', self::TEST_CLASS_NAME));
233
        $activityConfig->set('activities', ['Test\Activity1']);
234
235
        $this->configManager->expects($this->once())
236
            ->method('hasConfig')
237
            ->with(self::TEST_CLASS_NAME)
238
            ->willReturn(true);
239
        $this->configManager->expects($this->exactly(2))
240
            ->method('getEntityConfig')
241
            ->willReturnMap(
242
                [
243
                    ['extend', self::TEST_CLASS_NAME, $expendConfig],
244
                    ['activity', self::TEST_CLASS_NAME, $activityConfig],
245
                ]
246
            );
247
248
        $this->activityContactProvider->expects($this->once())
249
            ->method('getSupportedActivityClasses')
250
            ->willReturn(['Test\Activity2']);
251
252
        $configObject = $this->createConfigObject($config);
253
        $this->context->setResult($configObject);
254
        $this->processor->process($this->context);
255
256
        $this->assertConfig(
257
            [
258
                'exclusion_policy' => 'all',
259
                'fields'           => [
260
                    ActivityScope::LAST_CONTACT_DATE     => null,
261
                    ActivityScope::LAST_CONTACT_DATE_IN  => null,
262
                    ActivityScope::LAST_CONTACT_DATE_OUT => null,
263
                    ActivityScope::CONTACT_COUNT         => null,
264
                    ActivityScope::CONTACT_COUNT_IN      => null,
265
                    ActivityScope::CONTACT_COUNT_OUT     => null,
266
                ]
267
            ],
268
            $configObject
269
        );
270
    }
271
272
    public function testProcessForEntityWithSupportedActivities()
273
    {
274
        $config = [
275
            'exclusion_policy' => 'all',
276
            'fields'           => [
277
                ActivityScope::LAST_CONTACT_DATE     => null,
278
                ActivityScope::LAST_CONTACT_DATE_IN  => null,
279
                ActivityScope::LAST_CONTACT_DATE_OUT => null,
280
                ActivityScope::CONTACT_COUNT         => null,
281
                ActivityScope::CONTACT_COUNT_IN      => null,
282
                ActivityScope::CONTACT_COUNT_OUT     => null,
283
            ]
284
        ];
285
286
        $expendConfig = new Config(new EntityConfigId('extend', self::TEST_CLASS_NAME));
287
        $expendConfig->set('is_extend', true);
288
        $activityConfig = new Config(new EntityConfigId('activity', self::TEST_CLASS_NAME));
289
        $activityConfig->set('activities', ['Test\Activity1', 'Test\Activity2']);
290
291
        $this->configManager->expects($this->once())
292
            ->method('hasConfig')
293
            ->with(self::TEST_CLASS_NAME)
294
            ->willReturn(true);
295
        $this->configManager->expects($this->exactly(2))
296
            ->method('getEntityConfig')
297
            ->willReturnMap(
298
                [
299
                    ['extend', self::TEST_CLASS_NAME, $expendConfig],
300
                    ['activity', self::TEST_CLASS_NAME, $activityConfig],
301
                ]
302
            );
303
304
        $this->activityContactProvider->expects($this->once())
305
            ->method('getSupportedActivityClasses')
306
            ->willReturn(['Test\Activity2']);
307
308
        $configObject = $this->createConfigObject($config);
309
        $this->context->setResult($configObject);
310
        $this->processor->process($this->context);
311
312
        $this->assertConfig(
313
            [
314
                'exclusion_policy' => 'all',
315
                'fields'           => [
316
                    'lastContactedDate'    => ['property_path' => ActivityScope::LAST_CONTACT_DATE],
317
                    'lastContactedDateIn'  => ['property_path' => ActivityScope::LAST_CONTACT_DATE_IN],
318
                    'lastContactedDateOut' => ['property_path' => ActivityScope::LAST_CONTACT_DATE_OUT],
319
                    'timesContacted'       => ['property_path' => ActivityScope::CONTACT_COUNT],
320
                    'timesContactedIn'     => ['property_path' => ActivityScope::CONTACT_COUNT_IN],
321
                    'timesContactedOut'    => ['property_path' => ActivityScope::CONTACT_COUNT_OUT],
322
                ]
323
            ],
324
            $configObject
325
        );
326
    }
327
328
    public function testProcessForUpdateAction()
329
    {
330
        $config = [
331
            'exclusion_policy' => 'all',
332
            'fields'           => [
333
                ActivityScope::LAST_CONTACT_DATE     => null,
334
                ActivityScope::LAST_CONTACT_DATE_IN  => [
335
                    'exclude' => true
336
                ],
337
                ActivityScope::LAST_CONTACT_DATE_OUT => [
338
                    'exclude' => false
339
                ],
340
                ActivityScope::CONTACT_COUNT         => null,
341
                ActivityScope::CONTACT_COUNT_IN      => null,
342
                ActivityScope::CONTACT_COUNT_OUT     => null,
343
            ]
344
        ];
345
346
        $expendConfig = new Config(new EntityConfigId('extend', self::TEST_CLASS_NAME));
347
        $expendConfig->set('is_extend', true);
348
        $activityConfig = new Config(new EntityConfigId('activity', self::TEST_CLASS_NAME));
349
        $activityConfig->set('activities', ['Test\Activity1', 'Test\Activity2']);
350
351
        $this->configManager->expects($this->once())
352
            ->method('hasConfig')
353
            ->with(self::TEST_CLASS_NAME)
354
            ->willReturn(true);
355
        $this->configManager->expects($this->exactly(2))
356
            ->method('getEntityConfig')
357
            ->willReturnMap(
358
                [
359
                    ['extend', self::TEST_CLASS_NAME, $expendConfig],
360
                    ['activity', self::TEST_CLASS_NAME, $activityConfig],
361
                ]
362
            );
363
364
        $this->activityContactProvider->expects($this->once())
365
            ->method('getSupportedActivityClasses')
366
            ->willReturn(['Test\Activity2']);
367
368
        $configObject = $this->createConfigObject($config);
369
        $this->context->setResult($configObject);
370
        $this->context->setTargetAction('update');
371
        $this->processor->process($this->context);
372
373
        $this->assertConfig(
374
            [
375
                'exclusion_policy' => 'all',
376
                'fields'           => [
377
                    'lastContactedDate'    => [
378
                        'exclude'       => true,
379
                        'property_path' => ActivityScope::LAST_CONTACT_DATE
380
                    ],
381
                    'lastContactedDateIn'  => [
382
                        'exclude'       => true,
383
                        'property_path' => ActivityScope::LAST_CONTACT_DATE_IN
384
                    ],
385
                    'lastContactedDateOut' => [
386
                        'property_path' => ActivityScope::LAST_CONTACT_DATE_OUT
387
                    ],
388
                    'timesContacted'       => [
389
                        'exclude'       => true,
390
                        'property_path' => ActivityScope::CONTACT_COUNT
391
                    ],
392
                    'timesContactedIn'     => [
393
                        'exclude'       => true,
394
                        'property_path' => ActivityScope::CONTACT_COUNT_IN
395
                    ],
396
                    'timesContactedOut'    => [
397
                        'exclude'       => true,
398
                        'property_path' => ActivityScope::CONTACT_COUNT_OUT
399
                    ],
400
                ]
401
            ],
402
            $configObject
403
        );
404
    }
405
406
    public function testProcessForEntityWithSupportedActivitiesAndHasConflicts()
407
    {
408
        $config = [
409
            'exclusion_policy' => 'all',
410
            'fields'           => [
411
                ActivityScope::LAST_CONTACT_DATE => null,
412
                'lastContactedDate'              => null,
413
                ActivityScope::CONTACT_COUNT     => ['property_path' => 'field1'],
414
            ]
415
        ];
416
417
        $expendConfig = new Config(new EntityConfigId('extend', self::TEST_CLASS_NAME));
418
        $expendConfig->set('is_extend', true);
419
        $activityConfig = new Config(new EntityConfigId('activity', self::TEST_CLASS_NAME));
420
        $activityConfig->set('activities', ['Test\Activity1', 'Test\Activity2']);
421
422
        $this->configManager->expects($this->once())
423
            ->method('hasConfig')
424
            ->with(self::TEST_CLASS_NAME)
425
            ->willReturn(true);
426
        $this->configManager->expects($this->exactly(2))
427
            ->method('getEntityConfig')
428
            ->willReturnMap(
429
                [
430
                    ['extend', self::TEST_CLASS_NAME, $expendConfig],
431
                    ['activity', self::TEST_CLASS_NAME, $activityConfig],
432
                ]
433
            );
434
435
        $this->activityContactProvider->expects($this->once())
436
            ->method('getSupportedActivityClasses')
437
            ->willReturn(['Test\Activity2']);
438
439
        $configObject = $this->createConfigObject($config);
440
        $this->context->setResult($configObject);
441
        $this->processor->process($this->context);
442
443
        $this->assertConfig(
444
            [
445
                'exclusion_policy' => 'all',
446
                'fields'           => [
447
                    ActivityScope::LAST_CONTACT_DATE => null,
448
                    'lastContactedDate'              => null,
449
                    ActivityScope::CONTACT_COUNT     => ['property_path' => 'field1'],
450
                ]
451
            ],
452
            $configObject
453
        );
454
    }
455
}
456