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
|
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
use Piwik\Tests\Framework\Fixture;
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(200, $responseInfo["http_code"], 'Ok response');
$piwik_js = file_get_contents(PIWIK_PATH_TEST_TO_ROOT . '/piwik.js');
$this->assertEquals($piwik_js, $fullResponse, 'script content');
}
/**
* @group Core
*/
function testPiwikJsNoComment()
{
$curlHandle = curl_init();
curl_setopt($curlHandle, CURLOPT_URL, $this->getStaticSrvUrl() . '/js/tracker.php');
curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
$fullResponse = curl_exec($curlHandle);
$responseInfo = curl_getinfo($curlHandle);
curl_close($curlHandle);
$this->assertEquals(200, $responseInfo["http_code"], 'Ok response');
$piwikJs = file_get_contents(PIWIK_PATH_TEST_TO_ROOT . '/piwik.js');
$piwikNoCommentJs = substr($piwikJs, strpos($piwikJs, "*/\n") + 3);
$this->assertEquals($piwikNoCommentJs, $fullResponse, 'script content (if comment shows, $byteStart value in /js/tracker.php)');
}
/**
* @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(200, $responseInfo["http_code"], var_export($responseInfo, true));
$expected = "R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==";
$processed = base64_encode($fullResponse);
if ($expected != $processed) {
$this->markTestSkipped("testPiwikPhp invalid response content: " . $fullResponse);
}
$this->assertEquals(
$expected,
$processed,
'checking for image content' . "\n\n\n\nRaw content: \n\n\n" . $fullResponse
);
}
/**
* Helper methods
*/
private function getStaticSrvUrl()
{
return Fixture::getRootUrl();
}
}
|