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 CampaignLeadsTest 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\LoadCampaignLeadsWidgetFixture' |
24
|
|
|
]); |
25
|
|
|
|
26
|
|
|
$this->widget = $this->getReference('widget_campaigns_leads'); |
27
|
|
|
} |
28
|
|
|
public function testGetWidgetConfigureDialog() |
29
|
|
|
{ |
30
|
|
|
$this->getConfigureDialog(); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @depends testGetWidgetConfigureDialog |
35
|
|
|
* @dataProvider widgetProvider |
36
|
|
|
* @param $requestData |
37
|
|
|
*/ |
38
|
|
View Code Duplication |
public function testDateRangeBetweenFilter($requestData) |
|
|
|
|
39
|
|
|
{ |
40
|
|
|
$this->configureWidget($this->widget, $requestData['widgetConfig']); |
41
|
|
|
|
42
|
|
|
$crawler = $this->client->request( |
43
|
|
|
'GET', |
44
|
|
|
$this->getUrl( |
45
|
|
|
'orocrm_campaign_dashboard_campaigns_leads_chart', |
46
|
|
|
[ |
47
|
|
|
'widget' => 'campaigns_leads', |
48
|
|
|
'_widgetId' => $this->widget->getId() |
49
|
|
|
] |
50
|
|
|
) |
51
|
|
|
); |
52
|
|
|
$response = $this->client->getResponse(); |
53
|
|
|
$this->assertEquals($response->getStatusCode(), 200, "Failed in getting widget view !"); |
54
|
|
|
$this->assertNotEmpty($crawler->html()); |
55
|
|
|
|
56
|
|
|
$data = $this->getChartData($crawler); |
57
|
|
|
$this->assertEquals('Campaign', $data[0]->label); |
58
|
|
|
$this->assertEquals($requestData['expectedResultCount'], $data[0]->value); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
View Code Duplication |
protected function getConfigureDialog() |
|
|
|
|
62
|
|
|
{ |
63
|
|
|
$this->client->request( |
64
|
|
|
'GET', |
65
|
|
|
$this->getUrl( |
66
|
|
|
'oro_dashboard_configure', |
67
|
|
|
['id' => $this->widget->getId(), '_widgetContainer' => 'dialog'] |
68
|
|
|
) |
69
|
|
|
); |
70
|
|
|
$response = $this->client->getResponse(); |
71
|
|
|
$this->assertEquals($response->getStatusCode(), 200, 'Failed in getting configure widget dialog window !'); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return array |
76
|
|
|
*/ |
77
|
|
|
public function widgetProvider() |
78
|
|
|
{ |
79
|
|
|
return [ |
80
|
|
|
'Opportunity by status with between date range filter' => [ |
81
|
|
|
[ |
82
|
|
|
'widgetConfig' => [ |
83
|
|
|
'campaigns_leads[dateRange][part]' => 'value', |
84
|
|
|
'campaigns_leads[dateRange][type]' => AbstractDateFilterType::TYPE_BETWEEN, |
85
|
|
|
'campaigns_leads[dateRange][value][start]' => '2016-12-28', |
86
|
|
|
'campaigns_leads[dateRange][value][end]' => '2016-12-29' |
87
|
|
|
], |
88
|
|
|
'expectedResultCount' => 2 |
89
|
|
|
], |
90
|
|
|
], |
91
|
|
|
'Opportunity by status with this month date range filter' => [ |
92
|
|
|
[ |
93
|
|
|
'widgetConfig' => [ |
94
|
|
|
'campaigns_leads[dateRange][part]' => 'value', |
95
|
|
|
'campaigns_leads[dateRange][type]' => AbstractDateFilterType::TYPE_THIS_MONTH |
96
|
|
|
], |
97
|
|
|
'expectedResultCount' => 1 |
98
|
|
|
], |
99
|
|
|
], |
100
|
|
|
'Opportunity by status with this all time date range filter' => [ |
101
|
|
|
[ |
102
|
|
|
'widgetConfig' => [ |
103
|
|
|
'campaigns_leads[dateRange][part]' => 'value', |
104
|
|
|
'campaigns_leads[dateRange][type]' => AbstractDateFilterType::TYPE_ALL_TIME |
105
|
|
|
], |
106
|
|
|
'expectedResultCount' => 5 |
107
|
|
|
], |
108
|
|
|
], |
109
|
|
|
]; |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
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.