Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ReportWidgetFactoryTest.php « Report « Unit « PHPUnit « tests - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2f49fee3cbcdd9a4b9aa6f906c7827014ac15d9b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
/**
 * Piwik - free/libre analytics platform
 *
 * @link http://piwik.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */

namespace Piwik\Tests\Unit\Report;

use Piwik\Plugin\Report;
use Piwik\Report\ReportWidgetConfig;
use Piwik\Report\ReportWidgetFactory;
use Piwik\Widget\WidgetConfig;
use Piwik\Widget\WidgetContainerConfig;

class GetBasicReport extends Report
{
    protected function init()
    {
        parent::init();

        $this->name = 'Report_MyCustomReportName';
        $this->order  = 20;
        $this->module = 'TestPlugin';
        $this->action = 'getBasicReport';
        $this->categoryId = 'Goals_Goals';
        $this->subcategoryId = 'General_Overview';
        $this->actionToLoadSubTables = 'invalidReport';
        $this->parameters = array('idGoal' => '1');
    }

    public function getDefaultTypeViewDataTable()
    {
        return 'graph';
    }
}

/**
 * @group Widget
 * @group Report
 * @group ReportWidgetFactory
 * @group ReportWidgetFactoryTest
 */
class ReportWidgetFactoryTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @var ReportWidgetFactory
     */
    private $factory;

    public function setUp()
    {
        parent::setUp();

        $this->factory = new ReportWidgetFactory(new GetBasicReport());
    }

    public function test_createContainerWidget_ShouldCreateAContainerBasedOnReportWithGivenId()
    {
        $config = $this->factory->createContainerWidget('myId');

        $this->assertTrue($config instanceof WidgetContainerConfig);
        $this->assertSame('myId', $config->getId());
        $this->assertSame('Goals_Goals', $config->getCategoryId());
        $this->assertSame('General_Overview', $config->getSubcategoryId());
        $this->assertSame(100 + 20, $config->getOrder());
    }

    public function test_createWidget_ShouldCreateAContainerBasedOnReportWithGivenId()
    {
        $config = $this->factory->createWidget();

        $this->assertTrue($config instanceof ReportWidgetConfig);
        $this->assertSame('Report_MyCustomReportName', $config->getName());
        $this->assertSame('Goals_Goals', $config->getCategoryId());
        $this->assertSame('General_Overview', $config->getSubcategoryId());
        $this->assertSame('graph', $config->getViewDataTable());
        $this->assertSame(100 + 20, $config->getOrder());
        $this->assertSame('TestPlugin', $config->getModule());
        $this->assertSame('getBasicReport', $config->getAction());

        $this->assertSame(array(
            'viewDataTable' => 'graph',
            'module' => 'TestPlugin',
            'action' => 'getBasicReport',
            'idGoal' => '1'
        ), $config->getParameters());
    }

    public function test_createCustomWidget_ShouldCreateAContainerBasedOnReportWithGivenId()
    {
        $config = $this->factory->createCustomWidget('customAction');

        $this->assertTrue($config instanceof ReportWidgetConfig);
        $this->assertSame('Report_MyCustomReportName', $config->getName());
        $this->assertSame('Goals_Goals', $config->getCategoryId());
        $this->assertSame('General_Overview', $config->getSubcategoryId());
        $this->assertNull($config->getViewDataTable());
        $this->assertSame(100 + 20, $config->getOrder());
        $this->assertSame('TestPlugin', $config->getModule());
        $this->assertSame('customAction', $config->getAction());

        $this->assertSame(array(
            'module' => 'TestPlugin',
            'action' => 'customAction',
            'idGoal' => '1'
        ), $config->getParameters());
    }


}