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

MetricsTest.php « Core « PHPUnit « tests - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 735905b0528c1bd963732f9bf2853ec3a2e522b8 (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
<?php
use Piwik\Access;
use Piwik\Metrics;

/**
 * Piwik - free/libre analytics platform
 *
 * @link http://piwik.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */
class Core_MetricsTest extends PHPUnit_Framework_TestCase
{
    /**
     * @group Core
     */
    public function testGetVisitsMetricNames()
    {
        $names = Metrics::getVisitsMetricNames();
        $expectedNames = array(
            1 => 'nb_uniq_visitors',
            2 => 'nb_visits',
            3 => 'nb_actions',
            4 => 'max_actions',
            5 => 'sum_visit_length',
            6 => 'bounce_count',
            7 => 'nb_visits_converted',
        );
        $this->assertEquals($expectedNames, $names);
    }

    /**
     * @group Core
     */
    public function testGetMappingFromIdToName()
    {
        $mapping = Metrics::getMappingFromIdToName();
        $expectedMapping = array(
            'nb_uniq_visitors' => 1,
            'nb_visits' => 2,
            'nb_actions' => 3,
            'max_actions' => 4,
            'sum_visit_length' => 5,
            'bounce_count' => 6,
            'nb_visits_converted' => 7,
            'nb_conversions' => 8,
            'revenue' => 23,
            'goals' => 10,
            'sum_daily_nb_uniq_visitors' => 11,
            'nb_hits' => 12,
            'sum_time_spent' => 13,
            'sum_time_generation' => 30,
            'nb_hits_with_time_generation' => 31,
            'min_time_generation' => 32,
            'max_time_generation' => 33,
            'exit_nb_uniq_visitors' => 14,
            'exit_nb_visits' => 15,
            'sum_daily_exit_nb_uniq_visitors' => 16,
            'entry_nb_uniq_visitors' => 17,
            'sum_daily_entry_nb_uniq_visitors' => 18,
            'entry_nb_visits' => 19,
            'entry_nb_actions' => 20,
            'entry_sum_visit_length' => 21,
            'entry_bounce_count' => 22,
            'nb_hits_following_search' => 29,
            'quantity' => 24,
            'price' => 25,
            'price_viewed' => 27,
            'orders' => 26,
            'nb_events' => 34,
            'sum_event_value' => 35,
            'min_event_value' => 36,
            'max_event_value' => 37,
            'nb_events_with_value' => 38,
        );
        $this->assertEquals($expectedMapping, $mapping);
    }

    public function getLowerValuesBetter()
    {
        return array(
            array('bounce', true),
            array('exit', true),
            array('', false),
            array('price', false),
        );
    }

    /**
     * @dataProvider getLowerValuesBetter
     * @group Core
     */
    public function testIsLowerValueBetter($column, $expected)
    {
        $actual = Metrics::isLowerValueBetter($column);
        $this->assertEquals($expected, $actual);
    }

    public function getUnitColumns()
    {
        return array(
            array('avg_time_on_page', 's'),
            array('sum_time_spent', 's'),
            array('conversion_rate', '%'),
            array('revenue', '€'),
            array('nb_visits', ''),
        );
    }

    /**
     * @dataProvider getUnitColumns
     * @group Core
     */
    public function testGetUnit($column, $expected)
    {
        \Piwik\Site::setSites(array(
            1 => array('name' => 'TestSite', 'currency' => 'EUR')
        ));

        $pseudoMockAccess = new FakeAccess;
        FakeAccess::$superUser = true;
        Access::setSingletonInstance($pseudoMockAccess);

        $actual = Metrics::getUnit($column, 1);
        $this->assertEquals($expected, $actual);
    }

}