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: 3c083130188f79e9203449a7fcb1d8bdd06078be (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
<?php
/**
 * Piwik - free/libre analytics platform
 *
 * @link http://piwik.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */
namespace Piwik\Tests\Fixtures;

use Piwik\Date;
use Piwik\Access;
use Piwik\Option;
use ReflectionClass;
use Piwik\Plugins\VisitsSummary\API as VisitsSummaryAPI;
use Piwik\Tests\Framework\Fixture;
use Piwik\Tests\Framework\OverrideLogin;

/**
 * This fixture is the combination of every other fixture defined by Piwik. Should be used
 * with year periods.
 */
class OmniFixture extends Fixture
{
    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();

    private function requireAllFixtures()
    {
        $fixturesToLoad = array(
            '/tests/PHPUnit/Fixtures/*.php',
            '/tests/UI/Fixtures/*.php',
            '/plugins/*/tests/Fixtures/*.php',
            '/plugins/*/Test/Fixtures/*.php',
        );

        foreach($fixturesToLoad as $fixturePath) {
            foreach (glob(PIWIK_INCLUDE_PATH . $fixturePath) as $file) {
                require_once $file;
            }
        }
    }

    /**
     * Constructor.
     */
    public function __construct()
    {
        $this->requireAllFixtures();

        $date = $this->month . '-01';

        $classes = get_declared_classes();
        sort($classes);

        foreach ($classes as $className) {
            if (is_subclass_of($className, 'Piwik\\Tests\\Framework\\Fixture')
                && !is_subclass_of($className, __CLASS__)
                && $className != __CLASS__
                && $className != "Piwik\\Tests\\Fixtures\\SqlDump"
                && $className != "Piwik\\Tests\\Fixtures\\UpdaterTestFixture"
                && $className != "Piwik\\Tests\\Fixtures\\UITestFixture"
            ) {

                $klassReflect = new ReflectionClass($className);
                if (!strpos($klassReflect->getFilename(), "tests/PHPUnit/Fixtures")
                    && $className != "CustomAlerts"
                    && $className != "Piwik\\Plugins\\Insights\\tests\\Fixtures\\SomeVisitsDifferentPathsOnTwoDays"
                    && $className != "Piwik\\Plugins\\Contents\\tests\\Fixtures\\TwoVisitsWithContents"
                ) {
                    continue;
                }

                $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['Piwik\\Tests\\Fixtures\\ManySitesImportedLogsWithXssAttempts']->now;

        // make sure ManySitesImportedLogsWithXssAttempts is the first fixture
        $fixture = $this->fixtures['Piwik\\Tests\\Fixtures\\ManySitesImportedLogsWithXssAttempts'];
        unset($this->fixtures['Piwik\\Tests\\Fixtures\\ManySitesImportedLogsWithXssAttempts']);
        $this->fixtures = array_merge(array('Piwik\\Tests\\Fixtures\\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 $fixture) {
            echo "Setting up " . get_class($fixture) . "...\n";

            $fixture->setUp();
        }

        Option::set("Tests.forcedNowTimestamp", $this->now->getTimestamp());

        // launch archiving so tests don't run out of time
        $date = Date::factory($this->dateTime)->toString();
        VisitsSummaryAPI::getInstance()->get($this->idSite, 'year', $date);
        VisitsSummaryAPI::getInstance()->get($this->idSite, 'year', $date, urlencode($this->segment));
    }

    public function tearDown()
    {
        foreach ($this->fixtures as $fixture) {
            echo "Tearing down " . get_class($fixture) . "...\n";

            $fixture->tearDown();
        }
    }
}