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

JsProxyTest.php « Core « PHPUnit « tests - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7ec8d4ed258ee880b2b05be183136d9da28ffc3b (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
<?php
class Test_Piwik_JsProxy extends PHPUnit_Framework_TestCase
{
    /**
     * @group Core
     */
    function testPiwikJs()
    {
        $curlHandle = curl_init();
        curl_setopt($curlHandle, CURLOPT_URL, $this->getStaticSrvUrl() . '/js/');
        curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
        $fullResponse = curl_exec($curlHandle);
        $responseInfo = curl_getinfo($curlHandle);
        curl_close($curlHandle);

        $this->assertEquals($responseInfo["http_code"], 200, 'Ok response');

        $piwik_js = file_get_contents(PIWIK_PATH_TEST_TO_ROOT . '/piwik.js');
        $this->assertEquals($fullResponse, $piwik_js, 'script content');
    }

    /**
     * @group Core
     */
    function testPiwikPhp()
    {
        $curlHandle = curl_init();
        $url = $this->getStaticSrvUrl() . '/js/?idsite=1';
        curl_setopt($curlHandle, CURLOPT_URL, $url);
        curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
        $fullResponse = curl_exec($curlHandle);
        $responseInfo = curl_getinfo($curlHandle);
        curl_close($curlHandle);

        $this->assertEquals($responseInfo["http_code"], 200, 'Ok response');
        if ("R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" != base64_encode($fullResponse)) {
            \Piwik\Log::info("testPiwikPhp invalid response content: " . $fullResponse);
        }

        $this->assertEquals(
            "R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==",
            base64_encode($fullResponse),
            'checking for image content'
        );
    }

    /**
     * Helper methods
     */
    private function getStaticSrvUrl()
    {
        return Test_Piwik_BaseFixture::getRootUrl();
    }
}