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
|
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
/**
* @group Core
*/
class Core_TrackerTest extends DatabaseTestCase
{
public function setUp()
{
parent::setUp();
\Piwik\Piwik::setUserHasSuperUserAccess(true);
Fixture::createWebsite('2014-02-04');
}
protected function configureFixture()
{
$this->fixture->createSuperUser = true;
}
/**
* Test the Bulk tracking API as documented in: http://developer.piwik.org/api-reference/tracking-api#bulk-tracking
*
* With invalid token_auth the request would still work
*/
public function test_trackingApiWithBulkRequests_viaCurl_withWrongTokenAuth()
{
$token_auth = '33dc3f2536d3025974cccb4b4d2d98f4';
$this->issueBulkTrackingRequest($token_auth, $expectTrackingToSucceed = true);
}
public function test_trackingApiWithBulkRequests_viaCurl_withCorrectTokenAuth()
{
$token_auth = Fixture::getTokenAuth();
\Piwik\Filesystem::deleteAllCacheOnUpdate();
$this->issueBulkTrackingRequest($token_auth, $expectTrackingToSucceed = true);
}
protected function issueBulkTrackingRequest($token_auth, $expectTrackingToSucceed)
{
$piwikHost = Fixture::getRootUrl() . 'tests/PHPUnit/proxy/piwik.php';
$command = 'curl -s -X POST -d \'{"requests":["?idsite=1&url=http://example.org&action_name=Test bulk log Pageview&rec=1","?idsite=1&url=http://example.net/test.htm&action_name=Another bulk page view&rec=1"],"token_auth":"' . $token_auth . '"}\' ' . $piwikHost;
exec($command, $output, $result);
$output = implode("", $output);
if ($result !== 0) {
throw new Exception("tracking bulk failed: " . implode("\n", $output) . "\n\ncommand used: $command");
}
$this->assertStringStartsWith('{"status":', $output);
if($expectTrackingToSucceed) {
$this->assertNotContains('error', $output);
$this->assertContains('success', $output);
} else {
$this->assertContains('error', $output);
$this->assertNotContains('success', $output);
}
}
}
|