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
|
<?php
/**
* Piwik - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Tests\Integration;
use Piwik\Tests\Framework\Fixture;
use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
/**
* @group Core
*/
class JsProxyTest extends IntegrationTestCase
{
public function setUp()
{
parent::setUp();
Fixture::createWebsite('2014-01-01 02:03:04');
}
public function testMatomoJs()
{
$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 . '/matomo.js');
$this->assertEquals($piwik_js, $fullResponse, 'script content');
}
public function testPiwik_WhiteLabelledJs_HasNoComment()
{
$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 . '/matomo.js');
$piwikNoCommentJs = substr($piwikJs, strpos($piwikJs, "*/\n") + 3);
$this->assertEquals($piwikNoCommentJs, trim($fullResponse), 'script content (if comment shows, $byteStart value in /js/tracker.php)');
}
public function testPiwikPhp()
{
if(IntegrationTestCase::isMysqli()) {
$this->markTestSkipped('Sometimes fails with 500 error');
}
$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) . $fullResponse);
$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();
}
}
|