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

applied changes from [6792] to phpunit tests

git-svn-id: http://dev.piwik.org/svn/trunk@6799 59fd770c-687e-43c8-a1e3-f5a4ff64c105
parent 42a3e753
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
<?php
/**
* Tests the URL normalization.
*/
class Test_Piwik_Integration_UrlNormalization extends IntegrationTestCase
{
protected static $dateTime = '2010-03-06 11:22:33';
protected static $idSite = 1;
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 UrlNormalization
*/
public function testApi($api, $params)
{
$this->runApiTests($api, $params);
}
public function getApiForTesting()
{
$return = array();
$return[] = array('Actions.getPageUrls', array(
'testSuffix' => '_urls',
'idSite' => self::$idSite,
'date' => self::$dateTime,
));
$return[] = array('Actions.getPageTitles', array(
'testSuffix' => '_titles',
'idSite' => self::$idSite,
'date' => self::$dateTime,
));
$return[] = array('Actions.getPageUrls', array(
'testSuffix' => '_pagesSegmented',
'idSite' => self::$idSite,
'date' => self::$dateTime,
'segment' => 'pageUrl==https://WWw.example.org/foo/bar2.html',
));
$return[] = array('Actions.getPageUrls', array(
'testSuffix' => '_pagesSegmented',
'idSite' => self::$idSite,
'date' => self::$dateTime,
'segment' => 'pageUrl==example.org/foo/bar2.html',
));
$return[] = array('Actions.getPageUrls', array(
'testSuffix' => '_pagesSegmentedRef',
'idSite' => self::$idSite,
'date' => self::$dateTime,
'segment' => 'referrerUrl==http://www.google.com/search?q=piwik',
));
$return[] = array('Referers.getKeywordsForPageUrl', array(
'testSuffix' => '_keywords',
'idSite' => self::$idSite,
'date' => self::$dateTime,
'otherRequestParameters' => array(
'url' => 'http://WWW.example.org/foo/bar.html'
)
));
return $return;
}
/**
* @@depends testApi
* @group Integration
* @group UrlNormalization
*/
public function testCheckPostConditions()
{
$sql = "SELECT count(*) FROM " . Piwik_Common::prefixTable('log_action');
$count = Zend_Registry::get('db')->fetchOne($sql);
$expected = 9; // 4 urls + 5 titles
$this->assertEquals($expected, $count, "only $expected actions expected");
$sql = "SELECT name, url_prefix FROM " . Piwik_Common::prefixTable('log_action')
. " WHERE type = " . Piwik_Tracker_Action::TYPE_ACTION_URL
. " ORDER BY idaction ASC";
$urls = Zend_Registry::get('db')->fetchAll($sql);
$expected = array(
array('name' => 'example.org/foo/bar.html', 'url_prefix' => 0),
array('name' => 'example.org/foo/bar2.html', 'url_prefix' => 3),
array('name' => 'example.org/foo/bar3.html', 'url_prefix' => 1),
array('name' => 'example.org/foo/bar4.html', 'url_prefix' => 2)
);
$this->assertEquals($expected, $urls, "normalization went wrong");
}
public function getOutputPrefix()
{
return 'UrlNormalization';
}
protected static function setUpWebsitesAndGoals()
{
self::createWebsite(self::$dateTime);
}
protected static function trackVisits()
{
$dateTime = self::$dateTime;
$idSite = self::$idSite;
$t = self::getTracker($idSite, $dateTime, $defaultInit = true, $useThirdPartyCookie = 1);
$t->setUrlReferrer('http://www.google.com/search?q=piwik');
$t->setUrl('http://example.org/foo/bar.html');
self::checkResponse($t->doTrackPageView('http://incredible.title/'));
$t->setUrl('https://example.org/foo/bar.html');
$t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.2)->getDatetime());
self::checkResponse($t->doTrackPageView('https://incredible.title/'));
$t->setUrl('https://wWw.example.org/foo/bar2.html');
$t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.3)->getDatetime());
self::checkResponse($t->doTrackPageView('http://www.incredible.title/'));
$t->setUrl('http://WwW.example.org/foo/bar2.html');
$t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.4)->getDatetime());
self::checkResponse($t->doTrackPageView('https://www.incredible.title/'));
$t->setUrl('http://www.example.org/foo/bar3.html');
$t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.5)->getDatetime());
self::checkResponse($t->doTrackPageView('incredible.title/'));
$t->setUrl('https://example.org/foo/bar4.html');
$t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.6)->getDatetime());
self::checkResponse($t->doTrackPageView('incredible.title/'));
}
}
......@@ -2,7 +2,7 @@
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
* @version $Id$
*/
......@@ -14,91 +14,116 @@ class ActionsTests extends PHPUnit_Framework_TestCase
{
Piwik_Translate::getInstance()->loadEnglishTranslation();
}
public function tearDown()
{
Piwik_Translate::getInstance()->unloadEnglishTranslation();
}
public function getActionNameTestData()
{
return array(
array(
'params' => array( 'name' => 'http://example.org/', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL),
'expected' => array('/index' ),
'params' => array('name' => 'http://example.org/', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL, 'urlPrefix' => null),
'expected' => array('/index'),
),
array(
'params' => array('name' => 'example.org/', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL, 'urlPrefix' => 1),
'expected' => array('/index'),
),
array(
'params' => array('name' => 'example.org/', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL, 'urlPrefix' => 2),
'expected' => array('/index'),
),
array(
'params' => array('name' => 'example.org/', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL, 'urlPrefix' => 3),
'expected' => array('/index'),
),
array(
'params' => array( 'name' => 'http://example.org/path/', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL),
'expected' => array( 'path', '/index' ),
'params' => array('name' => 'example.org/', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL, 'urlPrefix' => 4),
'expected' => array('/index'),
),
array(
'params' => array( 'name' => 'http://example.org/test/path', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL),
'expected' => array( 'test', '/path' ),
'params' => array('name' => 'example.org/path/', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL, 'urlPrefix' => 4),
'expected' => array('path', '/index'),
),
array(
'params' => array( 'name' => 'Test / Path', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL),
'expected' => array( 'Test', '/Path' ),
'params' => array('name' => 'example.org/test/path', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL, 'urlPrefix' => 1),
'expected' => array('test', '/path'),
),
array(
'params' => array( 'name' => ' Test trim ', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL),
'expected' => array( '/Test trim' ),
'params' => array('name' => 'http://example.org/path/', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL),
'expected' => array('path', '/index'),
),
array(
'params' => array( 'name' => 'Category / Subcategory', 'type' => Piwik_Tracker_Action::TYPE_ACTION_NAME),
'expected' => array( 'Category', ' Subcategory' ),
'params' => array('name' => 'example.org/test/path', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL, 'urlPrefix' => 1),
'expected' => array('test', '/path'),
),
array(
'params' => array( 'name' => '/path/index.php?var=test', 'type' => Piwik_Tracker_Action::TYPE_ACTION_NAME),
'expected' => array( 'path', ' index.php?var=test' ),
'params' => array('name' => 'Test / Path', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL),
'expected' => array('Test', '/Path'),
),
array(
'params' => array( 'name' => 'http://example.org/path/Default.aspx#anchor', 'type' => Piwik_Tracker_Action::TYPE_ACTION_NAME),
'expected' => array( 'path', ' Default.aspx' ),
'params' => array('name' => ' Test trim ', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL),
'expected' => array('/Test trim'),
),
array(
'params' => array( 'name' => '', 'type' => Piwik_Tracker_Action::TYPE_ACTION_NAME),
'expected' => array( 'Page Name not defined' ),
'params' => array('name' => 'Category / Subcategory', 'type' => Piwik_Tracker_Action::TYPE_ACTION_NAME),
'expected' => array('Category', ' Subcategory'),
),
array(
'params' => array( 'name' => '', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL),
'expected' => array( 'Page URL not defined' ),
'params' => array('name' => '/path/index.php?var=test', 'type' => Piwik_Tracker_Action::TYPE_ACTION_NAME),
'expected' => array('path', ' index.php?var=test'),
),
array(
'params' => array( 'name' => 'http://example.org/download.zip', 'type' => Piwik_Tracker_Action::TYPE_DOWNLOAD),
'expected' => array( 'example.org', '/download.zip' ),
'params' => array('name' => 'http://example.org/path/Default.aspx#anchor', 'type' => Piwik_Tracker_Action::TYPE_ACTION_NAME),
'expected' => array('path', ' Default.aspx'),
),
array(
'params' => array( 'name' => 'http://example.org/download/1/', 'type' => Piwik_Tracker_Action::TYPE_DOWNLOAD),
'expected' => array( 'example.org', '/download/1/' ),
'params' => array('name' => '', 'type' => Piwik_Tracker_Action::TYPE_ACTION_NAME),
'expected' => array('Page Name not defined'),
),
array(
'params' => array( 'name' => 'http://example.org/link', 'type' => Piwik_Tracker_Action::TYPE_OUTLINK),
'expected' => array( 'example.org', '/link' ),
'params' => array('name' => '', 'type' => Piwik_Tracker_Action::TYPE_ACTION_URL),
'expected' => array('Page URL not defined'),
),
array(
'params' => array( 'name' => 'http://example.org/some/path/', 'type' => Piwik_Tracker_Action::TYPE_OUTLINK),
'expected' => array( 'example.org', '/some/path/' ),
'params' => array('name' => 'http://example.org/download.zip', 'type' => Piwik_Tracker_Action::TYPE_DOWNLOAD),
'expected' => array('example.org', '/download.zip'),
),
array(
'params' => array('name' => 'http://example.org/download/1/', 'type' => Piwik_Tracker_Action::TYPE_DOWNLOAD),
'expected' => array('example.org', '/download/1/'),
),
array(
'params' => array('name' => 'http://example.org/link', 'type' => Piwik_Tracker_Action::TYPE_OUTLINK),
'expected' => array('example.org', '/link'),
),
array(
'params' => array('name' => 'http://example.org/some/path/', 'type' => Piwik_Tracker_Action::TYPE_OUTLINK),
'expected' => array('example.org', '/some/path/'),
),
);
}
/**
* @dataProvider getActionNameTestData
* @group Plugins
* @group Actions
* @group Plugins
* @group Actions
*/
public function testGetActionExplodedNames($params, $expected)
{
$action = new Test_Piwik_Actions_getActionExplodedNames();
$processed = $action->public_getActionExplodedNames($params['name'],$params['type']);
$processed = $action->public_getActionExplodedNames($params['name'], $params['type'], (isset($params['urlPrefix'])?$params['urlPrefix']:null));
$this->assertEquals($expected, $processed);
}
}
class Test_Piwik_Actions_getActionExplodedNames extends Piwik_Actions {
public function public_getActionExplodedNames($name, $type)
class Test_Piwik_Actions_getActionExplodedNames extends Piwik_Actions
{
public function public_getActionExplodedNames($name, $type, $urlPrefix)
{
return self::getActionExplodedNames($name, $type);
return self::getActionExplodedNames($name, $type, $urlPrefix);
}
}
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