Newer
Older
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
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
* @version $Id: $
*/
/**
* Tests the log importer.
*/
class Test_Piwik_Integration_ImportLogs extends IntegrationTestCase
{
protected static $dateTime = '2010-03-06 11:22:33';
protected static $idSite = 1;
protected static $idGoal = null;
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
try {
self::setUpWebsitesAndGoals();
self::trackVisits();
} catch(Exception $e) {
// Skip whole test suite if an error occurs while setup
throw new PHPUnit_Framework_SkippedTestSuiteError($e->getMessage());
}
}
/**
* @dataProvider getApiForTesting
* @group Integration
* @group ImportLogs
*/
public function testApi($api, $params)
{
$this->runApiTests($api, $params);
}
public function getApiForTesting()
{
return array(
array('all', array('idSite' => self::$idSite,
'date' => '2012-08-09',
'periods' => 'month')),
);
}
public function getOutputPrefix()
{
return 'ImportLogs';
}
public static function setUpWebsitesAndGoals()
{
// for conversion testing
self::createWebsite(self::$dateTime);
self::$idGoal = Piwik_Goals_API::getInstance()->addGoal(
self::$idSite, 'all', 'url', 'http', 'contains', false, 5);
}
/**
* Logs a couple visits for Aug 9, Aug 10, Aug 11 of 2012.
*/
protected static function trackVisits()
{
$pwd = Zend_Registry::get('config')->superuser->password;
if(strlen($pwd) != 32) $pwd = md5($pwd);
$token_auth = Piwik_UsersManager_API::getInstance()->getTokenAuth(Zend_Registry::get('config')->superuser->login, $pwd);
$python = Piwik_Common::isWindows() ? "C:\Python27\python.exe" : 'python';
$cmd = $python . ' "'
. PIWIK_INCLUDE_PATH.'/misc/log-analytics/import_logs.py" ' # script loc
// . '-ddd ' // debug
. '--url="'.self::getRootUrl().'tests/PHPUnit/proxy/" ' # proxy so that piwik uses test config files
. '--idsite='.self::$idSite.' '
. '--recorders=4 '
. '--enable-http-errors '
. '--enable-http-redirects '
. '--enable-static '
. '--enable-bots "'
. PIWIK_INCLUDE_PATH.'/tests/resources/fake_logs.log" ' # log file