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

piwik.php « proxy « PHPUnit « tests - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 81356594105d2f7a1adbda167d05dcb3a847ed7a (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
<?php
/**
 *  Proxy to normal piwik.php, but in testing mode
 *
 *  - Use the tests database to record Tracking data
 *  - Allows to overwrite the Visitor IP, and Server datetime
 *
 */

use Piwik\Application\Environment;
use Piwik\DataTable\Manager;
use Piwik\Option;
use Piwik\Site;
use Piwik\Tests\Framework\TestingEnvironmentManipulator;
use Piwik\Tests\Framework\TestingEnvironmentVariables;
use Piwik\Tracker;

require realpath(dirname(__FILE__)) . "/includes.php";

// Wrapping the request inside ob_start() calls to ensure that the Test
// calling us waits for the full request to process before unblocking
ob_start();

try {
    $globalObservers = array(
        array('Environment.bootstrapped', function () {
            Tracker::setTestEnvironment();
            Manager::getInstance()->deleteAll();
            Option::clearCache();
            Site::clearCache();
        })
    );

    Environment::setGlobalEnvironmentManipulator(new TestingEnvironmentManipulator(new TestingEnvironmentVariables(), $globalObservers));

    include PIWIK_INCLUDE_PATH . '/matomo.php';
} catch (Exception $ex) {
    echo "Unexpected error during tracking: " . $ex->getMessage() . "\n" . $ex->getTraceAsString() . "\n";
}

if (ob_get_level() > 1) {
    ob_end_flush();
}