Completed
Push — 1.10 ( 3f8f95...f007bc )
by
unknown
09:16
created

CampaignByCloseRevenueTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
dl 12
loc 12
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $chartData of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
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