Skip to content
Extraits de code Groupes Projets
Valider 92be0b5d rédigé par sgiehl's avatar sgiehl
Parcourir les fichiers

refs #3227 added first versions of some integration tests. there are still...

refs #3227 added first versions of some integration tests. there are still many things to be improved. in order to make them running correct the HTTP_HOST config needs to be changed in phpunit.xml. some of the tests aren't running because of encoding problems. I'll maybe have a look at that later

git-svn-id: http://dev.piwik.org/svn/trunk@6560 59fd770c-687e-43c8-a1e3-f5a4ff64c105
parent 73924d85
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
<?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$
*/
/**
* This tests the output of the API plugin API
* It will return metadata about all API reports from all plugins
* as well as the data itself, pre-processed and ready to be displayed
*/
class Test_Piwik_Integration_ApiGetReportMetadata extends IntegrationTestCase
{
protected $dateTime = '2009-01-04 00:11:42';
protected $idSite = 1;
protected $idGoal = 1;
protected $idGoal2 = 2;
protected $idGoal3 = 3;
public function setUp()
{
parent::setUp();
$this->createWebsite($this->dateTime, $ecommerce = 1);
Piwik_Goals_API::getInstance()->addGoal($this->idSite, 'Goal 1 - Thank you', 'title', 'Thank you', 'contains', $caseSensitive = false, $revenue = 10, $allowMultipleConversions = 1);
Piwik_Goals_API::getInstance()->addGoal($this->idSite, 'Goal 2 - Hello', 'url', 'hellow', 'contains', $caseSensitive = false, $revenue = 10, $allowMultipleConversions = 0);
Piwik_Goals_API::getInstance()->addGoal($this->idSite, 'triggered js', 'manually', '', '');
$this->trackVisits();
// From Piwik 1.5, we hide Goals.getConversions and other get* methods via @ignore, but we ensure that they still work
// This hack allows the API proxy to let us generate example URLs for the ignored functions
Piwik_API_Proxy::getInstance()->hideIgnoredFunctions = false;
}
public function getOutputPrefix()
{
return 'apiGetReportMetadata';
}
public function getApiForTesting()
{
return array(
array('API', array('idSite' => $this->idSite, 'date' => $this->dateTime))
);
}
/**
* @dataProvider getApiForTesting
* @group Integration
* @group ApiGetReportMetadata
*/
public function testApi($api, $params)
{
$this->runApiTests($api, $params);
}
protected function trackVisits()
{
$idSite = $this->idSite;
$dateTime = $this->dateTime;
$t = $this->getTracker($idSite, $dateTime, $defaultInit = true);
// Record 1st page view
$t->setUrl('http://example.org/index.htm');
$this->checkResponse($t->doTrackPageView('incredible title!'));
$t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.3)->getDatetime());
$this->checkResponse($t->doTrackGoal($this->idGoal3, $revenue = 42.256));
}
}
<?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$
*/
/**
* test the Yearly metadata API response,
* with no visits, with custom response language
*/
class Test_Piwik_Integration_ApiGetReportMetadata_Year extends IntegrationTestCase
{
protected $idSite = 1;
protected $dateTime = '2009-01-04 00:11:42';
public function setUp()
{
parent::setUp();
$this->createWebsite($this->dateTime);
}
public function getApiForTesting()
{
$params = array('idSite' => $this->idSite,
'date' => $this->dateTime,
'periods' => 'year',
'language' => 'fr');
return array(
array('API.getProcessedReport', $params),
array('API.getReportMetadata', $params),
array('LanguagesManager.getTranslationsForLanguage', $params),
array('LanguagesManager.getAvailableLanguageNames', $params),
array('SitesManager.getJavascriptTag', $params)
);
}
public function getOutputPrefix()
{
return 'apiGetReportMetadata_year';
}
/**
* @dataProvider getApiForTesting
* @group Integration
* @group ApiGetReportMetadata
* @group ApiGetReportMetadata_year
*/
public function testApi($api, $params)
{
$this->runApiTests($api, $params);
}
}
<?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$
*/
require_once dirname(__FILE__).'/TwoVisitsWithCustomVariablesTest.php';
/**
* Test CSV export with Expanded rows, Translated labels, Different languages
*/
class Test_Piwik_Integration_CsvExport extends Test_Piwik_Integration_TwoVisitsWithCustomVariables
{
protected $useEscapedQuotes = false;
protected $doExtraQuoteTests = false;
public function getApiForTesting()
{
$apiToCall = array('VisitsSummary.get', 'CustomVariables.getCustomVariables');
$enExtraParam = array('expanded' => 0, 'flat' => 1, 'include_aggregate_rows' => 0, 'translateColumnNames' => 1);
$deExtraParam = array('expanded' => 0, 'flat' => 1, 'include_aggregate_rows' => 1, 'translateColumnNames' => 1);
return array(
array($apiToCall, array('idSite' => $this->idSite,
'date' => $this->dateTime, 'format' => 'csv',
'otherRequestParameters' => array('expanded' => 0, 'flat' => 0),
'testSuffix' => '_xp0')),
array($apiToCall, array('idSite' => $this->idSite,
'date' => $this->dateTime,
'format' => 'csv',
'otherRequestParameters' => $enExtraParam,
'language' => 'en',
'testSuffix' => '_xp1_inner0_trans-en')),
array($apiToCall, array('idSite' => $this->idSite,
'date' => $this->dateTime,
'format' => 'csv',
'otherRequestParameters' => $deExtraParam,
'language' => 'de',
'testSuffix' => '_xp1_inner1_trans-de')),
);
}
/**
* @dataProvider getApiForTesting
* @group Integration
* @group CsvExport
*/
public function testApi($api, $params)
{
$this->runApiTests($api, $params);
}
public function getOutputPrefix()
{
return 'csvExport';
}
}
<?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 w/ two visits & custom variables.
*/
class Test_Piwik_Integration_TwoVisitsWithCustomVariables extends IntegrationTestCase
{
protected $dateTime = '2010-01-03 11:22:33';
protected $width = 1111;
protected $height = 222;
protected $idSite = 1;
protected $idGoal1 = 1;
protected $idGoal2 = 2;
protected $visitorId = null;
protected $useEscapedQuotes = true;
protected $doExtraQuoteTests = true;
public function getApiForTesting()
{
$apiToCall = array('VisitsSummary.get', 'CustomVariables.getCustomVariables');
$return = array(
array($apiToCall, array('idSite' => 'all',
'date' => $this->dateTime,
'periods' => array('day', 'week'),
'setDateLastN' => true)),
);
return $return;
}
/**
* @dataProvider getApiForTesting
* @group Integration
* @group TwoVisitsWithCustomVariables
*/
public function testApi($api, $params)
{
$this->runApiTests($api, $params);
}
public function getOutputPrefix()
{
return 'twoVisitsWithCustomVariables';
}
public function setUp()
{
parent::setUp();
// tests run in UTC, the Tracker in UTC
$this->createWebsite($this->dateTime);
Piwik_Goals_API::getInstance()->addGoal($this->idSite, 'triggered js', 'manually', '', '');
Piwik_Goals_API::getInstance()->addGoal($this->idSite, 'second goal', 'manually', '', '');
$this->trackVisits();
}
protected function trackVisits()
{
$dateTime = $this->dateTime;
$idSite = $this->idSite;
$idGoal = $this->idGoal1;
$idGoal2 = $this->idGoal2;
ob_start();
$visitorA = $this->getTracker($idSite, $dateTime, $defaultInit = true);
// Used to test actual referer + keyword position in Live!
$visitorA->setUrlReferrer(urldecode('http://www.google.com/url?sa=t&source=web&cd=1&ved=0CB4QFjAA&url=http%3A%2F%2Fpiwik.org%2F&rct=j&q=this%20keyword%20should%20be%20ranked&ei=V8WfTePkKKLfiALrpZWGAw&usg=AFQjCNF_MGJRqKPvaKuUokHtZ3VvNG9ALw&sig2=BvKAdCtNixsmfNWXjsNyMw'));
// no campaign, but a search engine to attribute the goal conversion to
$attribution = array(
'',
'',
1302306504,
'http://www.google.com/search?q=piwik&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-GB:official&client=firefox-a'
);
$visitorA->setAttributionInfo(json_encode($attribution));
$visitorA->setResolution($this->width, $this->height);
// At first, visitor custom var is set to LoggedOut
$visitorA->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.1)->getDatetime());
$visitorA->setUrl('http://example.org/homepage');
$visitorA->setCustomVariable($id = 1, $name = 'VisitorType', $value = 'LoggedOut');
$this->checkResponse($visitorA->doTrackPageView('Homepage'));
$this->checkResponse($visitorA->doTrackGoal($idGoal2, 0));
// After login, set to LoggedIn, should overwrite previous value
$visitorA->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.2)->getDatetime());
$visitorA->setUrl('http://example.org/user/profile');
$visitorA->setCustomVariable($id = 1, $name = 'VisitorType', $value = 'LoggedIn');
$visitorA->setCustomVariable($id = 4, $name = 'Status user', $value = 'Loggedin', $scope = 'page');
if ($this->useEscapedQuotes) {
$lookingAtProfile = 'looking at &quot;profile page&quot;';
} else {
$lookingAtProfile = 'looking at profile page';
}
$visitorA->setCustomVariable($id = 5, $name = 'Status user', $value = $lookingAtProfile, $scope = 'page');
$this->checkResponse($visitorA->doTrackPageView('Profile page'));
$visitorA->setCustomVariable($id = 2, $name = 'SET WITH EMPTY VALUE', $value = '');
$visitorA->setCustomVariable($id = 1, $name = 'Language', $value = 'FR', $scope = 'page');
$visitorA->setCustomVariable($id = 2, $name = 'SET WITH EMPTY VALUE PAGE SCOPE', $value = '', $scope = 'page');
$visitorA->setCustomVariable($id = 4, $name = 'Status user', $value = "looking at \"profile page\"", $scope = 'page');
$visitorA->setCustomVariable($id = 3, $name = 'Value will be VERY long and truncated', $value = 'abcdefghijklmnopqrstuvwxyz----abcdefghijklmnopqrstuvwxyz----abcdefghijklmnopqrstuvwxyz----abcdefghijklmnopqrstuvwxyz----abcdefghijklmnopqrstuvwxyz----abcdefghijklmnopqrstuvwxyz----abcdefghijklmnopqrstuvwxyz----abcdefghijklmnopqrstuvwxyz----abcdefghijklmnopqrstuvwxyz----abcdefghijklmnopqrstuvwxyz----abcdefghijklmnopqrstuvwxyz----abcdefghijklmnopqrstuvwxyz----abcdefghijklmnopqrstuvwxyz----abcdefghijklmnopqrstuvwxyz----abcdefghijklmnopqrstuvwxyz----abcdefghijklmnopqrstuvwxyz----abcdefghijklmnopqrstuvwxyz----abcdefghijklmnopqrstuvwxyz----');
$this->checkResponse($visitorA->doTrackPageView('Profile page for user *_)%'));
$this->checkResponse($visitorA->doTrackGoal($idGoal, 0));
if ($this->doExtraQuoteTests) {
$visitorA->setCustomVariable($id = 2, $name = 'var1', $value = 'looking at "profile page"',
$scope = 'page');
$visitorA->setCustomVariable($id = 3, $name = 'var2', $value = '\'looking at "\profile page"\'',
$scope = 'page');
$visitorA->setCustomVariable($id = 4, $name = 'var3', $value = '\\looking at "\profile page"\\',
$scope = 'page');
$this->checkResponse($visitorA->doTrackPageView('Concurrent page views'));
}
// -
// Second new visitor on Idsite 1: one page view
$visitorB = $this->getTracker($idSite, $dateTime, $defaultInit = true);
$visitorB->setUrlReferrer('');
$attribution = array(
' CAMPAIGN NAME -%20YEAH! ',
' CAMPAIGN%20KEYWORD - RIGHT... ',
1302306504,
'http://www.example.org/test/really?q=yes'
);
$visitorB->setAttributionInfo(json_encode($attribution));
$visitorB->setResolution($this->width, $this->height);
$visitorB->setUserAgent('Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6');
$visitorB->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(1)->getDatetime());
$visitorB->setCustomVariable($id = 1, $name = 'VisitorType', $value = 'LoggedOut');
$visitorB->setCustomVariable($id = 2, $name = 'Othercustom value which should be truncated abcdefghijklmnopqrstuvwxyz', $value = 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz');
$visitorB->setCustomVariable($id = -2, $name = 'not tracked', $value = 'not tracked');
$visitorB->setCustomVariable($id = 6, $name = 'not tracked', $value = 'not tracked');
$visitorB->setCustomVariable($id = 6, $name = array('not tracked'), $value = 'not tracked');
$visitorB->setUrl('http://example.org/homepage');
$this->checkResponse($visitorB->doTrackGoal($idGoal, 1000));
$visitorB->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(1.1)->getDatetime());
$this->checkResponse($visitorB->doTrackPageView('Homepage'));
// DIFFERENT test -
// testing that starting the visit with an outlink works (doesn't trigger errors)
$visitorB->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(2)->getDatetime());
$this->checkResponse($visitorB->doTrackAction('http://test.com', 'link'));
// hack
$this->visitorId = $visitorB->getVisitorId();
}
}
Ce diff est replié.
......@@ -29,7 +29,7 @@ require_once PIWIK_INCLUDE_PATH .'/core/testMinimumPhpVersion.php';
require_once PIWIK_INCLUDE_PATH .'/core/Loader.php';
require_once PIWIK_INCLUDE_PATH .'/core/FrontController.php';
require_once PIWIK_INCLUDE_PATH .'/tests/PHPUnit/DatabaseTestCase.php';
#require_once PIWIK_INCLUDE_PATH .'/tests/PHPUnit/IntegrationTestCase.php';
require_once PIWIK_INCLUDE_PATH .'/tests/PHPUnit/IntegrationTestCase.php';
require_once PIWIK_INCLUDE_PATH .'/tests/PHPUnit/FakeAccess.php';
// required to build code coverage for uncovered files
......
......@@ -45,7 +45,6 @@
<php>
<server name="HTTP_HOST" value="local"/>
<server name="PATH_INFO" value=""/>
<server name="REQUEST_URI" value="/piwik/tests/all_tests.php"/>
<server name="REMOTE_ADDR" value="127.0.0.1"/>
</php>
......
<?php
/**
* Proxy to normal piwik.php, but in testing mode
*
* - Use the tests database to record Tracking data
* - Allows to overwrite the Visitor IP, and Server datetime
*
* @see Main.test.php
*
*/
// Wrapping the request inside ob_start() calls to ensure that the Test
// calling us waits for the full request to process before unblocking
ob_start();
define('PIWIK_INCLUDE_PATH', '../..');
define('PIWIK_USER_PATH', PIWIK_INCLUDE_PATH);
require_once PIWIK_INCLUDE_PATH .'/libs/upgradephp/upgrade.php';
require_once PIWIK_INCLUDE_PATH .'/core/Loader.php';
// Config files forced to use the test database
// Note that this also provides security for Piwik installs containing tests files:
// this proxy will not record any data in the production database.
Piwik::createConfigObject();
Piwik_Config::getInstance()->setTestEnvironment();
Piwik_Config::getInstance()->PluginsInstalled['PluginsInstalled'] = array();
Piwik_Tracker::setTestEnvironment();
Piwik_Common::deleteTrackerCache();
include '../../piwik.php';
ob_flush();
......@@ -49,9 +49,11 @@ function dump($var)
print("</pre>");
}
function printDebug($text)
{
return;
if(!function_exists('printDebug')) {
function printDebug($text)
{
return;
}
}
require_once PIWIK_INCLUDE_PATH .'/core/Loader.php';
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter