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

ControllerTest.php « Integration « tests « MultiSites « plugins - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: dd54beefad67a822309b980c2b41746d2d2407df (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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?php
/**
 * Matomo - free/libre analytics platform
 *
 * @link https://matomo.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */

namespace Piwik\Plugins\MultiSites\tests\Integration;

use Piwik\FrontController;
use Piwik\Plugins\MultiSites\tests\Fixtures\ManySitesWithVisits;
use Piwik\Tests\Framework\TestCase\SystemTestCase;

/**
 * @group MultiSites
 * @group ControllerTest
 * @group Plugins
 */
class ControllerTest extends SystemTestCase
{
    /**
     * @var ManySitesWithVisits
     */
    public static $fixture = null; // initialized below class definition

    public function test_getAllWithGroups()
    {
        $sites = $this->requestGetAllWithGroups(array('filter_limit' => 20));
        $this->assertTrue(is_string($sites));

        $sites = json_decode($sites, true);

        // as limit is 20 make sure it returns all 15 sites but we do not check for all the detailed sites info,
        // this is tested in other tests. We only check for first site.
        $this->assertSame(15, count($sites['sites']));
        $this->assertEquals(array(
            'label' => 'Site 1',
            'nb_visits' => '2',
            'nb_actions' => '4',
            'nb_pageviews' => '3',
            'revenue' => '$2,541',
            'visits_evolution' => '100%',
            'actions_evolution' => '100%',
            'pageviews_evolution' => '100%',
            'revenue_evolution' => '100%',
            'idsite' => 1,
            'group' => '',
            'main_url' => 'http://piwik.net',
            'nb_conversions' => 1,
            'orders' => 1,
            'ecommerce_revenue' => 2541,
            'nb_conversions_evolution' => '100%',
            'orders_evolution' => '100%',
            'ecommerce_revenue_evolution' => '100%',
            'ratio' => 1,
            'previous_nb_visits' => 0,
            'periodName' => 'day',
            'previousRange' => 'Tue, Jan 22',
            'previous_nb_actions' => 0,
            'previous_Actions_nb_pageviews' => 0,
            'previous_Goal_revenue' => 0,
            'previous_Goal_nb_conversions' => 0,
            'previous_Goal_0_nb_conversions' => 0,
            'previous_Goal_0_revenue' => 0,
            'visits_evolution_trend' => 1,
            'actions_evolution_trend' => 1,
            'pageviews_evolution_trend' => 1,
            'revenue_evolution_trend' => 1,
            'nb_conversions_evolution_trend' => 1,
            'orders_evolution_trend' => 1,
            'ecommerce_revenue_evolution_trend' => 1,
            'currencySymbol' => '$',
        ), $sites['sites'][0]);

        unset($sites['sites']);
        $expected = array(
            'numSites' => 15,
            'totals' => array(
                'nb_pageviews' => 8,
                'nb_visits' => 5,
                'nb_actions' => 12,
                'revenue' => '5,082',
                'nb_visits_lastdate' => 0,
            ),
            'lastDate' => '2013-01-22'
        );

        $this->assertEquals($expected, $sites);
    }

    public function test_getAllWithGroups_ifLimitIsApplied_ShouldStill_ReturnCorrectNumberOfSitesAvailable()
    {
        $sites = $this->requestGetAllWithGroups(array('filter_limit' => 5));
        $sites = json_decode($sites, true);

        $this->assertSame(5, count($sites['sites']));
        $this->assertSame(15, $sites['numSites']);
        $this->assertReturnedSitesEquals(array(1, 2, 3, 4, 5), $sites);
    }

    public function test_getAllWithGroups_shouldBeAbleToHandleLimitAndOffset()
    {
        $sites = $this->requestGetAllWithGroups(array('filter_limit' => 5, 'filter_offset' => 4));
        $sites = json_decode($sites, true);

        $this->assertSame(5, count($sites['sites']));
        $this->assertSame(15, $sites['numSites']);
        $this->assertReturnedSitesEquals(array(5, 6, 7, 8, 9), $sites);
    }

    public function test_getAllWithGroups_shouldApplySearchAndReturnInNumSitesOnlyTheNumberOfMatchingSites()
    {
        $pattern = 'Site 1';
        $sites = $this->requestGetAllWithGroups(array('filter_limit' => 5, 'pattern' => $pattern));
        $sites = json_decode($sites, true);

        $this->assertSame(5, count($sites['sites']));
        $this->assertSame(1 + 6, $sites['numSites']); // Site 1 + Site10-15
        $this->assertReturnedSitesEquals(array(1, 10, 11, 12, 13), $sites);
    }

    private function assertReturnedSitesEquals($expectedSiteIds, $sites)
    {
        foreach ($expectedSiteIds as $index => $expectedSiteId) {
            $this->assertSame($expectedSiteId, $sites['sites'][$index]['idsite']);
        }
    }

    private function requestGetAllWithGroups($params)
    {
        $oldGet = $_GET;
        $params['period'] = 'day';
        $params['date']   = '2013-01-23';
        $_GET   = $params;
        $sites  = FrontController::getInstance()->dispatch('MultiSites', 'getAllWithGroups');
        $_GET   = $oldGet;
        return $sites;
    }

    public static function getOutputPrefix()
    {
        return '';
    }

    public static function getPathToTestDirectory()
    {
        return dirname(__FILE__);
    }

}

ControllerTest::$fixture = new ManySitesWithVisits();