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: 7512beaad0239b0a443241bf2147cbf4fdca32da (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
<?php
/**
 * Piwik - Open source web analytics
 *
 * @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 ReflectionClass;

/**
 * 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();

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

        $classes = get_declared_classes();
        sort($classes);
        foreach ($classes as $className) {
            if (is_subclass_of($className, 'Fixture')
                && !is_subclass_of($className, __CLASS__)
                && $className != __CLASS__
                && $className != "Piwik_Test_Fixture_SqlDump"
                && $className != "Piwik\\Tests\\Fixtures\\UpdaterTestFixture"
            ) {
                $klassReflect = new ReflectionClass($className);
                if (!strpos($klassReflect->getFilename(), "tests/PHPUnit/Fixtures")
                    && $className != "Test_Piwik_Fixture_CustomAlerts"
                    && $className != "Piwik\\Plugins\\Insights\\tests\\Fixtures\\SomeVisitsDifferentPathsOnTwoDays"
                ) {
                    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['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();
        }
    }

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