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

ExternalScriptsTest.php « System « PHPUnit « tests - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 950f2bb9e601db9e1fb20d6c65ea016404563a36 (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
<?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\System;

use Piwik\DbHelper;
use Piwik\Tests\Framework\Fixture;
use Piwik\Tests\Framework\TestCase\SystemTestCase;

class ExternalScriptsTest extends SystemTestCase
{
    public static function setUpBeforeClass()
    {
        parent::setUpBeforeClass();

        DbHelper::createAnonymousUser();

        // the api_internal_call.php uses idSite=7, so we create 7 sites
        for ($i = 0; $i != 7; ++$i) {
            Fixture::createWebsite("2011-01-01 00:00:00", $ecommerce = 1, $siteName = "Site #$i");
        }

        // the script uses anonymous token auth, so give the anonymous user access
        \Piwik\Plugins\UsersManager\API::getInstance()->setUserAccess('anonymous', 'view', array(7));
    }

    public function test_ApiInternalCallScript_ExecutesCorrectly()
    {
        $output = $this->executeApiInternalCall();
        $expectedFileOutput = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<result />";
        $this->assertEquals($expectedFileOutput, $output);
    }

    private function executeApiInternalCall()
    {
        $proxyIncludeScript = PIWIK_INCLUDE_PATH . '/tests/PHPUnit/proxy/include_single_file.php';
        $apiInternalCallScript = PIWIK_INCLUDE_PATH . '/misc/others/api_internal_call.php';

        $command = "php '$proxyIncludeScript' '$apiInternalCallScript' 2>&1";
        return shell_exec($command);
    }
}