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

WidgetsListTest.php « PluginsFunctions « Core « PHPUnit « tests - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7c2c0e598c93e143d206343be46c76f2195e3579 (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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
/**
 * Piwik - Open source web analytics
 *
 * @link http://piwik.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */

class WidgetsListTest extends DatabaseTestCase
{
    /**
     * @group Core
     * @group PluginsFunctions
     * @group WidgetsList
     */
    public function testGet()
    {
        // setup the access layer
        $pseudoMockAccess = new FakeAccess;
        FakeAccess::$superUser = true;
        Zend_Registry::set('access', $pseudoMockAccess);

        Test_Piwik_BaseFixture::createWebsite('2009-01-04 00:11:42');

        $_GET['idSite'] = 1;

        IntegrationTestCase::loadAllPlugins();

        Piwik_WidgetsList::_reset();
        $widgets = Piwik_GetWidgetsList();
        Piwik_WidgetsList::_reset();

        // there should be 11 main categories
        $this->assertEquals(11, count($widgets));

        // check if each category has the right number of widgets
        $numberOfWidgets = array(
            'VisitsSummary_VisitsSummary'  => 6,
            'Live!'                        => 3,
            'General_Visitors'             => 12,
            'UserSettings_VisitorSettings' => 11,
            'Actions_Actions'              => 8,
            'Actions_SubmenuSitesearch'    => 5,
            'Referers_Referers'            => 7,
            'Goals_Goals'                  => 1,
            'SEO'                          => 2,
            'Example Widgets'              => 4,
            'ExamplePlugin_exampleWidgets' => 3
        );
        foreach ($numberOfWidgets AS $category => $widgetCount) {
            $this->assertEquals($widgetCount, count($widgets[$category]), sprintf("Widget: %s", $category));
        }
        IntegrationTestCase::unloadAllPlugins();
    }

    /**
     * @group Core
     * @group PluginsFunctions
     * @group WidgetsList
     */
    public function testGetWithGoals()
    {
        // setup the access layer
        $pseudoMockAccess = new FakeAccess;
        FakeAccess::$superUser = true;
        Zend_Registry::set('access', $pseudoMockAccess);

        Test_Piwik_BaseFixture::createWebsite('2009-01-04 00:11:42');
        Piwik_Goals_API::getInstance()->addGoal(1, 'Goal 1 - Thank you', 'title', 'Thank you', 'contains', $caseSensitive = false, $revenue = 10, $allowMultipleConversions = 1);

        $_GET['idSite'] = 1;

        $pluginsManager = Piwik_PluginsManager::getInstance();
        $pluginsToLoad = Piwik_Config::getInstance()->Plugins['Plugins'];
        $pluginsManager->loadPlugins($pluginsToLoad);

        Piwik_WidgetsList::_reset();
        $widgets = Piwik_GetWidgetsList();
        Piwik_WidgetsList::_reset();

        // there should be 11 main categories
        $this->assertEquals(11, count($widgets));

        // check that the goal widget was added
        $numberOfWidgets = array(
            'Goals_Goals' => 2,
        );

        foreach ($numberOfWidgets AS $category => $widgetCount) {
            $expected = count($widgets[$category]);
            $this->assertEquals($widgetCount, count($widgets[$category]));
        }
    }

    /**
     * @group Core
     * @group PluginsFunctions
     * @group WidgetsList
     */
    public function testGetWithGoalsAndEcommerce()
    {
        // setup the access layer
        $pseudoMockAccess = new FakeAccess;
        FakeAccess::$superUser = true;
        Zend_Registry::set('access', $pseudoMockAccess);

        Test_Piwik_BaseFixture::createWebsite('2009-01-04 00:11:42', true);
        Piwik_Goals_API::getInstance()->addGoal(1, 'Goal 1 - Thank you', 'title', 'Thank you', 'contains', $caseSensitive = false, $revenue = 10, $allowMultipleConversions = 1);

        $_GET['idSite'] = 1;

        $pluginsManager = Piwik_PluginsManager::getInstance();
        $pluginsToLoad = Piwik_Config::getInstance()->Plugins['Plugins'];
        $pluginsManager->loadPlugins($pluginsToLoad);

        Piwik_WidgetsList::_reset();
        $widgets = Piwik_GetWidgetsList();
        Piwik_WidgetsList::_reset();

        // there should be 12 main categories
        $this->assertEquals(12, count($widgets));

        // check if each category has the right number of widgets
        $numberOfWidgets = array(
            'Goals_Goals'     => 2,
            'Goals_Ecommerce' => 5,
        );

        foreach ($numberOfWidgets AS $category => $widgetCount) {
            $this->assertEquals($widgetCount, count($widgets[$category]));
        }
    }


}