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

ForecastWidgetTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 2
cbo 2
dl 0
loc 66
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 10 1
B testCloseDateFilterSuccess() 0 35 1
A getTimeFilter() 0 13 1
1
<?php
2
3
namespace OroCRM\Bundle\SalesBundle\Tests\Functional\Dashboard;
4
5
use Oro\Bundle\DashboardBundle\Tests\Functional\AbstractWidgetTestCase;
6
use Oro\Bundle\FilterBundle\Form\Type\Filter\AbstractDateFilterType;
7
8
/**
9
 * @outputBuffering enabled
10
 * @dbIsolation
11
 */
12
class ForecastWidgetTest extends AbstractWidgetTestCase
13
{
14
    protected function setUp()
15
    {
16
        $this->initClient(
17
            ['debug' => false],
18
            array_merge($this->generateBasicAuthHeader(), array('HTTP_X-CSRF-Header' => 1))
19
        );
20
        $this->loadFixtures([
21
            'OroCRM\Bundle\SalesBundle\Tests\Functional\Fixture\LoadForecastWidgetFixtures'
22
        ]);
23
    }
24
25
    /**
26
     * @dataProvider getTimeFilter
27
     */
28
    public function testCloseDateFilterSuccess($dateRangeType, $inProgressCount)
29
    {
30
        $widget = $this->getReference('widget_forecast');
31
32
        $this->configureWidget($widget, [
33
            'forecast_of_opportunities[dateRange][part]' => 'value',
34
            'forecast_of_opportunities[dateRange][type]' => $dateRangeType,
35
            'forecast_of_opportunities[subWidgets][items][0][id]' => 'in_progress',
36
            'forecast_of_opportunities[subWidgets][items][0][order]' => 0,
37
            'forecast_of_opportunities[subWidgets][items][0][show]' => 'on'
38
        ]);
39
40
        $crawler = $this->client->request(
41
            'GET',
42
            $this->getUrl(
43
                'oro_dashboard_itemized_data_widget',
44
                [
45
                    'widget' => 'forecast_of_opportunities',
46
                    'bundle' => 'OroDashboardBundle',
47
                    'name' => 'bigNumbers',
48
                    '_widgetId' => $widget->getId()
49
                ]
50
            )
51
        );
52
        $response = $this->client->getResponse();
53
        $this->assertEquals($response->getStatusCode(), 200, "Failed in gettting widget view !");
54
55
        $subWidgetValue = $crawler->filter('.sub-widget .value')->text();
56
57
        $this->assertEquals(
58
            $inProgressCount,
59
            $subWidgetValue,
60
            '"In progress" metric is not correct. Check calculation in ForecastProvider!'
61
        );
62
    }
63
64
    public function getTimeFilter()
65
    {
66
        return [
67
            'Close Date: All time' => [
68
                'date_range_type' => AbstractDateFilterType::TYPE_ALL_TIME,
69
                'in_progress_count' => 3,
70
            ],
71
            'Close Date: This month' => [
72
                'date_range_type' => AbstractDateFilterType::TYPE_THIS_MONTH,
73
                'in_progress_count' => 2,
74
            ],
75
        ];
76
    }
77
}
78