Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorsgiehl <stefan@matomo.org>2020-07-24 14:11:05 +0300
committersgiehl <stefan@matomo.org>2020-07-24 15:28:48 +0300
commit679e73f1236969db0c2d767655cb84456a727d24 (patch)
tree648722fa79cb524f8819857e79163e0c1cf16d59 /tests
parent6b5f8138180716d5088d764f0b41d5787159b28a (diff)
parent3e1234a887f56a1cf853e29ba89370b234af5127 (diff)
Merge branch '3.x-dev' into 4.x-dev
Diffstat (limited to 'tests')
-rw-r--r--tests/PHPUnit/Integration/OptionTest.php33
-rw-r--r--tests/PHPUnit/Integration/Tracker/TrackerCodeGeneratorTest.php26
-rw-r--r--tests/PHPUnit/System/expected/test_Archive_InvalidationWebsite2_NewDataShouldAppear__Actions.getPageUrls_month.xml12
-rw-r--r--tests/PHPUnit/System/expected/test_ImportLogs_siteIdThree_TrackedUsingLogReplayWithFixedSiteId__Live.getLastVisitsDetails_range.xml2
-rw-r--r--tests/PHPUnit/System/expected/test_ManyVisitorsOneWebsiteTest_pageurlNotContainsSegment__Live.getLastVisitsDetails_month.xml2
-rw-r--r--tests/PHPUnit/System/expected/test_apiGetReportMetadata_year__SitesManager.getJavascriptTag.xml4
-rw-r--r--tests/PHPUnit/Unit/NonceTest.php6
-rw-r--r--tests/UI/expected-screenshots/EmptySite_emptySiteDashboard.png4
-rw-r--r--tests/UI/expected-screenshots/OneClickUpdate_login.png4
-rw-r--r--tests/UI/expected-screenshots/UIIntegrationTest_admin_manage_tracking_code.png4
-rw-r--r--tests/javascript/index.php80
11 files changed, 139 insertions, 38 deletions
diff --git a/tests/PHPUnit/Integration/OptionTest.php b/tests/PHPUnit/Integration/OptionTest.php
index b487f4f939..dfc279d7ba 100644
--- a/tests/PHPUnit/Integration/OptionTest.php
+++ b/tests/PHPUnit/Integration/OptionTest.php
@@ -175,4 +175,37 @@ class OptionTest extends IntegrationTestCase
Option::deleteLike("%\\_defaultReport");
$this->assertSame('0', Option::get('adefaultReport'));
}
+
+ public function testDeleteLike_underscoreNotWildcard()
+ {
+ // insert guard - to test unescaped underscore
+ Option::set('adefaultReport', '1', true);
+
+ Option::deleteLike("adefaul_Report"); // the underscore should not match a character
+ $this->assertSame('1', Option::get('adefaultReport'));
+ }
+
+ public function testGetLike()
+ {
+ Option::set('adefaultReport', '1', true);
+ Option::set('adefaultRepo', '1', true);
+ Option::set('adefaultRepppppppport', '1', true);
+
+ $values = Option::getLike("adefaultRepo%"); // the underscore should not match a character
+ $this->assertSame(array(
+ 'adefaultRepo' => '1',
+ 'adefaultReport' => '1'
+ ), $values);
+ }
+
+ public function testGetLike_underscoreNotWildcard()
+ {
+ // insert guard - to test unescaped underscore
+ Option::set('adefaultReport', '1', true);
+
+ $values = Option::getLike("adefaul_Report"); // the underscore should not match a character
+ $this->assertSame(array(), $values);
+ $values = Option::getLike("adefaul%Report");
+ $this->assertSame(array('adefaultReport' => '1'), $values);
+ }
}
diff --git a/tests/PHPUnit/Integration/Tracker/TrackerCodeGeneratorTest.php b/tests/PHPUnit/Integration/Tracker/TrackerCodeGeneratorTest.php
index e0d72dd5ae..47f6c5d54b 100644
--- a/tests/PHPUnit/Integration/Tracker/TrackerCodeGeneratorTest.php
+++ b/tests/PHPUnit/Integration/Tracker/TrackerCodeGeneratorTest.php
@@ -41,7 +41,7 @@ class TrackerCodeGeneratorTest extends IntegrationTestCase
$expected = "&lt;!-- Matomo --&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
- var _paq = window._paq || [];
+ var _paq = window._paq = window._paq || [];
/* tracker methods like &quot;setCustomDimension&quot; should be called before &quot;trackPageView&quot; */
_paq.push([\"setDocumentTitle\", document.domain + \"/\" + document.title]);
_paq.push([\"setCookieDomain\", \"*.localhost\"]);
@@ -62,7 +62,7 @@ class TrackerCodeGeneratorTest extends IntegrationTestCase
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '1']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
- g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
+ g.type='text/javascript'; g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
&lt;/script&gt;
&lt;noscript&gt;&lt;p&gt;&lt;img src=&quot;//piwik-server/piwik/matomo.php?idsite=1&amp;amp;rec=1&quot; style=&quot;border:0;&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;&lt;/noscript&gt;
@@ -80,7 +80,7 @@ class TrackerCodeGeneratorTest extends IntegrationTestCase
$expected = "&lt;!-- Matomo --&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
- var _paq = window._paq || [];
+ var _paq = window._paq = window._paq || [];
/* tracker methods like &quot;setCustomDimension&quot; should be called before &quot;trackPageView&quot; */
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
@@ -89,7 +89,7 @@ class TrackerCodeGeneratorTest extends IntegrationTestCase
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '1']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
- g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
+ g.type='text/javascript'; g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
&lt;/script&gt;
&lt;!-- End Matomo Code --&gt;
@@ -118,7 +118,7 @@ class TrackerCodeGeneratorTest extends IntegrationTestCase
$expected = "&lt;!-- Matomo --&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
- var _paq = window._paq || [];
+ var _paq = window._paq = window._paq || [];
/* tracker methods like &quot;setCustomDimension&quot; should be called before &quot;trackPageView&quot; */
_paq.push([\"setDocumentTitle\", document.domain + \"/\" + document.title]);" . ($this->hasCustomVariables() ? "
// you can set up to 5 custom variables for each visitor
@@ -136,7 +136,7 @@ class TrackerCodeGeneratorTest extends IntegrationTestCase
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '1']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
- g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
+ g.type='text/javascript'; g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
&lt;/script&gt;
&lt;!-- End Matomo Code --&gt;
@@ -165,7 +165,7 @@ class TrackerCodeGeneratorTest extends IntegrationTestCase
$expected = "&lt;!-- Matomo --&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
- var _paq = window._paq || [];
+ var _paq = window._paq = window._paq || [];
/* tracker methods like &quot;setCustomDimension&quot; should be called before &quot;trackPageView&quot; */
_paq.push([\"setDocumentTitle\", document.domain + \"/\" + document.title]);" . ($this->hasCustomVariables() ? "
// you can set up to 5 custom variables for each visitor
@@ -184,7 +184,7 @@ class TrackerCodeGeneratorTest extends IntegrationTestCase
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '1']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
- g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
+ g.type='text/javascript'; g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
&lt;/script&gt;
&lt;!-- End Matomo Code --&gt;
@@ -209,7 +209,7 @@ class TrackerCodeGeneratorTest extends IntegrationTestCase
$expected = "&lt;!-- Matomo --&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
- var _paq = window._paq || [];
+ var _paq = window._paq = window._paq || [];
/* tracker methods like &quot;setCustomDimension&quot; should be called before &quot;trackPageView&quot; */
_paq.push([\"setDocumentTitle\", document.domain + \"/\" + document.title]);
_paq.push(['trackPageView']);
@@ -246,7 +246,7 @@ class TrackerCodeGeneratorTest extends IntegrationTestCase
$expected = '&lt;!-- Matomo --&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
- var _paq = window._paq || [];
+ var _paq = window._paq = window._paq || [];
/* tracker methods like &quot;setCustomDimension&quot; should be called before &quot;trackPageView&quot; */
_paq.push(["setDocumentTitle", document.domain + "/" + document.title]);' . ($this->hasCustomVariables() ? '
// you can set up to 5 custom variables for each visitor
@@ -262,7 +262,7 @@ class TrackerCodeGeneratorTest extends IntegrationTestCase
_paq.push([\'setTrackerUrl\', u+\'matomo.php\']);
_paq.push([\'setSiteId\', \'1\']);
var d=document, g=d.createElement(\'script\'), s=d.getElementsByTagName(\'script\')[0];
- g.type=\'text/javascript\'; g.async=true; g.defer=true; g.src=u+\'matomo.js\'; s.parentNode.insertBefore(g,s);
+ g.type=\'text/javascript\'; g.async=true; g.src=u+\'matomo.js\'; s.parentNode.insertBefore(g,s);
})();
&lt;/script&gt;
&lt;!-- End Matomo Code --&gt;
@@ -280,7 +280,7 @@ class TrackerCodeGeneratorTest extends IntegrationTestCase
$expected = '&lt;!-- Matomo --&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
- var _paq = window._paq || [];
+ var _paq = window._paq = window._paq || [];
/* tracker methods like &quot;setCustomDimension&quot; should be called before &quot;trackPageView&quot; */
_paq.push([\'trackPageView\']);
_paq.push([\'enableLinkTracking\']);
@@ -289,7 +289,7 @@ class TrackerCodeGeneratorTest extends IntegrationTestCase
_paq.push([\'setTrackerUrl\', u+\'matomo.php\']);
_paq.push([\'setSiteId\', \'1\']);
var d=document, g=d.createElement(\'script\'), s=d.getElementsByTagName(\'script\')[0];
- g.type=\'text/javascript\'; g.async=true; g.defer=true; g.src=u+\'matomo.js\'; s.parentNode.insertBefore(g,s);
+ g.type=\'text/javascript\'; g.async=true; g.src=u+\'matomo.js\'; s.parentNode.insertBefore(g,s);
})();
&lt;/script&gt;
&lt;!-- End Matomo Code --&gt;
diff --git a/tests/PHPUnit/System/expected/test_Archive_InvalidationWebsite2_NewDataShouldAppear__Actions.getPageUrls_month.xml b/tests/PHPUnit/System/expected/test_Archive_InvalidationWebsite2_NewDataShouldAppear__Actions.getPageUrls_month.xml
index ba5fa49ea6..154dd2715e 100644
--- a/tests/PHPUnit/System/expected/test_Archive_InvalidationWebsite2_NewDataShouldAppear__Actions.getPageUrls_month.xml
+++ b/tests/PHPUnit/System/expected/test_Archive_InvalidationWebsite2_NewDataShouldAppear__Actions.getPageUrls_month.xml
@@ -34,7 +34,7 @@
<entry_nb_actions>18</entry_nb_actions>
<entry_sum_visit_length>2</entry_sum_visit_length>
<entry_bounce_count>0</entry_bounce_count>
- <sum_daily_nb_uniq_visitors>2</sum_daily_nb_uniq_visitors>
+ <sum_daily_nb_uniq_visitors>3</sum_daily_nb_uniq_visitors>
<sum_daily_entry_nb_uniq_visitors>2</sum_daily_entry_nb_uniq_visitors>
<avg_time_on_page>0</avg_time_on_page>
<bounce_rate>0%</bounce_rate>
@@ -51,7 +51,7 @@
<nb_hits_with_bandwidth>0</nb_hits_with_bandwidth>
<min_bandwidth />
<max_bandwidth />
- <sum_daily_nb_uniq_visitors>2</sum_daily_nb_uniq_visitors>
+ <sum_daily_nb_uniq_visitors>3</sum_daily_nb_uniq_visitors>
<avg_time_on_page>0</avg_time_on_page>
<bounce_rate>0%</bounce_rate>
<exit_rate>0%</exit_rate>
@@ -67,7 +67,7 @@
<nb_hits_with_bandwidth>0</nb_hits_with_bandwidth>
<min_bandwidth />
<max_bandwidth />
- <sum_daily_nb_uniq_visitors>1</sum_daily_nb_uniq_visitors>
+ <sum_daily_nb_uniq_visitors>2</sum_daily_nb_uniq_visitors>
<avg_time_on_page>0</avg_time_on_page>
<bounce_rate>0%</bounce_rate>
<exit_rate>0%</exit_rate>
@@ -101,7 +101,7 @@
<nb_hits_with_bandwidth>0</nb_hits_with_bandwidth>
<min_bandwidth />
<max_bandwidth />
- <sum_daily_nb_uniq_visitors>2</sum_daily_nb_uniq_visitors>
+ <sum_daily_nb_uniq_visitors>3</sum_daily_nb_uniq_visitors>
<avg_bandwidth>0</avg_bandwidth>
<avg_page_load_time>0</avg_page_load_time>
<avg_time_on_page>0</avg_time_on_page>
@@ -119,7 +119,7 @@
<nb_hits_with_bandwidth>0</nb_hits_with_bandwidth>
<min_bandwidth />
<max_bandwidth />
- <sum_daily_nb_uniq_visitors>2</sum_daily_nb_uniq_visitors>
+ <sum_daily_nb_uniq_visitors>3</sum_daily_nb_uniq_visitors>
<avg_bandwidth>0</avg_bandwidth>
<avg_page_load_time>0</avg_page_load_time>
<avg_time_on_page>0</avg_time_on_page>
@@ -155,7 +155,7 @@
<min_bandwidth />
<max_bandwidth />
<exit_nb_visits>2</exit_nb_visits>
- <sum_daily_nb_uniq_visitors>2</sum_daily_nb_uniq_visitors>
+ <sum_daily_nb_uniq_visitors>3</sum_daily_nb_uniq_visitors>
<sum_daily_exit_nb_uniq_visitors>2</sum_daily_exit_nb_uniq_visitors>
<avg_time_on_page>0</avg_time_on_page>
<bounce_rate>0%</bounce_rate>
diff --git a/tests/PHPUnit/System/expected/test_ImportLogs_siteIdThree_TrackedUsingLogReplayWithFixedSiteId__Live.getLastVisitsDetails_range.xml b/tests/PHPUnit/System/expected/test_ImportLogs_siteIdThree_TrackedUsingLogReplayWithFixedSiteId__Live.getLastVisitsDetails_range.xml
index 920abd9f87..cc59d5cde4 100644
--- a/tests/PHPUnit/System/expected/test_ImportLogs_siteIdThree_TrackedUsingLogReplayWithFixedSiteId__Live.getLastVisitsDetails_range.xml
+++ b/tests/PHPUnit/System/expected/test_ImportLogs_siteIdThree_TrackedUsingLogReplayWithFixedSiteId__Live.getLastVisitsDetails_range.xml
@@ -1806,7 +1806,7 @@
<idVisit>43</idVisit>
<visitIp>0.0.0.0</visitIp>
- <fingerprint>e8e54c258f211e0c</fingerprint>
+ <fingerprint>17d589ebdc2ca70b</fingerprint>
<actionDetails>
<row>
<type>action</type>
diff --git a/tests/PHPUnit/System/expected/test_ManyVisitorsOneWebsiteTest_pageurlNotContainsSegment__Live.getLastVisitsDetails_month.xml b/tests/PHPUnit/System/expected/test_ManyVisitorsOneWebsiteTest_pageurlNotContainsSegment__Live.getLastVisitsDetails_month.xml
index 01d74e6651..887c043ac5 100644
--- a/tests/PHPUnit/System/expected/test_ManyVisitorsOneWebsiteTest_pageurlNotContainsSegment__Live.getLastVisitsDetails_month.xml
+++ b/tests/PHPUnit/System/expected/test_ManyVisitorsOneWebsiteTest_pageurlNotContainsSegment__Live.getLastVisitsDetails_month.xml
@@ -1409,7 +1409,7 @@
<idVisit>27</idVisit>
<visitIp>2003:f6:93bf:26f:9ec7:a6ff:fe29:27df</visitIp>
- <fingerprint>b6f1d5120b2b15a2</fingerprint>
+ <fingerprint>47b25ed9972126db</fingerprint>
<actionDetails>
<row>
<type>action</type>
diff --git a/tests/PHPUnit/System/expected/test_apiGetReportMetadata_year__SitesManager.getJavascriptTag.xml b/tests/PHPUnit/System/expected/test_apiGetReportMetadata_year__SitesManager.getJavascriptTag.xml
index 17afa1ddc3..2ed83de275 100644
--- a/tests/PHPUnit/System/expected/test_apiGetReportMetadata_year__SitesManager.getJavascriptTag.xml
+++ b/tests/PHPUnit/System/expected/test_apiGetReportMetadata_year__SitesManager.getJavascriptTag.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<result>&lt;!-- Matomo --&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
- var _paq = window._paq || [];
+ var _paq = window._paq = window._paq || [];
/* tracker methods like &quot;setCustomDimension&quot; should be called before &quot;trackPageView&quot; */
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
@@ -10,7 +10,7 @@
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '1']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
- g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
+ g.type='text/javascript'; g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
&lt;/script&gt;
&lt;!-- End Matomo Code --&gt;
diff --git a/tests/PHPUnit/Unit/NonceTest.php b/tests/PHPUnit/Unit/NonceTest.php
index 46f1685503..9020257f31 100644
--- a/tests/PHPUnit/Unit/NonceTest.php
+++ b/tests/PHPUnit/Unit/NonceTest.php
@@ -24,9 +24,9 @@ class NonceTest extends \PHPUnit\Framework\TestCase
{
return array(
// HTTP_HOST => expected
- array('example.com', array('http://example.com', 'https://example.com')),
- array('example.com:80', array('http://example.com', 'https://example.com')),
- array('example.com:443', array('http://example.com', 'https://example.com')),
+ array('example.com', array('http://example.com', 'https://example.com', 'http://example.com:80', 'https://example.com:443', )),
+ array('example.com:80', array('http://example.com', 'https://example.com', 'http://example.com:80', 'https://example.com:80')),
+ array('example.com:443', array('http://example.com', 'https://example.com', 'https://example.com:443')),
array('example.com:8080', array('http://example.com', 'https://example.com', 'http://example.com:8080', 'https://example.com:8080')),
);
}
diff --git a/tests/UI/expected-screenshots/EmptySite_emptySiteDashboard.png b/tests/UI/expected-screenshots/EmptySite_emptySiteDashboard.png
index b0916a114a..5cb4e0c7c7 100644
--- a/tests/UI/expected-screenshots/EmptySite_emptySiteDashboard.png
+++ b/tests/UI/expected-screenshots/EmptySite_emptySiteDashboard.png
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
-oid sha256:c567275eb5dc4db269eae11f0e3db50efd4d9e274eca647a84e0e48043753fc7
-size 300986
+oid sha256:0216d21836034495908026a050a7806f849c473dfdffc7a2cbaaa4da589b0c69
+size 301455
diff --git a/tests/UI/expected-screenshots/OneClickUpdate_login.png b/tests/UI/expected-screenshots/OneClickUpdate_login.png
index 8bd34e7e7e..d8998e265b 100644
--- a/tests/UI/expected-screenshots/OneClickUpdate_login.png
+++ b/tests/UI/expected-screenshots/OneClickUpdate_login.png
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
-oid sha256:81ba1bdb476809879d37e8fc05cc4fc09225cfff24f3de7efc1c39181fd514d8
-size 268589
+oid sha256:e4aa7576288c90312d52fe0348812888283b4736bb41d34093d56a4d8c99f402
+size 268933
diff --git a/tests/UI/expected-screenshots/UIIntegrationTest_admin_manage_tracking_code.png b/tests/UI/expected-screenshots/UIIntegrationTest_admin_manage_tracking_code.png
index 3dde1b33bf..745a249b9d 100644
--- a/tests/UI/expected-screenshots/UIIntegrationTest_admin_manage_tracking_code.png
+++ b/tests/UI/expected-screenshots/UIIntegrationTest_admin_manage_tracking_code.png
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
-oid sha256:8bcaedd927c9fff0659e8f0f67b92106bb88cb5583608e5ef08761f2055dc3a6
-size 440607
+oid sha256:343e58c0da95c3430fd38a7a5b1924dc71ab1164d66743a32483925c6c37851f
+size 441065
diff --git a/tests/javascript/index.php b/tests/javascript/index.php
index bcc39a36f3..0753337864 100644
--- a/tests/javascript/index.php
+++ b/tests/javascript/index.php
@@ -47,6 +47,9 @@ function getContentToken() {
function getHeartbeatToken() {
return "<?php $token = md5(uniqid(mt_rand(), true)); echo $token; ?>";
}
+function getCookieConsentToken() {
+ return "<?php $token = md5(uniqid(mt_rand(), true)); echo $token; ?>";
+}
function getConsentToken() {
return "<?php $token = md5(uniqid(mt_rand(), true)); echo $token; ?>";
}
@@ -530,7 +533,9 @@ function PiwikTest() {
// we fix the line numbers so they match to the line numbers in ../../js/piwik.js
JSLINT.errors.forEach( function (item, index) {
- item.line += countOfLinesRemoved;
+ if (item) {
+ item.line += countOfLinesRemoved;
+ }
console.log(item);
});
@@ -2070,7 +2075,7 @@ function PiwikTest() {
});
test("API methods", function() {
- expect(111);
+ expect(118);
equal( typeof Piwik.addPlugin, 'function', 'addPlugin' );
equal( typeof Piwik.addPlugin, 'function', 'addTracker' );
@@ -2101,6 +2106,7 @@ function PiwikTest() {
equal( typeof tracker.resetUserId, 'function', 'resetUserId' );
equal( typeof tracker.setUserId, 'function', 'setUserId' );
equal( typeof tracker.setSiteId, 'function', 'setSiteId' );
+ equal( typeof tracker.setVisitorId, 'function', 'setVisitorId' );
equal( typeof tracker.setCustomData, 'function', 'setCustomData' );
equal( typeof tracker.getCustomData, 'function', 'getCustomData' );
equal( typeof tracker.setCustomRequestProcessing, 'function', 'setCustomRequestProcessing' );
@@ -2165,7 +2171,13 @@ function PiwikTest() {
equal( typeof tracker.disableQueueRequest, 'function', 'disableQueueRequest' );
equal( typeof tracker.setRequestQueueInterval, 'function', 'setRequestQueueInterval' );
equal( typeof tracker.disableCookies, 'function', 'disableCookies' );
+ equal( typeof tracker.setCookieConsentGiven, 'function', 'setCookieConsentGiven' );
+ equal( typeof tracker.areCookiesEnabled, 'function', 'areCookiesEnabled' );
equal( typeof tracker.deleteCookies, 'function', 'deleteCookies' );
+ equal( typeof tracker.requireCookieConsent, 'function', 'requireCookieConsent' );
+ equal( typeof tracker.getRememberedCookieConsent, 'function', 'getRememberedCookieConsent' );
+ equal( typeof tracker.rememberCookieConsentGiven, 'function', 'rememberCookieConsentGiven' );
+ equal( typeof tracker.forgetCookieConsentGiven, 'function', 'forgetCookieConsentGiven' );
// content
equal( typeof tracker.trackAllContentImpressions, 'function', 'trackAllContentImpressions' );
equal( typeof tracker.trackVisibleContentImpressions, 'function', 'trackVisibleContentImpressions' );
@@ -3115,7 +3127,7 @@ function PiwikTest() {
}
test("User ID and Visitor UUID", function() {
- expect(27);
+ expect(28);
deleteCookies();
var userIdString = 'userid@mydomain.org';
@@ -3141,6 +3153,11 @@ function PiwikTest() {
var visitorId = tracker.getVisitorId();
equal(visitorId, tracker.getVisitorId(), "Visitor ID is the same when called multiple times");
+ tracker.setVisitorId('invalid'); // invalid characters
+ tracker.setVisitorId('012345abc'); // too short
+ tracker.setVisitorId('');
+ equal(visitorId, tracker.getVisitorId(), "Visitor ID is not updated when invalid");
+
// Check that setting an empty user id will not change the visitor ID
var userId = '';
equal(userId, tracker.getUserId(), "by default user ID is set to empty string");
@@ -4810,7 +4827,7 @@ if ($mysql) {
});
test("Test API - consent", function() {
- expect(29);
+ expect(34);
var queue;
var tracker = Piwik.getTracker();
@@ -4820,8 +4837,12 @@ if ($mysql) {
strictEqual(tracker.getRememberedConsent(), null, "getConsentRequestsQueue, does not return consent cookie content as no consent given" );
strictEqual(tracker.hasConsent(), true, "hasConsent, assumes consent by default" );
- ok(!tracker.isConsentRequired(), 'by default consent is not required')
+ ok(!tracker.isConsentRequired(), 'by default consent is not required');
+ ok(tracker.areCookiesEnabled(), 'by default cookies are enabled');
tracker.requireConsent();
+ ok(!tracker.areCookiesEnabled(), 'require consent disables cookies');
+
+
ok(tracker.isConsentRequired(), 'consent is required after requiring it')
deepEqual(tracker.getConsentRequestsQueue(), [], "getConsentRequestsQueue, still empty after requiring consent" );
@@ -4841,7 +4862,10 @@ if ($mysql) {
strictEqual(tracker.hasRememberedConsent(), false, "getConsentRequestsQueue, has not remembered consent" );
strictEqual(tracker.getRememberedConsent(), null, "getConsentRequestsQueue, does not return consent cookie content as no consent given" );
+ tracker.requireConsent();
+ ok(!tracker.areCookiesEnabled(), 'after requiring consent, cookies are disabled');
tracker.rememberConsentGiven();
+ ok(tracker.areCookiesEnabled(), 'remember cookie consent enables cookies');
strictEqual(tracker.hasRememberedConsent(), true, "rememberConsentGiven, sets cookie to remember consent" );
var rememberedConsent = tracker.getRememberedConsent();
@@ -4869,7 +4893,8 @@ if ($mysql) {
var results = fetchTrackedRequests(getConsentToken() + '1');
strictEqual(true, results.indexOf('myFoo=bar&baz=1') > 0, "setConsentGiven does replay all queued requests" );
strictEqual(true, results.indexOf('myFoo=bar&baz=2') > 0, "setConsentGiven does replay all queued requests" );
- strictEqual(2, (results.match(/consent=1/g) || []).length, "consent=1 parameter appears in URL when explicit consent given");
+ strictEqual(true, results.indexOf('ping=1') > 0, "setConsentGiven does replay all queued requests" );// sent when enabling cookies as part of setConsentGiven. Called twice in total
+ strictEqual(4, (results.match(/consent=1/g) || []).length, "consent=1 parameter appears in URL when explicit consent given");
var results2 = fetchTrackedRequests(getConsentToken() + '2');
strictEqual(true, results2.indexOf('myFoo=bar&baz=3') > 0, "normal request" );
@@ -4878,6 +4903,49 @@ if ($mysql) {
}, 2000);
});
+ test("Test API - cookie consent", function() {
+ expect(16);
+
+ var queue;
+ var tracker = Piwik.getTracker();
+ tracker.setCustomData('token', getCookieConsentToken() + '1');
+ strictEqual(tracker.areCookiesEnabled(), true, "areCookiesEnabled, enabled by default" );
+ strictEqual(tracker.getRememberedCookieConsent(), 0, "getRememberedCookieConsent, not set by default" );
+
+ var success = tracker.requireCookieConsent();
+ ok(success, 'cookies were disabled after calling requireCookieConsent');
+ ok(!tracker.areCookiesEnabled(), 'disabling cookies disables cookies');
+
+ tracker.setCookieConsentGiven();
+ ok(tracker.areCookiesEnabled(), 'setCookieConsentGiven enables cookies');
+
+ tracker.rememberCookieConsentGiven();
+ var nowBefore = new Date().getTime() - 10000;
+ var nowAfter = new Date().getTime() + 10000;
+ var timeConsentGiven = tracker.getRememberedCookieConsent();
+ ok(timeConsentGiven && nowBefore < timeConsentGiven && nowAfter > timeConsentGiven, "getRememberedCookieConsent, returns time was given" );
+
+ success = tracker.requireCookieConsent();
+ ok(!success, 'cookies were not disabled because consent was remembered')
+ ok(tracker.areCookiesEnabled(), 'disableCookies wont disable cookies if cookie consent was remembered');
+
+ tracker.forgetCookieConsentGiven();
+ ok(!tracker.areCookiesEnabled(), 'forgetCookieConsentGiven will disable cookies');
+
+ tracker.setCookieConsentGiven();
+ ok(tracker.areCookiesEnabled(), 'cookies can be enabled again after forgetting cookies');
+
+ tracker.requireCookieConsent();
+ ok(!tracker.areCookiesEnabled(), 'requireCookieConsent works after forgetting cookies');
+
+ tracker.rememberCookieConsentGiven();
+ ok(tracker.areCookiesEnabled(), 'cookies are enabled before disabling it');
+
+ tracker.disableCookies();
+ ok(!tracker.areCookiesEnabled(), 'disable cookies always disables cookies');
+ tracker.forgetCookieConsentGiven();
+ });
+
test("Test API - optOut (via consent feature)", function () {
expect(9);