1
|
|
|
<?php |
2
|
|
|
namespace OroCRM\Bundle\SalesBundle\Tests\Functional\Dashboard; |
3
|
|
|
|
4
|
|
|
use Oro\Bundle\DashboardBundle\Entity\Widget; |
5
|
|
|
use Oro\Bundle\DashboardBundle\Tests\Functional\AbstractWidgetTestCase; |
6
|
|
|
use Oro\Bundle\FilterBundle\Form\Type\Filter\AbstractDateFilterType; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @dbIsolationPerTest |
10
|
|
|
*/ |
11
|
|
|
class CampaignByCloseRevenueTest extends AbstractWidgetTestCase |
12
|
|
|
{ |
13
|
|
|
/** @var Widget */ |
14
|
|
|
protected $widget; |
15
|
|
|
|
16
|
|
View Code Duplication |
public function setUp() |
|
|
|
|
17
|
|
|
{ |
18
|
|
|
$this->initClient( |
19
|
|
|
['debug' => false], |
20
|
|
|
array_merge($this->generateBasicAuthHeader(), array('HTTP_X-CSRF-Header' => 1)) |
21
|
|
|
); |
22
|
|
|
$this->loadFixtures([ |
23
|
|
|
'OroCRM\Bundle\SalesBundle\Tests\Functional\Fixture\LoadCampaignByCloseRevenueWidgetFixture' |
24
|
|
|
]); |
25
|
|
|
|
26
|
|
|
$this->widget = $this->getReference('widget_campaigns_by_close_revenue'); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @dataProvider widgetProvider |
31
|
|
|
* @param $requestData |
32
|
|
|
*/ |
33
|
|
|
public function testDateRangeAllTypeFilter($requestData) |
34
|
|
|
{ |
35
|
|
|
$this->configureWidget($this->widget, $requestData['widgetConfig']); |
36
|
|
|
|
37
|
|
|
$crawler = $this->client->request( |
38
|
|
|
'GET', |
39
|
|
|
$this->getUrl( |
40
|
|
|
'orocrm_campaign_dashboard_campaigns_by_close_revenue_chart', |
41
|
|
|
[ |
42
|
|
|
'widget' => 'campaigns_by_close_revenue', |
43
|
|
|
'_widgetId' => $this->widget->getId() |
44
|
|
|
] |
45
|
|
|
) |
46
|
|
|
); |
47
|
|
|
$response = $this->client->getResponse(); |
48
|
|
|
$this->assertEquals($response->getStatusCode(), 200, "Failed in getting widget view !"); |
49
|
|
|
$this->assertNotEmpty($crawler->html()); |
50
|
|
|
|
51
|
|
|
$chartData = $this->getChartData($crawler); |
52
|
|
|
|
53
|
|
|
//If we have data for chart we need only first campaign |
54
|
|
|
if ($chartData) { |
|
|
|
|
55
|
|
|
$chartData = reset($chartData); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
$this->assertEquals( |
59
|
|
|
$requestData['expectedResult'], |
60
|
|
|
round($chartData->value), |
61
|
|
|
'Revenue for campaign widget calculated incorrectly' |
62
|
|
|
); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @dataProvider widgetConfigureProvider |
67
|
|
|
* @array $requestData |
68
|
|
|
*/ |
69
|
|
|
public function testFilterCampaignByNullCloseRevenue(array $requestData) |
70
|
|
|
{ |
71
|
|
|
$this->configureWidget($this->widget, $requestData['widgetConfig']); |
72
|
|
|
|
73
|
|
|
$crawler = $this->client->request( |
74
|
|
|
'GET', |
75
|
|
|
$this->getUrl( |
76
|
|
|
'orocrm_campaign_dashboard_campaigns_by_close_revenue_chart', |
77
|
|
|
[ |
78
|
|
|
'widget' => 'campaigns_by_close_revenue', |
79
|
|
|
'_widgetId' => $this->widget->getId() |
80
|
|
|
] |
81
|
|
|
) |
82
|
|
|
); |
83
|
|
|
$response = $this->client->getResponse(); |
84
|
|
|
$this->assertEquals($response->getStatusCode(), 200, "Failed in getting widget view !"); |
85
|
|
|
$this->assertNotEmpty($crawler->html()); |
86
|
|
|
|
87
|
|
|
$chartData = $this->getChartData($crawler); |
88
|
|
|
|
89
|
|
|
$this->assertCount( |
90
|
|
|
$requestData['expectedCampaignCount'], |
91
|
|
|
$chartData, |
92
|
|
|
"Opportunity with null or 0 close revenue is presented" |
93
|
|
|
); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function widgetConfigureProvider() |
97
|
|
|
{ |
98
|
|
|
return [ |
99
|
|
|
'Closed lost opportunities' => [ |
100
|
|
|
[ |
101
|
|
|
'widgetConfig' => [ |
102
|
|
|
'campaigns_by_close_revenue[dateRange][part]' => 'value', |
103
|
|
|
'campaigns_by_close_revenue[dateRange][type]' => AbstractDateFilterType::TYPE_ALL_TIME, |
104
|
|
|
], |
105
|
|
|
'expectedResult' => 200, // 2 opportunities * $100 |
106
|
|
|
'expectedCampaignCount' => 1 // Opportunity with test campaign have null close revenue |
107
|
|
|
], |
108
|
|
|
], |
109
|
|
|
]; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @return array |
114
|
|
|
*/ |
115
|
|
|
public function widgetProvider() |
116
|
|
|
{ |
117
|
|
|
return [ |
118
|
|
|
'Closed lost opportunities' => [ |
119
|
|
|
[ |
120
|
|
|
'widgetConfig' => [ |
121
|
|
|
'campaigns_by_close_revenue[dateRange][part]' => 'value', |
122
|
|
|
'campaigns_by_close_revenue[dateRange][type]' => AbstractDateFilterType::TYPE_ALL_TIME, |
123
|
|
|
], |
124
|
|
|
'expectedResult' => 200 // 2 opportunities * $100 |
125
|
|
|
], |
126
|
|
|
], |
127
|
|
|
'Opportunities for today' => [ |
128
|
|
|
[ |
129
|
|
|
'widgetConfig' => [ |
130
|
|
|
'campaigns_by_close_revenue[dateRange][part]' => 'value', |
131
|
|
|
'campaigns_by_close_revenue[dateRange][type]' => AbstractDateFilterType::TYPE_BETWEEN, |
132
|
|
|
'campaigns_by_close_revenue[dateRange][value][start]' => '2016-12-29 00:00:00', |
133
|
|
|
'campaigns_by_close_revenue[dateRange][value][end]' => '2016-12-29 23:59:59', |
134
|
|
|
], |
135
|
|
|
'expectedResult' => 100 // 1 opportunity * $100 |
136
|
|
|
], |
137
|
|
|
] |
138
|
|
|
]; |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.