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

RawLogDaoTest.php « System « PHPUnit « tests - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c8108972f9d49b0f4d7364221d9a4976e02a541b (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
<?php
/**
 * Piwik - free/libre analytics platform
 *
 * @link https://matomo.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */

namespace Piwik\Tests\System;

use Piwik\DataAccess\RawLogDao;
use Piwik\Tests\Framework\Fixture;
use Piwik\Tests\Framework\TestCase\SystemTestCase;

class CustomRawLogDao extends RawLogDao {

    public function getTableIdColumns()
    {
        return parent::getTableIdColumns();
    }

    public function getIdFieldForLogTable($logTable)
    {
        return parent::getIdFieldForLogTable($logTable);
    }

    public function getMaxIdsInLogTables()
    {
        return parent::getMaxIdsInLogTables();
    }
}

/**
 * @group Core
 * @group RawLogDao
 * @group RawLogDaoTest
 */
class RawLogDaoTest extends SystemTestCase
{
    /**
     * @var CustomRawLogDao
     */
    private $dao;

    private $idSite = 1;

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

        if (!Fixture::siteCreated($this->idSite)) {
            Fixture::createWebsite('2010-00-00 00:00:00');
        }

        $this->dao = new CustomRawLogDao();
    }

    /**
     * @dataProvider getVisitsInTimeFrameData
     */
    public function test_hasSiteVisitsInTimeframe_shouldDetectWhetherThereAreVisitsInCertainTimeframe($from, $to, $idSite, $expectedHasVisits)
    {
        Fixture::getTracker($this->idSite, '2015-01-25 05:35:27')->doTrackPageView('/test');

        $hasVisits = $this->dao->hasSiteVisitsBetweenTimeframe($from, $to, $idSite);
        $this->assertSame($expectedHasVisits, $hasVisits);
    }

    public function test_getIdColumns()
    {
        $expected = array(
            'log_action' => 'idaction',
            'log_conversion' => 'idvisit',
            'log_conversion_item' => 'idvisit',
            'log_link_visit_action' => 'idlink_va',
            'log_visit' => 'idvisit',
        );
        $this->assertSame($expected, $this->dao->getTableIdColumns());
    }

    public function test_getIdFieldForLogTable()
    {
        $this->assertSame('idaction', $this->dao->getIdFieldForLogTable('log_action'));
        $this->assertSame('idlink_va', $this->dao->getIdFieldForLogTable('log_link_visit_action'));
        $this->assertSame('idvisit', $this->dao->getIdFieldForLogTable('log_visit'));
    }

    /**
     * @expectedException \Exception
     * @expectedExceptionMessage Unknown log table 'log_foobarbaz'
     */
    public function test_getIdFieldForLogTable_whenUnknownTable()
    {
        $this->dao->getIdFieldForLogTable('log_foobarbaz');
    }

    public function test_getMaxIdsInLogTables()
    {
        $expected = array(
            'log_action' => '2',
            'log_conversion_item' => null,
            'log_conversion' => null,
            'log_link_visit_action' => '11',
            'log_visit' => '1',
        );
        $this->assertEquals($expected, $this->dao->getMaxIdsInLogTables());
    }

    public function getVisitsInTimeFrameData()
    {
        return array(
            array($from = '2015-01-25 05:35:26', $to = '2015-01-25 05:35:27', $this->idSite, $hasVisits = false), // there is no second "between" the timeframe so cannot have visits
            array($from = '2015-01-25 05:35:27', $to = '2015-01-25 05:35:28', $this->idSite, $hasVisits = false), // there is no second "between" the timeframe so cannot have visits
            array($from = '2015-01-25 05:35:26', $to = '2015-01-25 05:35:28', $this->idSite, $hasVisits = true), // only one sec difference between from and to
            array($from = '2015-01-25 05:35:26', $to = '2015-01-26 05:35:27', $this->idSite, $hasVisits = true),
            array($from = '2015-01-24 05:35:26', $to = '2015-01-26 05:35:27', $this->idSite, $hasVisits = true),
            array($from = '2015-01-25 05:35:26', $to = '2015-01-25 05:35:27', $idSite = 2, $hasVisits = false),  // no because idSite does not match
            array($from = '2015-01-24 05:35:26', $to = '2015-01-25 05:35:27', $idSite = 2, $hasVisits = false),  // ...
            array($from = '2015-01-25 05:35:26', $to = '2015-01-26 05:35:27', $idSite = 2, $hasVisits = false),  // ...
            array($from = '2015-01-24 05:35:26', $to = '2015-01-26 05:35:27', $idSite = 2, $hasVisits = false),  // ... no because not matching idsite
            array($from = '2015-01-24 05:35:26', $to = '2015-01-25 05:35:26', $this->idSite, $hasVisits = false), // time of visit is later
            array($from = '2015-01-25 05:35:28', $to = '2015-01-27 05:35:27', $this->idSite, $hasVisits = false),  // time of visit is earlier
        );
    }

}