diff options
-rw-r--r-- | plugins/CoreHome/Tracker/VisitRequestProcessor.php | 2 | ||||
-rw-r--r-- | tests/PHPUnit/Integration/Tracker/SettingsTest.php | 90 | ||||
-rw-r--r-- | tests/PHPUnit/Integration/Tracker/Visit2Test.php | 45 | ||||
-rw-r--r-- | tests/PHPUnit/Integration/Tracker/VisitTest.php | 2 |
4 files changed, 83 insertions, 56 deletions
diff --git a/plugins/CoreHome/Tracker/VisitRequestProcessor.php b/plugins/CoreHome/Tracker/VisitRequestProcessor.php index 792436f935..f33c899118 100644 --- a/plugins/CoreHome/Tracker/VisitRequestProcessor.php +++ b/plugins/CoreHome/Tracker/VisitRequestProcessor.php @@ -22,6 +22,8 @@ use Piwik\Tracker\VisitorRecognizer; /** * Encapsulates core tracking logic related to visits. + * + * TODO: much of the logic in this class should be moved to new service class */ class VisitRequestProcessor extends RequestProcessor { diff --git a/tests/PHPUnit/Integration/Tracker/SettingsTest.php b/tests/PHPUnit/Integration/Tracker/SettingsTest.php index fc008467a4..6078cd3b52 100644 --- a/tests/PHPUnit/Integration/Tracker/SettingsTest.php +++ b/tests/PHPUnit/Integration/Tracker/SettingsTest.php @@ -39,10 +39,13 @@ class SettingsTest extends IntegrationTestCase public function test_getConfigId_isSame() { - $settings1 = $this->makeSettings(array('idsite' => 1)); - $settings2 = $this->makeSettings(array('idsite' => 1)); + $request1 = $this->makeRequest(array('idsite' => 1)); + $settings1 = $this->makeSettings(); - $this->assertEquals($settings1->getConfigId(), $settings2->getConfigId()); + $request2 = $this->makeRequest(array('idsite' => 1)); + $settings2 = $this->makeSettings(); + + $this->assertEquals($settings1->getConfigId($request1, $this->ip), $settings2->getConfigId($request2, $this->ip)); } @@ -50,44 +53,59 @@ class SettingsTest extends IntegrationTestCase { $isSameFingerprintAcrossWebsites = true; - $settingsSite1 = $this->makeSettings(array('idsite' => 1), $isSameFingerprintAcrossWebsites); - $settingsSite2 = $this->makeSettings(array('idsite' => 2), $isSameFingerprintAcrossWebsites); + $request1 = $this->makeRequest(array('idsite' => 1)); + $settingsSite1 = $this->makeSettings($isSameFingerprintAcrossWebsites); + + $request2 = $this->makeRequest(array('idsite' => 2)); + $settingsSite2 = $this->makeSettings($isSameFingerprintAcrossWebsites); - $this->assertEquals($settingsSite1->getConfigId(), $settingsSite2->getConfigId()); + $this->assertEquals($settingsSite1->getConfigId($request1, $this->ip), $settingsSite2->getConfigId($request2, $this->ip)); } public function test_getConfigId_isDifferent_whenConfiguredUserHasDifferentFingerprintAcrossWebsites() { $isSameFingerprintAcrossWebsites = false; - $settingsSite1 = $this->makeSettings(array('idsite' => 1), $isSameFingerprintAcrossWebsites); - $settingsSite2 = $this->makeSettings(array('idsite' => 2), $isSameFingerprintAcrossWebsites); + $request1 = $this->makeRequest(array('idsite' => 1)); + $settingsSite1 = $this->makeSettings($isSameFingerprintAcrossWebsites); - $this->assertNotSame($settingsSite1->getConfigId(), $settingsSite2->getConfigId()); + $request2 = $this->makeRequest(array('idsite' => 2)); + $settingsSite2 = $this->makeSettings($isSameFingerprintAcrossWebsites); + + $this->assertNotSame($settingsSite1->getConfigId($request1, $this->ip), $settingsSite2->getConfigId($request2, $this->ip)); } public function test_getConfigId_isSame_whenBrowserSamebutDifferentUserAgent() { - $settingsFirefox = $this->makeSettings(array('ua' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10; rv:33.0) Gecko/20100101 Firefox/33.0')); - $settingsSlightlyDifferentUserAgent = $this->makeSettings(array('ua' => 'Mozilla/5.0 (Macintosh; Extra; string; here; Hello; world; Intel Mac OS X 10_10; rv:33.0) Gecko/20100101 Firefox/33.0')); + $request1 = $this->makeRequest(array('ua' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10; rv:33.0) Gecko/20100101 Firefox/33.0')); + $settingsFirefox = $this->makeSettings(); + + $request2 = $this->makeRequest(array('ua' => 'Mozilla/5.0 (Macintosh; Extra; string; here; Hello; world; Intel Mac OS X 10_10; rv:33.0) Gecko/20100101 Firefox/33.0')); + $settingsSlightlyDifferentUserAgent = $this->makeSettings(); - $this->assertSame($settingsSlightlyDifferentUserAgent->getConfigId(), $settingsFirefox->getConfigId()); + $this->assertSame($settingsSlightlyDifferentUserAgent->getConfigId($request1, $this->ip), $settingsFirefox->getConfigId($request2, $this->ip)); } public function test_getConfigId_isDifferent_whenBrowserChanges() { - $settingsFirefox = $this->makeSettings(array('ua' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10; rv:33.0) Gecko/20100101 Firefox/33.0')); - $settingsChrome = $this->makeSettings(array('ua' => 'Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Mobile Safari/535.19 ')); + $request1 = $this->makeRequest(array('ua' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10; rv:33.0) Gecko/20100101 Firefox/33.0')); + $settingsFirefox = $this->makeSettings(); - $this->assertNotSame($settingsChrome->getConfigId(), $settingsFirefox->getConfigId()); + $request2 = $this->makeRequest(array('ua' => 'Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Mobile Safari/535.19 ')); + $settingsChrome = $this->makeSettings(); + + $this->assertNotSame($settingsChrome->getConfigId($request1, $this->ip), $settingsFirefox->getConfigId($request2, $this->ip)); } public function test_getConfigId_isDifferent_whenOSChanges() { - $settingsFirefoxMac = $this->makeSettings(array('ua' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10; rv:33.0) Gecko/20100101 Firefox/33.0')); - $settingsFirefoxLinux = $this->makeSettings(array('ua' => 'Mozilla/5.0 (Linux; rv:33.0) Gecko/20100101 Firefox/33.0')); + $request1 = $this->makeRequest(array('ua' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10; rv:33.0) Gecko/20100101 Firefox/33.0')); + $settingsFirefoxMac = $this->makeSettings(); + + $request2 = $this->makeRequest(array('ua' => 'Mozilla/5.0 (Linux; rv:33.0) Gecko/20100101 Firefox/33.0')); + $settingsFirefoxLinux = $this->makeSettings(); - $this->assertNotSame($settingsFirefoxLinux->getConfigId(), $settingsFirefoxMac->getConfigId()); + $this->assertNotSame($settingsFirefoxLinux->getConfigId($request1, $this->ip), $settingsFirefoxMac->getConfigId($request2, $this->ip)); } public function test_getConfigId_isDifferent_whenPluginChanges() @@ -98,50 +116,52 @@ class SettingsTest extends IntegrationTestCase 'fla' => 0, 'idsite' => 1, ); - $settingsWithoutFlash = $this->makeSettings($params); + $request1 = $this->makeRequest($params); + $settingsWithoutFlash = $this->makeSettings(); // activate flash $params['fla'] = 1; + $request2 = $this->makeRequest($params); $settingsWithFlash = $this->makeSettings($params); - $this->assertNotSame($settingsWithoutFlash->getConfigId(), $settingsWithFlash->getConfigId()); + $this->assertNotSame($settingsWithoutFlash->getConfigId($request1, $this->ip), $settingsWithFlash->getConfigId($request2, $this->ip)); } public function test_getConfigId_isDifferent_whenIPIsAnonimised() { - $settingsIpIsNotAnon = $this->makeSettings(array(), true, '125.1.55.55'); - $settingsIpIsAnon = $this->makeSettings(array(), true, '125.1.0.0'); + $request1 = $this->makeRequest(array()); + $settingsIpIsNotAnon = $this->makeSettings(true); - $this->assertNotSame($settingsIpIsNotAnon->getConfigId(), $settingsIpIsAnon->getConfigId()); + $request2 = $this->makeRequest(array()); + $settingsIpIsAnon = $this->makeSettings(true); + + $this->assertNotSame($settingsIpIsNotAnon->getConfigId($request1, '125.1.55.55'), $settingsIpIsAnon->getConfigId($request2, '125.1.0.0')); } public function test_getConfigId_isSame_whenIPIsAnonimisedAndBothSame() { - $settingsIpIsAnon = $this->makeSettings(array(), true, '125.2.0.0'); - $settingsIpIsAnonBis = $this->makeSettings(array(), true, '125.2.0.0'); + $request1 = $this->makeRequest(array()); + $settingsIpIsAnon = $this->makeSettings(true); + + $request2 = $this->makeRequest(array()); + $settingsIpIsAnonBis = $this->makeSettings(true); - $this->assertSame($settingsIpIsAnonBis->getConfigId(), $settingsIpIsAnon->getConfigId()); + $this->assertSame($settingsIpIsAnonBis->getConfigId($request1, '125.2.0.0'), $settingsIpIsAnon->getConfigId($request2, '125.2.0.0')); } /** - * @param $params array * @param $isSameFingerprintAcrossWebsites - * @param $ip * @return Settings */ - protected function makeSettings($params, $isSameFingerprintAcrossWebsites = false, $ip = null) + protected function makeSettings($isSameFingerprintAcrossWebsites = false) { - if(is_null($ip)) { - $ip = $this->ip; - } - $requestSite1 = $this->makeRequest($params); - $settingsSite1 = new Settings($requestSite1, $ip, $isSameFingerprintAcrossWebsites); + $settingsSite1 = new Settings($isSameFingerprintAcrossWebsites); return $settingsSite1; } /** * @param $extraParams array - * @return array + * @return Request */ private function makeRequest($extraParams) { diff --git a/tests/PHPUnit/Integration/Tracker/Visit2Test.php b/tests/PHPUnit/Integration/Tracker/Visit2Test.php index 0be2b525d2..654226aa1b 100644 --- a/tests/PHPUnit/Integration/Tracker/Visit2Test.php +++ b/tests/PHPUnit/Integration/Tracker/Visit2Test.php @@ -15,7 +15,6 @@ use Piwik\Tracker\Request; use Piwik\Tracker\Visit; use Piwik\Tracker\Visitor; use Piwik\Piwik; -use Piwik\EventDispatcher; use Piwik\Tests\Framework\Fixture; use Piwik\Tests\Framework\TestCase\IntegrationTestCase; @@ -92,24 +91,24 @@ class FakeTrackerVisitDimension4 extends VisitDimension class FakeTrackerVisit extends Visit { - public function __construct($request) + public function __construct($request, Visit\VisitProperties $visitProperties) { parent::__construct(); $this->request = $request; - $this->visitProperties = new Visit\VisitProperties(); + $this->visitProperties = $visitProperties; $this->visitProperties->visitorInfo['location_ip'] = $request->getIp(); $this->visitProperties->visitorInfo['idvisitor'] = 1; } - public function handleExistingVisit($visitor, $action, $visitIsConverted) + public function handleExistingVisit($visitIsConverted) { - parent::handleExistingVisit($visitor, $action, $visitIsConverted); + parent::handleExistingVisit($visitIsConverted); } - public function handleNewVisit($visitor, $action, $visitIsConverted) + public function handleNewVisit($visitIsConverted) { - parent::handleNewVisit($visitor, $action, $visitIsConverted); + parent::handleNewVisit($visitIsConverted); } public function getAllVisitDimensions() @@ -154,10 +153,11 @@ class Visit2Test extends IntegrationTestCase public function test_handleNewVisitWithoutConversion_shouldTriggerDimensions() { $request = new Request(array()); - $visitor = new Visitor($request, '', new Visit\VisitProperties()); + $visitProperties = new Visit\VisitProperties(); + $visitor = new Visitor($request, $visitProperties); - $visit = new FakeTrackerVisit($request); - $visit->handleNewVisit($visitor, null, false); + $visit = new FakeTrackerVisit($request, $visitProperties); + $visit->handleNewVisit(false); $info = $visit->getVisitorInfo(); @@ -176,10 +176,11 @@ class Visit2Test extends IntegrationTestCase public function test_handleNewVisitWithConversion_shouldTriggerDimensions() { $request = new Request(array()); - $visitor = new Visitor($request, '', new Visit\VisitProperties()); + $visitProperties = new Visit\VisitProperties(); + $visitor = new Visitor($request, $visitProperties); - $visit = new FakeTrackerVisit($request); - $visit->handleNewVisit($visitor, null, true); + $visit = new FakeTrackerVisit($request, $visitProperties); + $visit->handleNewVisit(true); $info = $visit->getVisitorInfo(); @@ -194,11 +195,12 @@ class Visit2Test extends IntegrationTestCase public function test_handleExistingVisitWithoutConversion_shouldTriggerDimensions() { $request = new Request(array()); - $visitor = new Visitor($request, '', new Visit\VisitProperties()); + $visitProperties = new Visit\VisitProperties(); + $visitor = new Visitor($request, $visitProperties); - $visit = new FakeTrackerVisit($request); - $visit->handleNewVisit($visitor, null, false); - $visit->handleExistingVisit($visitor, null, false); + $visit = new FakeTrackerVisit($request, $visitProperties); + $visit->handleNewVisit(false); + $visit->handleExistingVisit(false); $info = $visit->getVisitorInfo(); @@ -217,11 +219,12 @@ class Visit2Test extends IntegrationTestCase public function test_handleExistingVisitWithConversion_shouldTriggerDimensions() { $request = new Request(array()); - $visitor = new Visitor($request, '', new Visit\VisitProperties()); + $visitProperties = new Visit\VisitProperties(); + $visitor = new Visitor($request, $visitProperties); - $visit = new FakeTrackerVisit($request); - $visit->handleNewVisit($visitor, null, false); - $visit->handleExistingVisit($visitor, null, true); + $visit = new FakeTrackerVisit($request, $visitProperties); + $visit->handleNewVisit(false); + $visit->handleExistingVisit(true); $info = $visit->getVisitorInfo(); diff --git a/tests/PHPUnit/Integration/Tracker/VisitTest.php b/tests/PHPUnit/Integration/Tracker/VisitTest.php index 83bd1a7e5c..c5aec2995c 100644 --- a/tests/PHPUnit/Integration/Tracker/VisitTest.php +++ b/tests/PHPUnit/Integration/Tracker/VisitTest.php @@ -26,6 +26,8 @@ use Piwik\Tracker\Visitor; /** * @group Core + * + * TODO: move isVisitNew tests to CoreHome plugin */ class VisitTest extends IntegrationTestCase { |