Skip to content
Extraits de code Groupes Projets
Valider 064f14ca rédigé par Benaka Moorthi's avatar Benaka Moorthi
Parcourir les fichiers

Fixing Core/Tracker/VisitTest test.

parent 8d1adbc7
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -14,11 +14,19 @@ ...@@ -14,11 +14,19 @@
*/ */
class Piwik_Tracker_VisitExcluded class Piwik_Tracker_VisitExcluded
{ {
public function __construct(Piwik_Tracker_Request $request, $ip) public function __construct(Piwik_Tracker_Request $request, $ip = false, $userAgent = false)
{ {
if ($ip === false) {
$ip = $request->getIp();
}
if ($userAgent === false) {
$userAgent = $request->getUserAgent();
}
$this->request = $request; $this->request = $request;
$this->idSite = $request->getIdSite(); $this->idSite = $request->getIdSite();
$this->userAgent = $request->getUserAgent(); $this->userAgent = $userAgent;
$this->ip = $ip; $this->ip = $ip;
} }
......
...@@ -69,15 +69,17 @@ class Tracker_VisitTest extends DatabaseTestCase ...@@ -69,15 +69,17 @@ class Tracker_VisitTest extends DatabaseTestCase
*/ */
public function testIsVisitorIpExcluded($excludedIp, $tests) public function testIsVisitorIpExcluded($excludedIp, $tests)
{ {
$visit = new Test_Piwik_TrackerVisit_public();
$idsite = Piwik_SitesManager_API::getInstance()->addSite("name", "http://piwik.net/", $ecommerce = 0, $idsite = Piwik_SitesManager_API::getInstance()->addSite("name", "http://piwik.net/", $ecommerce = 0,
$siteSearch = 1, $searchKeywordParameters = null, $searchCategoryParameters = null, $excludedIp); $siteSearch = 1, $searchKeywordParameters = null, $searchCategoryParameters = null, $excludedIp);
$visit->setRequest(array('idsite' => $idsite));
$request = new Piwik_Tracker_Request(array('idsite' => $idsite));
// test that IPs within the range, or the given IP, are excluded // test that IPs within the range, or the given IP, are excluded
foreach ($tests as $ip => $expected) { foreach ($tests as $ip => $expected) {
$testIpIsExcluded = Piwik_IP::P2N($ip); $testIpIsExcluded = Piwik_IP::P2N($ip);
$this->assertSame($expected, $visit->public_isVisitorIpExcluded($testIpIsExcluded));
$excluded = new Test_Piwik_Tracker_VisitExcluded_public($request, $testIpIsExcluded);
$this->assertSame($expected, $excluded->public_isVisitorIpExcluded($testIpIsExcluded));
} }
} }
...@@ -116,21 +118,23 @@ class Tracker_VisitTest extends DatabaseTestCase ...@@ -116,21 +118,23 @@ class Tracker_VisitTest extends DatabaseTestCase
{ {
Piwik_SitesManager_API::getInstance()->setSiteSpecificUserAgentExcludeEnabled(true); Piwik_SitesManager_API::getInstance()->setSiteSpecificUserAgentExcludeEnabled(true);
$visit = new Test_Piwik_TrackerVisit_public();
$idsite = Piwik_SitesManager_API::getInstance()->addSite("name", "http://piwik.net/", $ecommerce = 0, $idsite = Piwik_SitesManager_API::getInstance()->addSite("name", "http://piwik.net/", $ecommerce = 0,
$siteSearch = 1, $searchKeywordParameters = null, $searchCategoryParameters = null, $excludedIp = null, $siteSearch = 1, $searchKeywordParameters = null, $searchCategoryParameters = null, $excludedIp = null,
$excludedQueryParameters = null, $timezone = null, $currency = null, $group = null, $startDate = null, $excludedQueryParameters = null, $timezone = null, $currency = null, $group = null, $startDate = null,
$excludedUserAgent); $excludedUserAgent);
$visit->setRequest(array('idsite' => $idsite));
$request = new Piwik_Tracker_Request(array('idsite' => $idsite));
// test that user agents that contain excluded user agent strings are excluded // test that user agents that contain excluded user agent strings are excluded
foreach ($tests as $ua => $expected) { foreach ($tests as $ua => $expected) {
$this->assertSame($expected, $visit->public_isUserAgentExcluded($ua), "Result if isUserAgentExcluded('$ua') was not " . ($expected ? 'true' : 'false') . "."); $excluded = new Test_Piwik_Tracker_VisitExcluded_public($request, $ip = false, $ua);
$this->assertSame($expected, $excluded->public_isUserAgentExcluded($ua), "Result if isUserAgentExcluded('$ua') was not " . ($expected ? 'true' : 'false') . ".");
} }
} }
} }
class Test_Piwik_TrackerVisit_public extends Piwik_Tracker_Visit class Test_Piwik_Tracker_VisitExcluded_public extends Piwik_Tracker_VisitExcluded
{ {
public function public_isVisitorIpExcluded($ip) public function public_isVisitorIpExcluded($ip)
{ {
......
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