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

OmniFixture.php « Fixtures « PHPUnit « tests - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4c1c38236e2014913356556e0c3685862c0ee4a6 (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
<?php
/**
 * Piwik - Open source web analytics
 *
 * @link http://piwik.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */

use Piwik\Date;
use Piwik\Tracker\Visit;

/**
 * This fixture is the combination of every other fixture defined by Piwik. Should be used
 * with year periods.
 */
class Test_Piwik_Fixture_OmniFixture extends Test_Piwik_BaseFixture
{
    public $month = '2012-01';
    public $idSite = 'all';
    public $dateTime = '2012-02-01';
    public $now = null;
    public $segment = "browserCode==FF";

    // Visitor profile screenshot test needs visitor id
    public $visitorIdDeterministic = null;

    public $fixtures = array();

    /**
     * Constructor.
     */
    public function __construct()
    {
        $date = $this->month . '-01';

        $classes = get_declared_classes();
        foreach ($classes as $className) {
            if (is_subclass_of($className, 'Test_Piwik_BaseFixture')
                && $className != __CLASS__
            ) {
                $fixture = new $className();
                if (!property_exists($fixture, 'dateTime')) {
                    continue;
                }   

                $fixture->dateTime = $this->adjustDateTime($fixture->dateTime, $date);

                $this->fixtures[$className] = $fixture;

                $date = Date::factory($date)->addDay(1)->toString();
            }
        }

        $this->now = $this->fixtures['Test_Piwik_Fixture_ManySitesImportedLogsWithXssAttempts']->now;

        // make sure Test_Piwik_Fixture_ManySitesImportedLogsWithXssAttempts is the first fixture
        $fixture = $this->fixtures['Test_Piwik_Fixture_ManySitesImportedLogsWithXssAttempts'];
        unset($this->fixtures['Test_Piwik_Fixture_ManySitesImportedLogsWithXssAttempts']);
        $this->fixtures = array_merge(array('Test_Piwik_Fixture_ManySitesImportedLogsWithXssAttempts' => $fixture), $this->fixtures);
    }

    private function adjustDateTime($dateTime, $adjustToDate)
    {
        $parts = explode(' ', $dateTime);

        $result = $adjustToDate . ' ';
        $result .= isset($parts[1]) ? $parts[1] : '11:22:33';

        return $result;
    }

    public function setUp()
    {
        foreach ($this->fixtures as $name => $fixture) {
            $fixture->setUp();
        }

        $this->visitorIdDeterministic = bin2hex(\Piwik\Db::fetchOne(
            "SELECT idvisitor FROM " . \Piwik\Common::prefixTable('log_visit')
            . " WHERE idsite = 2 AND location_latitude IS NOT NULL LIMIT 1"));

    }

    public function tearDown()
    {
        foreach ($this->fixtures as $fixture) {
            $fixture->tearDown();
        }
    }
}