1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OroCRM\Bundle\AnalyticsBundle\Tests\Functional\Builder; |
4
|
|
|
|
5
|
|
|
use Oro\Bundle\TestFrameworkBundle\Test\WebTestCase; |
6
|
|
|
use OroCRM\Bundle\AnalyticsBundle\Builder\RFMBuilder; |
7
|
|
|
use OroCRM\Bundle\ChannelBundle\Entity\Channel; |
8
|
|
|
use OroCRM\Bundle\MagentoBundle\Entity\Customer; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @dbIsolation |
12
|
|
|
*/ |
13
|
|
|
class RFMBuilderTest extends WebTestCase |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var RFMBuilder |
17
|
|
|
*/ |
18
|
|
|
protected $builder; |
19
|
|
|
|
20
|
|
|
protected function setUp() |
21
|
|
|
{ |
22
|
|
|
$this->initClient(); |
23
|
|
|
$this->loadFixtures([ |
24
|
|
|
'OroCRM\Bundle\AnalyticsBundle\Tests\Functional\DataFixtures\LoadEntitiesData', |
25
|
|
|
'OroCRM\Bundle\AnalyticsBundle\Tests\Functional\DataFixtures\LoadRFMMetricCategoryData', |
26
|
|
|
'OroCRM\Bundle\AnalyticsBundle\Tests\Functional\DataFixtures\LoadOrderData', |
27
|
|
|
]); |
28
|
|
|
|
29
|
|
|
$this->builder = $this->getContainer()->get('orocrm_analytics.builder.rfm'); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @dataProvider buildDataProvider |
34
|
|
|
* |
35
|
|
|
* @param $channelReference |
36
|
|
|
* @param array $ids |
37
|
|
|
* @param array $expectedData |
38
|
|
|
*/ |
39
|
|
|
public function testBuild($channelReference, array $expectedData, array $ids = []) |
40
|
|
|
{ |
41
|
|
|
/** @var Channel $channel */ |
42
|
|
|
$channel = $this->getReference($channelReference); |
43
|
|
|
$this->builder->build($channel, $ids); |
44
|
|
|
$this->assertAnalyticBuild($channel, $expectedData); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @return array |
49
|
|
|
*/ |
50
|
|
|
public function buildDataProvider() |
51
|
|
|
{ |
52
|
|
|
return [ |
53
|
|
|
[ |
54
|
|
|
'channelReference' => 'Channel.CustomerChannel', |
55
|
|
|
'expectedData' => [ |
56
|
|
|
'Channel.CustomerIdentity.CustomerIdentity' => [ |
57
|
|
|
'recency' => 10, |
58
|
|
|
'frequency' => null, |
59
|
|
|
'monetary' => 8, |
60
|
|
|
], |
61
|
|
|
'Channel.CustomerChannel.Customer' => [ |
62
|
|
|
'recency' => null, |
63
|
|
|
'frequency' => 9, |
64
|
|
|
'monetary' => 8, |
65
|
|
|
], |
66
|
|
|
] |
67
|
|
|
] |
68
|
|
|
]; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param Channel $channel |
73
|
|
|
* @param array $expectedData |
74
|
|
|
*/ |
75
|
|
|
protected function assertAnalyticBuild(Channel $channel, array $expectedData) |
76
|
|
|
{ |
77
|
|
|
$expectedData = array_combine(array_map(function ($item) { |
78
|
|
|
return $this->getReference($item)->getId(); |
79
|
|
|
}, array_keys($expectedData)), array_values($expectedData)); |
80
|
|
|
|
81
|
|
|
$repository = $this->getContainer()->get('doctrine') |
82
|
|
|
->getManagerForClass('OroCRM\Bundle\MagentoBundle\Entity\Customer') |
83
|
|
|
->getRepository('OroCRM\Bundle\MagentoBundle\Entity\Customer'); |
84
|
|
|
|
85
|
|
|
$actualData = $repository->findBy(['dataChannel' => $channel]); |
86
|
|
|
/** @var Customer[] $actualData */ |
87
|
|
|
$actualData = array_reduce($actualData, function ($result, Customer $item) { |
88
|
|
|
$result[$item->getId()] = [ |
89
|
|
|
'recency' => $item->getRecency(), |
90
|
|
|
'frequency' => $item->getFrequency(), |
91
|
|
|
'monetary' => $item->getMonetary(), |
92
|
|
|
]; |
93
|
|
|
return $result; |
94
|
|
|
}, []); |
95
|
|
|
$this->assertCount(count($expectedData), $actualData); |
96
|
|
|
$this->assertEquals($expectedData, $actualData); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|